aio-libs / aio-libs/aiohttp

Customize max_line_size and max_field_size in HttpParser?

Aperta
#2,988 10 commenti 0 reazioni 0 assegnatari Vedi su GitHub
enhancement
Lingua principale
Python
Stelle
16.5k
Fork
2.4k
Merge medio
17h 22m
PR unite (30g)
212

Descrizione

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](https://github.com/aio-libs/aiohttp/blob/3.2/aiohttp/_http_parser.pyx#L425) in order to override `max_line_size` and `max_field_size`. Here's the horrible things we've been doing: [gist](https://gist.github.com/alexandru/f68bc29aac2e4961f7720ecfba63afd3) — 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](https://gist.github.com/alexandru/fa54cde5088be9fb6acb56808efb01f9) if interested.

Cheers,

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.