python-hyper / h11

A pure-Python, bring-your-own-I/O implementation of HTTP/1.1
https://h11.readthedocs.io/
MIT License
490 stars 62 forks source link

Fails with LocalProtocolError for HTTP1.0 redirect #129

Closed rawler closed 3 years ago

rawler commented 3 years ago

Given a HTTP1.0 server, (with an implicit Connection: close), H11 fails with error message can't handle event type ConnectionClosed when role=SERVER and state=SEND_RESPONSE.

The response in question is

HTTP/1.0 307 Temporary Redirect
date: Tue, 09 Feb 2021 20:34:47 GMT
server: WSGIServer/0.2 CPython/3.6.9
content-type: text/html; charset=utf-8
content-length: 259
location: http://10.228.66.135:8080/

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>Redirecting...</title>
<h1>Redirecting...</h1>
<p>You should be redirected automatically to target URL: <a href="http://10.228.66.135:8080/">http://10.228.66.135:8080/</a>.  If not click the link.

The state "SEND_RESPONSE" is probably the culprit here. The response and the body is finished (259 bytes body sent), so the state should probably be IDLE, not SEND_RESPONSE.

If HTTP1.0 is explicitly not intended to be supported, it should probably be explicitly rejected when seen.

njsmith commented 3 years ago

Yeah, as far as I know this ought to work. Would it be easy to make a runnable reproducer? (You can hard-code the strings fed in from the server, so it doesn't require a real network.)

rawler commented 3 years ago

Started looking into it, but not quite sure how to repro using h11 directly. I'm experiencing the issue through httpx though, perhaps I should file the bug there instead?

njsmith commented 3 years ago

CC @tomchristie

tomchristie commented 3 years ago

@rawler By all means, yup. That'll give us a good starting point for tracking down exactly what needs to change, where.

If you've any good tips on quick and easy ways to replicate this that'd be super helpful too. (Wouldn't be too time consuming to pull together a little 1.0 responding service, but if there's any neat shortcuts that'll save us the time of having to do that, then that'd be ace.)

rawler commented 3 years ago

I have spent some time, digging in and trying to figure out what exactly goes wrong here. Will close this ticket, and if I manage to find the time and repro with httpx, post it there instead.