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

Proper 'Connection' header handling compatible with HTTP/1.0 and HTTP/1.1 #662

Merged
merged 1 commit into from
Mar 6, 2015
Merged

Proper 'Connection' header handling compatible with HTTP/1.0 and HTTP/1.1 #662

merged 1 commit into from
Mar 6, 2015

Conversation

iaintshine
Copy link
Contributor

Hi,

I hope you find this pull request useful. It includes a fix which makes puma handle the 'Connection' header properly.

In the current state, when you make an HTTP/1.1 request with the 'Connection' header set to 'close', you expect it to always respond with the 'Connection: close'. It's not the case if the server responds with a 204 status code or any other code without a body. The response won't include the 'Connection' header at all. This behavior can cause potential issues, such as writing to a socket that's already closed if some proxy server rewrites the 'Connection' header to 'close' and a client expects the connection to last for more than one request. Even though the HTTP/1.1 Message and Routing RFC - Persistence states that connection can be closed at any time, with or without intention it's always nice to inform a client about the server intention to close the connection.

The pull request changes the current state to behave in the following way:

  • If the received protocol is HTTP/1.1, and no 'Connection' header is present, or the header is set to 'keep-alive', the connection will persist and the header won't be present in the response
  • If the received protocol is HTTP/1.1, and the 'Connection' header is present and is set to 'close', the connection will not persist and the response will include the 'Connection' header set to 'close'
  • If the received protocol is HTTP/1.0, and no 'Connection' header is present, or the header is set to 'close', the connection will not persist and the header won't be present in the response
  • If the received protocol is HTTP/1.0, and the 'Connection' header is present and is set to 'keep-alive', the connection will persist and the response will include the 'Connection' header set to 'keep-alive'

Hope that make sense.

Kind Regards

evanphx added a commit that referenced this pull request Mar 6, 2015
Proper 'Connection' header handling compatible with HTTP/1.0 and HTTP/1.1
@evanphx evanphx merged commit bd3ddea into puma:master Mar 6, 2015
@evanphx
Copy link
Member

evanphx commented Mar 6, 2015

Thanks! Great work!

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.

None yet

2 participants