Correct keep-alive responses to HTTP 1.0 clients #407
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
Straight to nginx with default HTTP 1.0:
$ curl -I --http1.0 'https://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:
Default HTTP 1.0 request through the proxy:
$ curl -I --http1.0 'https://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 toConnection: 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.