Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to do an early stop? #87

Open
Kludex opened this issue Oct 1, 2022 · 2 comments
Open

How to do an early stop? #87

Kludex opened this issue Oct 1, 2022 · 2 comments

Comments

@Kludex
Copy link

Kludex commented Oct 1, 2022

Hi there 馃憢

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
Copy link
Author

Kludex commented Oct 2, 2022

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
Copy link
Author

Kludex commented Oct 30, 2022

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

httptools does something cool here:

if PyMemoryView_Check(data):
buf = PyMemoryView_GET_BUFFER(data)
data_len = <size_t>buf.len
err = cparser.llhttp_execute(
self._cparser,
<char*>buf.buf,
data_len)
else:
buf = &self.py_buf
PyObject_GetBuffer(data, buf, PyBUF_SIMPLE)
owning_buf = True
data_len = <size_t>buf.len
err = cparser.llhttp_execute(
self._cparser,
<char*>buf.buf,
data_len)

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant