poster.streaminghttp

Streaming HTTP uploads module.

This module extends the standard httplib and urllib2 objects so that iterable objects can be used in the body of HTTP requests.

In most cases all one should have to do is call register_openers() to register the new streaming http handlers which will take priority over the default handlers, and then you can use iterable objects in the body of HTTP requests.

N.B. You must specify a Content-Length header if using an iterable object since there is no way to determine in advance the total size that will be yielded, and there is no way to reset an interator.

Example usage:

>>> from StringIO import StringIO
>>> import urllib2, poster.streaminghttp
>>> opener = poster.streaminghttp.register_openers()
>>> s = "Test file data"
>>> f = StringIO(s)
>>> req = urllib2.Request("http://localhost:5000", f,
...                       {'Content-Length': str(len(s))})
class poster.streaminghttp.StreamingHTTPConnection(host, port=None, strict=None, timeout=<object object at 0x7fd23df2d0c0>)

Subclass of httplib.HTTPConnection that overrides the send() method to support iterable body objects

class poster.streaminghttp.StreamingHTTPRedirectHandler

Subclass of urllib2.HTTPRedirectHandler that overrides the redirect_request method to properly handle redirected POST requests

This class is required because python 2.5’s HTTPRedirectHandler does not remove the Content-Type or Content-Length headers when requesting the new resource, but the body of the original request is not preserved.

redirect_request(req, fp, code, msg, headers, newurl)

Return a Request or None in response to a redirect.

This is called by the http_error_30x methods when a redirection response is received. If a redirection should take place, return a new Request to allow http_error_30x to perform the redirect. Otherwise, raise HTTPError if no-one else should try to handle this url. Return None if you can’t but another Handler might.

class poster.streaminghttp.StreamingHTTPHandler(debuglevel=0)

Subclass of urllib2.HTTPHandler that uses StreamingHTTPConnection as its http connection class.

http_open(req)

Open a StreamingHTTPConnection for the given request

http_request(req)

Handle a HTTP request. Make sure that Content-Length is specified if we’re using an interable value

poster.streaminghttp.register_openers()

Register the streaming http handlers in the global urllib2 default opener object.

Returns the created OpenerDirector object.

class poster.streaminghttp.StreamingHTTPSHandler(debuglevel=0)

Subclass of urllib2.HTTPSHandler that uses StreamingHTTPSConnection as its http connection class.

https_open(req)
https_request(req)
class poster.streaminghttp.StreamingHTTPSConnection(host, port=None, key_file=None, cert_file=None, strict=None, timeout=<object object at 0x7fd23df2d0c0>)

Subclass of httplib.HTTSConnection that overrides the send() method to support iterable body objects

Previous topic

poster.encode

This Page