-
Notifications
You must be signed in to change notification settings - Fork 63
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
Fix Connection persistence according to RFC 9112 #917
Conversation
db511f5
to
a6581f3
Compare
case None => getHttpMinor(req) == 0 | ||
} | ||
val mustClose: Boolean = | ||
checkRequestCloseConnection(req.headers.get[HConnection], getHttpMinor(req), NullWriter) |
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 had a hard time teasing apart the side effect of writing the Connection: close
header, but we don't even want the side effect on the client side.
Alternatives would be to:
- duplicate the connection persistence logic
- put a protected method in
Http1Stage
to represent the side effect, or lack thereof - wrap this writer in an Option
- question all our lives' choices
if (minorVersion >= 1) { | ||
rr << "Connection: close\r\n" | ||
} |
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 tried to replace the Boolean
with a sum type to include whether the close is implicit or explicit. But the result threads through fairly deeply as a Boolean
.
@@ -57,13 +57,19 @@ object ServerTestRoutes extends Http4sDsl[IO] { | |||
// /////////////////////////////// | |||
( | |||
"GET /get HTTP/1.0\r\nConnection:close\r\n\r\n", | |||
(Status.Ok, Set(length(3), textPlain, connClose), "get"), | |||
(Status.Ok, Set(length(3), textPlain), "get"), |
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.
All removals of connClose
from this test are because it's the default in HTTP/1.0. There's no need for us to reiterate that.
( | ||
"GET /get HTTP/1.1\r\nConnection: fiddle-faddle\r\n\r\n", | ||
(Status.Ok, Set(length(3), textPlain), "get"), | ||
), |
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.
This test exposes the behavior change that motivated this PR.
Merging on Miles' review. |
We are aggressively closing connections in the presence of
Connection
headers composed exclusively of options other thankeep-alive
orclose
. This is contrary to the RFCConnection
tokens other thanclose
andkeep-alive
are no longer considered in persistence logic.Connection: close
header to the response unless required by RFC 9112.Connection: close
header when the request already has one.Replaces #913, which targeted the incorrect branch.