Customize max_line_size and max_field_size in HttpParser? #2988
Description
We're using aiohttp 2.x with Python 3.5.2 and trying to upgrade to the latest aiohttp 3.2.0 with Python 3.6.5.
We're getting errors such as these:
[2018-05-10 08:31:55 +0000] [12471] [ERROR] Error handling request
Traceback (most recent call last):
File "/project/lib/python3.6/site-packages/aiohttp/web_protocol.py", line 235, in data_received
messages, upgraded, tail = self._request_parser.feed_data(data)
File "aiohttp/_http_parser.pyx", line 297, in aiohttp._http_parser.HttpParser.feed_data
File "aiohttp/_http_parser.pyx", line 425, in aiohttp._http_parser.cb_on_header_value
aiohttp.http_exceptions.LineTooLong: 400, message='Got more than 8190 bytes (9383) when reading Header value is too long.'
This was happening in aiohttp 2.x as well, because I believe the standard specifies that length as the maximum, however the real world doesn't always agree with standards 😒
To fix this, with aiohttp 2.x we were monkey-patching HttpParser in order to override max_line_size and max_field_size. Here's the horrible things we've been doing: gist — this file being imported in our gunicorn_worker.py.
Now that we've upgraded to 3.x, this monkey patching no longer works. Don't know why.
Any way to customize max_line_size and max_field_size?
Possibly without monkey patching, but not necessarily, atm I just want the thing to work?
Environment:
- Python 3.6.5
- aiohttp 3.2.0
- Gunicorn 19.8.1 (via
aiohttp.worker.GunicornWebWorker)
See the full requirements.txt if interested.
Cheers,