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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dealing with large requests: possibility to set max_incomplete_event_size for h11 #1234

Closed
1 of 2 tasks
alexiri opened this issue Nov 6, 2021 · 10 comments
Closed
1 of 2 tasks

Comments

@alexiri
Copy link

alexiri commented Nov 6, 2021

Checklist

  • There are no similar issues or pull requests for this yet.
  • I discussed this idea on the community chat and feedback is positive.
    (Asked in the chat, but no response received)

Is your feature related to a problem? Please describe.

I'm working on an application that needs to deal with large http headers, but I'm getting the following exception:

WARNING:  Invalid HTTP request received.
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/uvicorn/protocols/http/h11_impl.py", line 136, in handle_events
    event = self.conn.next_event()
  File "/usr/local/lib/python3.9/site-packages/h11/_connection.py", line 432, in next_event
    raise RemoteProtocolError(
h11._util.RemoteProtocolError: Receive buffer too long

Describe the solution you would like.

This error could be fixed if I was able to configure the max_incomplete_event_size of the h11 connection:

https://github.com/python-hyper/h11/blob/master/h11/_connection.py#L119

Describe alternatives you considered

For the time being, I've moved to Hypercorn which does allow me to change that parameter.

Additional context

@Kludex
Copy link
Sponsor Member

Kludex commented Nov 6, 2021

Yeah, some time ago I was reviewing the h11 implementation, and I've noticed that we just use the default.

The default value is explained on h11, but I guess it does make sense to allow the user to change its value if needed.

PR is welcome, but let's use the same strategy that we use with other CLI arguments: if the argument is not used, just ignore it.

Also, the "describe alternatives you considered" is meant to be an alternative solution that we can use to solve the problem in hands. Have you also tried the httptools implementation?

@alexiri
Copy link
Author

alexiri commented Nov 7, 2021

I confess I haven't tried the httptools implementation, I was in a bit of a rush with the deployment of my application and didn't think of testing it. I'll see if I find some time this week to do so.

@johnraz
Copy link

johnraz commented Dec 2, 2021

Doesn't this also applies to large query string?
If so I think the issue should be renamed to avoid that people discard reading the issue while the explanation is actually there ;-)

@alexiri alexiri changed the title Dealing with large headers: possibility to set max_incomplete_event_size for h11 Dealing with large requests: possibility to set max_incomplete_event_size for h11 Dec 2, 2021
@tomchristie
Copy link
Member

tomchristie commented Jan 27, 2022

I'm working on an application that needs to deal with large http headers

So, there is a trade-off with #1240 - which is that although it's a very nicely worked on PR. It also adds more configuration controls, which really we ought to try to avoid if at all possible.

More configurability means more different things for folks to read and understand when they're looking for whatever they do actually need.

It might not be a bad idea for us to just talk through your actual use-case here. Can you provide an example of why you need super large headers, and give an indication of what kind of size-range you're expecting?

A useful thing for us to then do would be just to have a bit of a look into what other clients or servers would (or wouldn't) support your use case. So we can make a more informed call on if we want to add configurability here or not.

@alexiri
Copy link
Author

alexiri commented Jan 28, 2022

My application was sitting behind an SSO proxy which passed the user's information in headers. This information includes the groups that a user is a member of, which my application uses for some sharing features. Some users can be members of a huge number of groups, which results in a very large header that uvicorn is currently unable to deal with.

Since h11 already supports configuring this, I thought it would be worthwhile to actually expose this through uvicorn to make it useful. It seems I'm in the minority on this, though, and I've since moved on and no longer need this feature.

@gauravojha
Copy link
Contributor

gauravojha commented Jun 10, 2022

@alexiri @Kludex we have the same usecase as yours (behind a proxy with user info in header). Would love to ask with reopening the evaluation of #1240

In case contribution or changes to the original PR are required, we would be more than happy to help contribute back if it helps.

@Kludex
Copy link
Sponsor Member

Kludex commented Jun 10, 2022

I can review it if you continue the previous implementation. I've written some comments over there.

@gauravojha
Copy link
Contributor

thanks.. will do..

@Kludex
Copy link
Sponsor Member

Kludex commented Jun 10, 2022

Be aware that I'd need to study this issue again, so it's not a promise of merging it. But if you work on the PR, I'll try my best to follow up.

euri10 pushed a commit that referenced this issue Jun 22, 2022
…1514)

* Solves #1234

* Update docs/settings.md

Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>

* Update uvicorn/main.py

Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>

* Fix lint

* Fixing tests

* Tweak tests a bit

* Remove event_loop fixture

Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
@Kludex
Copy link
Sponsor Member

Kludex commented Oct 1, 2022

This was solved by #1514, and it's available since 0.18.0.

@Kludex Kludex closed this as completed Oct 1, 2022
Kludex added a commit to sephioh/uvicorn that referenced this issue Oct 29, 2022
…ncode#1514)

* Solves encode#1234

* Update docs/settings.md

Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>

* Update uvicorn/main.py

Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>

* Fix lint

* Fixing tests

* Tweak tests a bit

* Remove event_loop fixture

Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
Kludex added a commit that referenced this issue Oct 29, 2022
…1514)

* Solves #1234

* Update docs/settings.md

Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>

* Update uvicorn/main.py

Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>

* Fix lint

* Fixing tests

* Tweak tests a bit

* Remove event_loop fixture

Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants