Skip to content

Rewrite header parsing to improve spec compliance#2030

Merged
erikdubbelboer merged 1 commit intomasterfrom
http-header-parser
Aug 12, 2025
Merged

Rewrite header parsing to improve spec compliance#2030
erikdubbelboer merged 1 commit intomasterfrom
http-header-parser

Conversation

@erikdubbelboer
Copy link
Collaborator

This change updates header parsing to match the behavior of net/http more closely.

Breaking change: headers delimited by \n (instead of \r\n) are no longer supported.

Previously, fasthttp accepted \n as a delimiter, which is not spec compliant. This made it difficult to correctly parse headers containing both \n and \r\n.

Benchmarks show that the new parser is slightly slower, but still a lot faster than net/http.

goos: linux
goarch: amd64
pkg: github.com/valyala/fasthttp
cpu: Intel(R) Xeon(R) CPU @ 3.10GHz

old:
BenchmarkRequestHeaderRead-8   	        1000000000      52.78 ns/op	       0 B/op	     0 allocs/op

new:
BenchmarkRequestHeaderRead-8            515757008	    139.2 ns/op	       0 B/op	     0 allocs/op

net/http
BenchmarkRequestHeaderReadNetHttp-8     130283641	    552.0 ns/op     1152 B/op       18 allocs/op

TODO: After merged add fuzz tests to: https://github.com/google/oss-fuzz/blob/20a387d78148c14dd5243ea1b16164fe08b73884/projects/fasthttp/build.sh

Fixes: #2020
Fixes: #1974

@erikdubbelboer erikdubbelboer force-pushed the deprecated-newline-separator branch from 6733621 to e5b271d Compare June 27, 2025 04:19
@erikdubbelboer erikdubbelboer changed the base branch from deprecated-newline-separator to master July 27, 2025 06:28
@erikdubbelboer erikdubbelboer marked this pull request as ready for review August 4, 2025 06:45
This change updates header parsing to match the behavior of net/http more closely.

**Breaking change**: headers delimited by `\n` (instead of `\r\n`) are no longer supported.

Previously, fasthttp accepted `\n` as a delimiter, which is not spec compliant.
This made it difficult to correctly parse headers containing both `\n` and `\r\n`.
@erikdubbelboer erikdubbelboer merged commit f9d84d7 into master Aug 12, 2025
11 checks passed
@erikdubbelboer erikdubbelboer deleted the http-header-parser branch September 5, 2025 10:56
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.

Questions about code reading FastHTTP incorrectly handles obs-fold on the first line

1 participant