Skip to content
This repository has been archived by the owner on Dec 18, 2018. It is now read-only.

Content-Length not set to zero when no keep-alive #1041

Closed
tmds opened this issue Aug 9, 2016 · 4 comments
Closed

Content-Length not set to zero when no keep-alive #1041

tmds opened this issue Aug 9, 2016 · 4 comments
Assignees
Labels

Comments

@tmds
Copy link
Contributor

tmds commented Aug 9, 2016

Content-Length is set to zero when an AppFunc completes without a write, see #174.

This doesn't happen when the connection isn't persistent (_keepAlive == false).

When using Kestrel with IIS, IIS adds Content-Length: 0.

@halter73
Copy link
Member

I believe that Kestrel sets the Connection: close header in response to non keep-alive HTTP/1.1 requests in lieu of Content-Length: 0.

Looking into this, I think the behavior is somewhat broken for HTTP/1.0 requests post #835. We don't send the Connection: close response header in response to HTTP/1.0 requests. Omitting the header made a bit a sense when Kestrel would send HTTP/1.0 responses since Connection: close is implicit in that case, but now that all responses are HTTP/1.1 we should probably send the headers regardless.

I just submitted a PR (#1043) so that we send the Connection: close header in response to HTTP/1.0 request. Does this resolve your issue @tmds? Or is there some reason Content-Length: 0 should also be set even though the connection is being immediately closed?

@tmds
Copy link
Contributor Author

tmds commented Aug 10, 2016

I think the behavior is okay and consider sending Content-Length zero in this case an improvement.
The RFC has the following on this:

14.13 Content-Length
...
Applications SHOULD use this field to indicate the transfer-length of
   the message-body, unless this is prohibited by the rules in section
   4.4.
...

It may be beneficial to whomever is parsing the request to know how many bytes will follow before the close.

@tmds
Copy link
Contributor Author

tmds commented Aug 16, 2016

@halter73 do you want to keep the current behavior?
Unrelated to reference made by @CesarBS ?

@halter73
Copy link
Member

@tmds We are changing the behavior as you suggested.

In 1.1.0, Kestrel will automatically set both the Connection: close and Content-Length: 0 headers when the app doesn't write to the response body of a non keep-alive request. Assuming the the app hasn't changed either of those headers itself of course.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants