httptools icon indicating copy to clipboard operation
httptools copied to clipboard

How to do an early stop?

Open Kludex opened this issue 3 years ago • 2 comments

Hi there :wave:

I'm trying to implement a flag --limit-request-header-count on uvicorn, which I implemented changing the value of an attribute too_many_headers and raising an exception from on_header callback, see https://github.com/encode/uvicorn/pull/1683/files.

My question is: is my implementation as intended? Should the HttpParserCallbackError send more information when an exception happens from one of the callbacks?

Kludex avatar Oct 01 '22 11:10 Kludex

It looks like checking the count doesn't make much sense if we can limit the size of the headers. How can I do it for httptools? Should it be on httptools itself?

Kludex avatar Oct 02 '22 07:10 Kludex

Ok. Now I understand more. What I did doesn't make any sense.

httptools does something cool here: https://github.com/MagicStack/httptools/blob/e2d1a464d113418be26e0b2f36945f032c92a017/httptools/parser/parser.pyx#L166-L183

Still, I cannot do anything on uvicorn to limit the size of the headers/body, because I need to do it before it's parsed.

Ref.: https://github.com/nodejs/node/tree/fd36a8dadba7fcbd74f0ab82a8ee1b3150ce5167/deps/llhttp/src (this is for myself)

Kludex avatar Oct 30 '22 18:10 Kludex