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

Possibly h11 in client mode should raise an exception if it receives data before sending a Request #24

Open
njsmith opened this issue Dec 2, 2016 · 2 comments

Comments

@njsmith
Copy link
Member

njsmith commented Dec 2, 2016

This is related to: https://github.com/njsmith/h11/issues/23

Right now, there are two reasons this doesn't happen:

  • h11 doesn't look at the next request/response cycle at all until the current one finishes and someone calls start_next_cycle

  • the state machine actually allows a server to send a spontaneous Response. This is because when acting as a server, we want to be able to send back a 400 response to malformed requests, which from the state machine's point of view is like having no request at all. When acting as a client, though, then this doesn't make much sense.

CC @Lukasa

@njsmith
Copy link
Member Author

njsmith commented Dec 2, 2016

Oh, meh, checking git logs reminded me of the other reason why the state machine allows for spontaneous Response. We used to only allow this if the client state was ERROR, but it turns out there's this thing called 408 Timed out...

@Lukasa
Copy link
Member

Lukasa commented Dec 2, 2016

Heh, so amusingly I bumped into the spontaneous response while working on CONNECT tunnelling for urllib3. We're doing that by using two h11 state machines, one for the original CONNECT request and then a new one for the "inner" connection. However, I typoed and sent the CONNECT request on the "inner" state machine, and didn't notice for a very long time (it just led to weird errors that were difficult to track down). A bit annoying.

However, as you point out it's not totally implausible to get responses without requests. Generally speaking though I'd say that any client that sees one is probably doing something well outside the norm.

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

2 participants