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

Correct keep-alive responses to HTTP 1.0 clients #407

Merged
merged 2 commits into from
Apr 21, 2013

Conversation

GUI
Copy link
Contributor

@GUI GUI commented Apr 18, 2013

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:

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

Straight to nginx with default HTTP 1.0:

$ 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:

$ 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:

$ 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.

GUI added 2 commits April 18, 2013 16:33
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.
@indexzero
Copy link
Contributor

@GUI If all PRs were this good the world would be a better place. You sir, are a hero.

indexzero added a commit that referenced this pull request Apr 21, 2013
Correct keep-alive responses to HTTP 1.0 clients
@indexzero indexzero merged commit 98f5c46 into http-party:master Apr 21, 2013
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

Successfully merging this pull request may close these issues.

2 participants