nodejitsu/node-http-proxy — pull request #407 by GUI (2013-04-18 23:36:10+00:00)
Title: Correct keep-alive responses to HTTP 1.0 clients

This issue stems from #59

Since the proxy requests comes from NodeJS's HTTP 1.1 request client, a
backend server may default to setting Connection: keep-alive in its
response. However, the real HTTP 1.0 client may not be able to
handle that.

Force HTTP 1.0 client's to Connection: close, unless the client
explicitly supports keep-alive.

Here's a demonstration of the existing problem with a default nginx install running on port 8082 and the proxy running on port 9999:

```js
httpProxy.createServer(8082, 'localhost').listen(9999);
```

Straight to nginx with default HTTP 1.0:

```sh
$ curl -I --http1.0 'http://127.0.0.1:8082/'
HTTP/1.1 404 Not Found
Server: nginx/1.2.6
Date: Thu, 18 Apr 2013 22:44:51 GMT
Content-Type: text/html
Content-Length: 168
Connection: close
```

Straight to nginx with HTTP 1.0 and keep-alive header:

```sh
$ curl -I --http1.0 -H 'Connection: keep-alive' 'http://127.0.0.1:8082/'
HTTP/1.1 404 Not Found
Server: nginx/1.2.6
Date: Thu, 18 Apr 2013 22:46:22 GMT
Content-Type: text/html
Content-Length: 168
Connection: keep-alive
```

Default HTTP 1.0 request through the proxy:

```sh
$ curl -I --http1.0 'http://127.0.0.1:9999/'
HTTP/1.1 404 Not Found
server: nginx/1.2.6
date: Thu, 18 Apr 2013 22:47:06 GMT
content-type: text/html
content-length: 168
connection: keep-alive
```

This patch restores nginx's default behavior of only returning `Connection: keep-alive` for HTTP 1.0 clients if the client explicitly supports it. Otherwise, it will default to `Connection: close`.

I'm not sure if all backend servers behave this way, but this seems like the correct way to handle it given the fact that the node proxy forces the request to HTTP 1.1 but an HTTP 1.0 client won't support keep-alive by default.