tornado.httputil — Manipulate HTTP headers and URLs¶
HTTP utility code shared by clients and servers.
-
class
tornado.httputil.HTTPHeaders(*args, **kwargs)[source]¶ A dictionary that maintains
Http-Header-Casefor all keys.Supports multiple values per key via a pair of new methods,
add()andget_list(). The regular dictionary interface returns a single value per key, with multiple values joined by a comma.>>> h = HTTPHeaders({"content-type": "text/html"}) >>> list(h.keys()) ['Content-Type'] >>> h["Content-Type"] 'text/html'>>> h.add("Set-Cookie", "A=B") >>> h.add("Set-Cookie", "C=D") >>> h["set-cookie"] 'A=B,C=D' >>> h.get_list("set-cookie") ['A=B', 'C=D']>>> for (k,v) in sorted(h.get_all()): ... print('%s: %s' % (k,v)) ... Content-Type: text/html Set-Cookie: A=B Set-Cookie: C=D-
get_all()[source]¶ Returns an iterable of all (name, value) pairs.
If a header has multiple values, multiple pairs will be returned with the same name.
-
-
tornado.httputil.url_concat(url, args)[source]¶ Concatenate url and argument dictionary regardless of whether url has existing query parameters.
>>> url_concat("http://example.com/foo?a=b", dict(c="d")) 'http://example.com/foo?a=b&c=d'
-
class
tornado.httputil.HTTPFile[source]¶ Represents a file uploaded via a form.
For backwards compatibility, its instance attributes are also accessible as dictionary keys.
filenamebodycontent_type
-
tornado.httputil.parse_body_arguments(content_type, body, arguments, files)[source]¶ Parses a form request body.
Supports
application/x-www-form-urlencodedandmultipart/form-data. Thecontent_typeparameter should be a string andbodyshould be a byte string. Theargumentsandfilesparameters are dictionaries that will be updated with the parsed contents.
-
tornado.httputil.parse_multipart_form_data(boundary, data, arguments, files)[source]¶ Parses a
multipart/form-databody.The
boundaryanddataparameters are both byte strings. The dictionaries given in the arguments and files parameters will be updated with the contents of the body.
-
tornado.httputil.format_timestamp(ts)[source]¶ Formats a timestamp in the format used by HTTP.
The argument may be a numeric timestamp as returned by
time.time, a time tuple as returned bytime.gmtime, or adatetime.datetimeobject.>>> format_timestamp(1359312200) 'Sun, 27 Jan 2013 18:43:20 GMT'