Add support for allow_nonstandard_methods.

Add allow_nonstandard_methods to the http_fetch method to allow a client to
send HTTP requests that don't strictly adhere to the HTTP specification.
This commit is contained in:
Brian Korty 2017-08-07 11:08:06 -04:00
parent 01d04c5a6c
commit e1c7388047
2 changed files with 15 additions and 2 deletions

View file

@ -66,7 +66,8 @@ class HTTPClientMixin(object):
request_timeout=DEFAULT_REQUEST_TIMEOUT,
auth_username=None,
auth_password=None,
user_agent=None):
user_agent=None,
allow_nonstandard_methods=False):
"""Perform a HTTP request
Will retry up to ``self.MAX_HTTP_RETRIES`` times.
@ -88,6 +89,8 @@ class HTTPClientMixin(object):
:param str auth_password: Password for HTTP authentication
:param str user_agent: The str used for the ``User-Agent`` header,
default used if unspecified.
:param bool allow_nonstardard_methods: Allow methods that don't adhere
to the HTTP spec.
:rtype: HTTPResponse
"""
@ -114,7 +117,8 @@ class HTTPClientMixin(object):
request_timeout=request_timeout,
user_agent=user_agent or self._http_req_user_agent(),
follow_redirects=follow_redirects,
raise_error=False)
raise_error=False,
allow_nonstandard_methods=allow_nonstandard_methods)
except (OSError, socket.gaierror) as error:
LOGGER.debug('HTTP Request Error for %s to %s'
'attempt %i of %i: %s',

View file

@ -393,4 +393,13 @@ class MixinTestCase(testing.AsyncHTTPTestCase):
self.assertEqual(response.headers['Content-Type'], 'text/html')
self.assertEqual(response.body.decode('utf-8'), expectation)
@testing.gen_test()
def test_allow_nonstardard_methods(self):
response = yield self.mixin.http_fetch(
self.get_url('/test'),
method='DELETE',
body={'foo': 'bar', 'status_code': 200},
allow_nonstandard_methods=True)
self.assertTrue(response.ok)
self.assertEqual(response.code, 200)