aio-libs / aio-libs/aiohttp

Customize max_line_size and max_field_size in HttpParser?

Đang mở
#2,988 10 bình luận 0 reaction 0 người được giao Xem trên GitHub
enhancement
Ngôn ngữ chính
Python
Star
16.5k
Fork
2.4k
Merge trung bình
17 giờ 22 phút
Pull request đã merge (30 ngày)
212

Mô tả

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,

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.