Pass kwargs through to http client fetch.

This commit is contained in:
Dave Shawley 2020-04-07 11:42:53 -04:00
parent 7058cb3f27
commit 7309cff4cc
3 changed files with 24 additions and 2 deletions

View file

@ -1,6 +1,11 @@
Version History
===============
Next Release
------------
- Pass keyword parameters through to the underlying HTTPClient fetch method.
This enables niceties like streaming callback support
`2.3.1`_ Apr 7, 2020
--------------------
- Address `#27`_ by using the shortest appropriate timeout

View file

@ -272,7 +272,8 @@ class HTTPClientMixin:
user_agent=None,
validate_cert=True,
allow_nonstandard_methods=False,
dont_retry=None):
dont_retry=None,
**kwargs):
"""Perform a HTTP request
Will retry up to ``self.MAX_HTTP_RETRIES`` times.
@ -304,6 +305,8 @@ class HTTPClientMixin:
to the HTTP spec.
:param set dont_retry: A list of status codes that will not be retried
if an error is returned. Default: set({})
:param kwargs: additional keyword parameters are passed to
:meth:`tornado.httpclient.AsyncHTTPClient.fetch`
:rtype: HTTPResponse
"""
@ -353,7 +356,8 @@ class HTTPClientMixin:
max_redirects=max_redirects,
raise_error=False,
validate_cert=validate_cert,
allow_nonstandard_methods=allow_nonstandard_methods)
allow_nonstandard_methods=allow_nonstandard_methods,
**kwargs)
except (OSError, httpclient.HTTPError) as error:
response.append_exception(error)
LOGGER.warning(

View file

@ -615,3 +615,16 @@ class MixinTestCase(testing.AsyncHTTPTestCase):
self.assertAlmostEqual(response.duration,
response.attempts * 0.25,
places=1)
@testing.gen_test
def test_that_kwargs_are_passed_through(self):
chunks = []
def streaming_callback(chunk):
chunks.append(chunk)
response = yield self.mixin.http_fetch(
self.get_url('/test'),
streaming_callback=streaming_callback)
self.assertTrue(response.ok)
self.assertGreater(len(chunks), 0)