API¶
HTTP Client Mixin¶
A Tornado Request Handler Mixin that provides functions for making HTTP requests.
-
class
sprockets.mixins.http.
HTTPClientMixin
¶ Mixin for making http requests. Requests using the asynchronous
HTTPClientMixin.http_fetch()
method-
http_fetch
(url, method='GET', request_headers=None, body=None, content_type='application/msgpack', follow_redirects=False, connect_timeout=10, request_timeout=60, auth_username=None, auth_password=None)¶ Perform a HTTP request
Will retry up to
self.MAX_HTTP_RETRIES
times.Parameters: - url (str) – The URL for the request
- method (str) – The HTTP request method, defaults to
GET
- request_headers (dict) – Headers to include in the HTTP request
- body (mixed) – The HTTP request body to send with the request
- content_type (
ContentType
or str) – The mime type to use for requests & responses. Defaults toapplication/msgpack
- follow_redirects (bool) – Follow HTTP redirects when received
- connect_timeout (float) – Timeout for initial connection in seconds, default 20 seconds
- request_timeout (float) – Timeout for entire request in seconds, default 20 seconds
- auth_username (str) – Username for HTTP authentication
- auth_password (str) – Password for HTTP authentication
Return type:
-
-
class
sprockets.mixins.http.
HTTPResponse
(ok, code, headers, body, raw, attempts, duration)¶ Response in the form of a
namedtuple
returned fromhttp_fetch()
that provides a slightly higher level of functionality than Tornado’stornado.httpclient.HTTPResponse
class.Parameters: - ok (bool) – The response status code was between 200 and 308
- code (int) – The HTTP response status code
- headers (dict) – The HTTP response headers
- body (mixed) – The deserialized HTTP response body if available/supported
- raw (tornado.httpclient.HTTPResponse) – The original Tornado HTTP response object for the request
- attempts (int) – The number of HTTP request attempts made
- duration (float) – The total duration of time spent making the request(s)