-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[8.0] Optionally respect HTTP/1.0 keep-Alive for HTTP.sys #57182
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
Changes from all commits
7e5fa5e
5dbe8f3
5b62646
a5a0ef6
c797bd8
ceb4a32
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,7 @@ internal sealed class Response | |
| private BoundaryType _boundaryType; | ||
| private HttpApiTypes.HTTP_RESPONSE_V2 _nativeResponse; | ||
| private HeaderCollection? _trailers; | ||
| private readonly bool _respectHttp10KeepAlive; | ||
|
|
||
| internal Response(RequestContext requestContext) | ||
| { | ||
|
|
@@ -51,6 +52,7 @@ internal Response(RequestContext requestContext) | |
| _nativeStream = null; | ||
| _cacheTtl = null; | ||
| _authChallenges = RequestContext.Server.Options.Authentication.Schemes; | ||
| _respectHttp10KeepAlive = RequestContext.Server.Options.RespectHttp10KeepAlive; | ||
| } | ||
|
|
||
| private enum ResponseState | ||
|
|
@@ -390,6 +392,7 @@ internal HttpApiTypes.HTTP_FLAGS ComputeHeaders(long writeCount, bool endOfReque | |
| var requestConnectionString = Request.Headers[HeaderNames.Connection]; | ||
| var isHeadRequest = Request.IsHeadMethod; | ||
| var requestCloseSet = Matches(Constants.Close, requestConnectionString); | ||
| var requestConnectionKeepAliveSet = Matches(Constants.KeepAlive, requestConnectionString); | ||
|
|
||
| // Gather everything the app may have set on the response: | ||
| // Http.Sys does not allow us to specify the response protocol version, assume this is a HTTP/1.1 response when making decisions. | ||
|
|
@@ -402,12 +405,25 @@ internal HttpApiTypes.HTTP_FLAGS ComputeHeaders(long writeCount, bool endOfReque | |
|
|
||
| // Determine if the connection will be kept alive or closed. | ||
| var keepConnectionAlive = true; | ||
| if (requestVersion <= Constants.V1_0 // Http.Sys does not support "Keep-Alive: true" or "Connection: Keep-Alive" | ||
|
|
||
| if (requestVersion < Constants.V1_0 | ||
| || (requestVersion == Constants.V1_1 && requestCloseSet) | ||
| || responseCloseSet) | ||
| { | ||
| keepConnectionAlive = false; | ||
| } | ||
| else if (requestVersion == Constants.V1_0) | ||
| { | ||
| // In .NET 9, we updated the behavior for 1.0 clients here to match | ||
| // RFC 2068. The new behavior is available down-level behind an | ||
| // AppContext switch. | ||
|
|
||
| // An HTTP/1.1 server may also establish persistent connections with | ||
| // HTTP/1.0 clients upon receipt of a Keep-Alive connection token. | ||
| // However, a persistent connection with an HTTP/1.0 client cannot make | ||
| // use of the chunked transfer-coding. From: https://www.rfc-editor.org/rfc/rfc2068#section-19.7.1 | ||
| keepConnectionAlive = _respectHttp10KeepAlive && requestConnectionKeepAliveSet && !responseChunkedSet; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. responseChunkedSet is only for cases where the application sets the chunked header and does the chunking themselves, it doesn't cover the default case where the server does chunking automatically. See edit nevermind, the automatic case only happens for 1.1.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the review! |
||
| } | ||
|
|
||
| // Determine the body format. If the user asks to do something, let them, otherwise choose a good default for the scenario. | ||
| if (responseContentLength.HasValue) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might say "// Internal for testing".