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

Handle non "chunked" Transfer-Encoding header values (#1181) #1185

Merged
merged 1 commit into from
Oct 31, 2016

Conversation

cesarblum
Copy link
Contributor

@cesarblum cesarblum commented Oct 27, 2016

#1181

  • Reject request if chunked is not final token in Transfer-Encoding
  • Close connection if chunked is not final token in response Transfer-Encoding

Point for discussion: should we insert chunked and auto-chunk responses that don't have chunked in Transfer-Encoding? Or should we leave it up to the app to chunk the response in those cases? The problem with not auto-chunking is that Kestrel will now close the connection if such a response is sent.

@halter73 @davidfowl @Tratcher @mikeharder

@cesarblum
Copy link
Contributor Author

cesarblum commented Oct 27, 2016

No impact on plaintext benchmark:

dev: 1210317.84 RPS
PR: 1224226.38

@benaadams
Copy link
Contributor

For compression Content-Encoding would be used if Kestrel was source server; but maybe? Transfer-Encoding would be used if it was a proxy - but not necessarily chunked if length was known? (Trying to think of a scenerio where it would apply)

{
await connection.SendAll(
"POST / HTTP/1.1",
"Transfer-Encoding: not-chunked",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a test where the request includes both a Content-Length and a non-chunked Transfer-Encoding?

@@ -812,6 +812,8 @@ private Task WriteSuffix()
var responseHeaders = FrameResponseHeaders;
var hasConnection = responseHeaders.HasConnection;
var connectionOptions = hasConnection ? FrameHeaders.ParseConnection(responseHeaders.HeaderConnection) : ConnectionOptions.None;
var hasTransferEncoding = responseHeaders.HasTransferEncoding;
var transferCoding = hasTransferEncoding ? FrameHeaders.GetFinalTransferCoding(responseHeaders.HeaderTransferEncoding) : TransferCoding.None;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: HasConnection and HasContentLength both simply call StringValues.Count. It would be simpler to have ParseConnection and GetFinalTransferCoding check the Count themselves and return None rather than doing the Has checks here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just realized I don't even have to check Count - the foreach simply won't iterate over anything and those methods will return None.


if (hasConnection)
{
responseHeaders.SetRawConnection("close", _bytesConnectionClose);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like setting _keepAlive to false, but I'm not sure about changing headers that the user as already explicitly set even to save them from violating the HTTP spec. Do we do that for other headers?

@cesarblum
Copy link
Contributor Author

Updated.

@cesarblum cesarblum force-pushed the cesarbs/transfer-encoding-proper-handling branch from be7ab02 to 7763bf3 Compare October 31, 2016 17:24
@cesarblum
Copy link
Contributor Author

Ping.

@halter73
Copy link
Member

:shipit:

@cesarblum cesarblum force-pushed the cesarbs/transfer-encoding-proper-handling branch from 7763bf3 to 2940895 Compare October 31, 2016 20:58
@cesarblum cesarblum merged commit 2940895 into dev Oct 31, 2016
@cesarblum cesarblum deleted the cesarbs/transfer-encoding-proper-handling branch October 31, 2016 22:08
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants