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

Fix Connection persistence according to RFC 9112 #917

Merged
merged 1 commit into from
Nov 4, 2024

Conversation

rossabaker
Copy link
Member

We are aggressively closing connections in the presence of Connection headers composed exclusively of options other than keep-alive or close. This is contrary to the RFC

  • Connection tokens other than close and keep-alive are no longer considered in persistence logic.
  • blaze-server will no longer add an implicit Connection: close header to the response unless required by RFC 9112.
  • blaze-client will no longer add a duplicate Connection: close header when the request already has one.

Replaces #913, which targeted the incorrect branch.

case None => getHttpMinor(req) == 0
}
val mustClose: Boolean =
checkRequestCloseConnection(req.headers.get[HConnection], getHttpMinor(req), NullWriter)
Copy link
Member Author

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

Comment on lines +99 to +101
if (minorVersion >= 1) {
rr << "Connection: close\r\n"
}
Copy link
Member Author

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"),
Copy link
Member Author

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"),
),
Copy link
Member Author

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.

@rossabaker
Copy link
Member Author

Merging on Miles' review.

@rossabaker rossabaker merged commit 17766b8 into series/0.23 Nov 4, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant