Honor HTTP/1.1 persistent-connection default per RFC 9112 §9.3#209
Merged
swhitty merged 1 commit intoApr 26, 2026
Merged
Conversation
HTTPRequest.shouldKeepAlive now treats HTTP/1.1 as persistent unless `Connection: close` is sent, and HTTP/1.0 as closed unless `keep-alive` is sent. Splits the Connection header on commas so multi-token values like `Keep-Alive, Upgrade` are recognized (RFC 9110 §7.6.1). HTTPServer.handleRequest no longer overwrites a Connection header that the handler explicitly set (e.g. WebSocket's `Upgrade`); it only echoes the request's Connection token when the response has none. Adds nine HTTPRequest.shouldKeepAlive cases covering HTTP/1.1 default, multi-token, and HTTP/1.0 semantics. Updates the keep-alive iteration test to terminate via `Connection: close` instead of relying on the old (buggy) behavior. Closes TVT-288 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #209 +/- ##
==========================================
+ Coverage 92.67% 92.69% +0.01%
==========================================
Files 69 69
Lines 3551 3558 +7
==========================================
+ Hits 3291 3298 +7
Misses 260 260 ☔ View full report in Codecov by Sentry. |
swhitty
approved these changes
Apr 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
HTTPRequest.shouldKeepAlivenow follows RFC 9112 §9.3: HTTP/1.1 connections persist unlessConnection: close; HTTP/1.0 connections close unlessConnection: keep-aliveis present. The Connection header is split on commas so multi-token values likeKeep-Alive, Upgradeare handled (RFC 9110 §7.6.1).HTTPServer.handleRequestno longer overwrites a Connection header that the handler explicitly set (e.g. WebSocket'sUpgrade). It only echoes the request's Connection token when the response has none.Connection: keep-alive(the compliant default) would have the connection closed after one request. With multi-token headers, evenKeep-Alive, Upgradefailed the equality check.Closes TVT-288.
Test plan
HTTPRequestTestscases covering HTTP/1.1 default, multi-token, and HTTP/1.0 semantics.connectionRequestsAreReceived_WhileConnectionIsKeptAliveto terminate viaConnection: closeinstead of relying on the previous (buggy) behavior.