Repository navigation
Fix incorrect status lines in HTTPResponseEncoder fast paths - #3631
Merged
glbrntt merged 3 commits intoJun 23, 2026
Merged
Conversation
Motivation: `HTTPResponseEncoder` writes hand-optimised status lines for the well-known `HTTPResponseStatus` values instead of going through the general `default` path that formats `HTTP/<version> <code> <reasonPhrase>`. Several of those fast paths had drifted out of sync with `HTTPResponseStatus.reasonPhrase`, so the exact bytes on the wire depended on whether a status happened to have a fast path: * HTTP/1.0 + 511 emitted the wrong HTTP version (`HTTP/1.1 511 ...`), which is a wire-format correctness bug, not just cosmetic. * HTTP/1.1 + 431 emitted the reason phrase `Range Not Satisfiable` instead of `Request Header Fields Too Large`. * HTTP/1.1 + 416 emitted `Request Range Not Satisified` (also misspelled) instead of `Range Not Satisfiable`. * HTTP/1.0 and HTTP/1.1 + 307 emitted `Tempory Redirect` (misspelled) instead of `Temporary Redirect`. Modifications: * Correct the five diverging status lines in `HTTPResponseEncoder` so they match `HTTPResponseStatus.reasonPhrase` and carry the correct HTTP version. * Add a regression test that, for every well-known status at both HTTP/1.0 and HTTP/1.1, asserts the encoded status line equals the canonical `HTTP/<version> <code> <reasonPhrase>` form, keeping the fast paths in lockstep with `reasonPhrase`. Result: The encoder now produces correct, consistent status lines for all well-known statuses regardless of whether they use a fast path.
glbrntt
reviewed
Jun 23, 2026
glbrntt
left a comment
Contributor
There was a problem hiding this comment.
Thanks, this look great. One tiny thing in the tests to fixup.
| andHeaders: HTTPHeaders(), | ||
| version: version | ||
| ) | ||
| let bytes = written.getString(at: written.readerIndex, length: written.readableBytes)! |
Contributor
There was a problem hiding this comment.
Prefer the direct init rather than using get* APIs. I think this is the API:
Suggested change
| let bytes = written.getString(at: written.readerIndex, length: written.readableBytes)! | |
| let bytes = String(buffer: written) |
Address review feedback to prefer the direct String(buffer:) initializer over the getString get* API.
tkshsbcue
force-pushed
the
fix-http-response-encoder-status-lines
branch
from
June 23, 2026 11:40
60cdfb0 to
55127fd
Compare
Contributor
Author
|
hey @glbrntt just made those changes you suggest please have a look |
glbrntt
enabled auto-merge (squash)
June 23, 2026 12:28
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.
Motivation
HTTPResponseEncoderwrites hand-optimised status lines for the well-knownHTTPResponseStatusvalues instead of going through the generaldefaultpath that formatsHTTP/<version> <code> <reasonPhrase>. Several of those fast paths had drifted out of sync withHTTPResponseStatus.reasonPhrase, so the exact bytes on the wire depended on whether a status happened to have a fast path:HTTP/1.1 511 ...) β a wire-format correctness bug, not just cosmetic.Range Not Satisfiableinstead ofRequest Header Fields Too Large.Request Range Not Satisified(also misspelled) instead ofRange Not Satisfiable.Tempory Redirect(misspelled) instead ofTemporary Redirect.Resolves #3630.
Modifications
HTTPResponseEncoderso they matchHTTPResponseStatus.reasonPhraseand carry the correct HTTP version.HTTP/<version> <code> <reasonPhrase>form, keeping the fast paths in lockstep withreasonPhrase.Result
The encoder now produces correct, consistent status lines for all well-known statuses regardless of whether they use a fast path. The new test fails on the pre-fix code (the 511 case fails on the version, the 431/416/307 cases on the reason phrase) and passes after the fix.