Skip to content

fix(http1): recognize \n\r\n as a head terminator in the partial-read fast path - #4147

Merged
seanmonstar merged 2 commits into
hyperium:masterfrom
nam2ee:fix-h1-lf-crlf-fast-path
Aug 10, 2026
Merged

fix(http1): recognize \n\r\n as a head terminator in the partial-read fast path#4147
seanmonstar merged 2 commits into
hyperium:masterfrom
nam2ee:fix-h1-lf-crlf-fast-path

Conversation

@nam2ee

@nam2ee nam2ee commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Closes #4145.

is_complete_fast recognizes \r\n\r\n and \n\n as head terminators but not \n\r\n, while the full parser (httparse) accepts all three. So a request whose head ends with \n\r\n parses fine when it arrives in a single read, but stalls when it arrives split across reads: the fast path never reports the head complete and the connection keeps waiting for more bytes.

This extends the \n branch to also accept a following \r\n, using the same panic-safe slicing idiom as the \r branch. Added the \n\r\n witness and the \n\r negative to test_is_complete_fast, plus a parse-level test documenting that the full parser accepts this terminator.

@seanmonstar

Copy link
Copy Markdown
Member

Thanks for the PR! Seems simple to fix, sure :) I have to assume it's pretty rare to actually happen, most implementations usually use just one or the other, not both line endings mixed. 🤓

@nam2ee

nam2ee commented Aug 10, 2026

Copy link
Copy Markdown
Contributor Author

sorry I just adjusted to pass lint :/

@seanmonstar
seanmonstar merged commit 3534d75 into hyperium:master Aug 10, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HTTP/1: request with \n\r\n head terminator is accepted only when it arrives in a single read

2 participants