senko/tornado-proxy — pull request #3 by stanvit (2013-01-04 02:52:28+00:00)
Title: Early client.close() and potential upstream.close() issue

Despite the [docs on tornado.iostream.IOStream](http://www.tornadoweb.org/documentation/iostream.html#tornado.iostream.IOStream.read_until_close), under some circumstances read_until_close()'s handler does receive some leftover data.

Without the patch:

```
$ telnet localhost 8888
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
CONNECT httpbin.org:80 HTTP/1.0

HTTP/1.0 200 Connection established

GET /get HTTP/1.0
Host: httpbin.org

Connection closed by foreign host.
```

With the patch:

```
$ telnet localhost 8888
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
CONNECT httpbin.org:80 HTTP/1.0

HTTP/1.0 200 Connection established

GET /get HTTP/1.0
Host: httpbin.org

HTTP/1.1 200 OK
Content-Type: application/json
Date: Fri, 04 Jan 2013 02:45:50 GMT
Server: gunicorn/0.16.1
Content-Length: 155
Connection: Close

{
"headers": {
"Connection": "keep-alive",
"Host": "httpbin.org"
},
"origin": "10.5.13.63",
"args": {},
"url": "http://httpbin.org/get"
}Connection closed by foreign host.
```

Mac OS X10.7.5
Python 2.7.1
Tornado 2.4.1