with the parsed contents.
"""
if content_type.startswith("application/x-www-form-urlencoded"):
- uri_arguments = parse_qs_bytes(native_str(body), keep_blank_values=True)
+ try:
+ uri_arguments = parse_qs_bytes(native_str(body), keep_blank_values=True)
+ except Exception as e:
+ gen_log.warning('Invalid x-www-form-urlencoded body: %s', e)
+ uri_arguments = {}
for name, values in uri_arguments.items():
if values:
arguments.setdefault(name, []).extend(values)
self.assertEqual(200, response.code)
self.assertEqual(json_decode(response.body), {})
+ def test_malformed_body(self):
+ # parse_qs is pretty forgiving, but it will fail on python 3
+ # if the data is not utf8. On python 2 parse_qs will work,
+ # but then the recursive_unicode call in EchoHandler will
+ # fail.
+ if str is bytes_type:
+ return
+ with ExpectLog(gen_log, 'Invalid x-www-form-urlencoded body'):
+ response = self.fetch(
+ '/echo', method="POST",
+ headers={'Content-Type': 'application/x-www-form-urlencoded'},
+ body=b'\xe9')
+ self.assertEqual(200, response.code)
+ self.assertEqual(b'{}', response.body)
+
class HTTPServerRawTest(AsyncHTTPTestCase):
def get_app(self):