diff --git a/docs/history.rst b/docs/history.rst index b2ef6b3..857157b 100644 --- a/docs/history.rst +++ b/docs/history.rst @@ -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 diff --git a/sprockets/mixins/http/__init__.py b/sprockets/mixins/http/__init__.py index cfe118c..8db3c2c 100644 --- a/sprockets/mixins/http/__init__.py +++ b/sprockets/mixins/http/__init__.py @@ -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( diff --git a/tests.py b/tests.py index 5476c7d..72c6044 100644 --- a/tests.py +++ b/tests.py @@ -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)