httptools
httptools copied to clipboard
How to do an early stop?
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?
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?
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)