v1.79.0 adds a WebSocket server and client package and direct access to HTTP trailer values. It also fixes cross-stream data leaks in compression, strengthens request forwarding and HTTP framing, and improves shutdown, multipart streaming, and static-file cache isolation.
Features
- A new WebSocket package supports servers and clients.
github.com/valyala/fasthttp/websocketprovidesAccept,Dial, context-based reads and writes, streaming message readers and writers, ping handling, and close handshakes. Optional permessage-deflate supports both compression modes, with and without context takeover; compression is disabled by default. The default message limit is 4 MiB.Readreturns connection-owned data valid until the nextReadorReadercall. Follow-up fixes correct URL credential decoding and connection closing, and reduce buffer sizes for large messages. #2493, #2545 - Trailer values can be read separately from upfront headers.
RequestHeaderandResponseHeadernow exposePeekTrailerandPeekAllTrailer. These search only the trailer section, so an upfront header with the same name is not mistaken for a trailer. For streamed bodies, received trailers are available after the body reaches EOF. #2534
Security fixes and hardening
- Pooled compression state no longer leaks data between streams. Stackless writers always complete
CloseandReset, including when the worker queue is full. Stackless zstd encoding finishes its writes before output buffers are released, and pooled zstd decoding cannot return another caller's output after malformed input. #2555, #2554, #2564 - Compression retains ownership of the data it still uses. Response compression is skipped after a handler times out. File readers and streamed requests remain alive until compression finishes, including when the response is discarded or a client disconnects during a write. This prevents premature pool reuse while a compression goroutine still holds references. #2559, #2560, #2565
- Forwarded requests preserve the host and resource checked by the server. Slash-prefixed targets retain the supplied Host, absolute request targets retain their authority across path rewrites, and adapted
net/httprequests use the same resource interpretation as fasthttp. Incoming request authorities containing userinfo are rejected before server callbacks run; client-constructed URLs still support credentials. #2572, #2575, #2580, #2579 - Replacement and redirect handling remove stale sensitive values. Setting a header, cookie, or argument replaces later duplicates rather than leaving old values behind. Redirect credential stripping handles every header-name casing, including trailers, and a POST changed to GET after a 301 or 302 no longer forwards its body. Empty request-cookie names also survive serialization when their values contain
=, preventing a nameless cookie from becoming a named one. #2570, #2574, #2571, #2586 - Request parsing rejects ambiguous content types and excessive chunk overhead. Conflicting
Content-Typevalues are rejected before reading the body; identical repeats remain accepted. Chunk parsing bounds optional padding on individual size lines and excess framing overhead across chunks, applying the same limits to buffered bodies, streams, and unread-body drains. #2576, #2573 - Multipart forwarding and shared compression caches preserve isolation. Re-serializing a parsed multipart form rejects decoded content that would introduce a delimiter and create additional parts. Generated compressed files in a shared
CompressRootare separated by source root, preventing oneFShandler from serving another root's cached content. Existing flat cache entries are regenerated on demand. #2581, #2584
HTTP framing and connection handling
- Connection reuse respects message boundaries. Empty GET and HEAD requests clear stale body framing, timeout responses to HEAD omit the body, and broken request chunks cause the connection to close even when the error is encountered while writing a streamed response. HTTP clients close connections after
101 Switching Protocolsinstead of reusing them for another HTTP request. #2562, #2568, #2569, #2566 - Shutdown closes stalled first requests. Connections still reading their first request are closed during shutdown once the five-second grace period from acceptance has passed. Requests already in a handler and later keep-alive requests retain their existing shutdown behavior. Remote-address overrides are also cleared between keep-alive requests. #2536, #2582
- Multipart uploads follow the configured streaming behavior. With request streaming enabled, fixed-length multipart uploads above
MaxRequestBodySizeremain on the body stream so the handler can enforce its own limit before form buffering or temporary-file creation. TimedPipelineClientrequests preserve pre-parsed uploads when copying work for asynchronous execution. #2583, #2563 - Adapted handlers clean up and terminate responses correctly. Writes after hijacking are discarded without touching released buffers, invalid status codes abort the response, and multipart temporary files are removed when the adapted handler returns. #2567, #2577, #2578
Other fixes report io.ErrShortWrite from affected writers and compression helpers, separate IPv4-only and dual-stack DNS cache entries, support HTTP proxy URLs with a trailing slash, and correct generated directory links, modification-time handling, and Windows CONNECT redirects. The Server.MaxRequestBodySize documentation now explains that buffered requests can reserve memory from the declared body size before payload data arrives.
Performance improvements
Buffered chunk sizes are parsed directly instead of using one ReadByte call per digit. In the PR's Apple M5 benchmarks, two-chunk responses took about 10% less time, two-chunk requests 9% less time, and bodies with 200 one-byte chunks 17% less time. Results varied by platform and code layout; readers delivering one byte per call were 2–3% slower on the tested AMD EPYC system. These are focused PR measurements, not a release-wide comparison. #2539
The new WebSocket implementation also reduces excess buffer capacity for large messages. In the follow-up PR's examples, reading a compressed 4 MiB message used a 4 MiB buffer instead of 16 MiB, and compressing 1 MiB of repetitive text used a 64 KiB output buffer instead of 2 MiB. #2545
What's Changed
Features
- Add a WebSocket package by @h2zi in #2493
- feat(header): add trailer value accessors by @ZXLyyds100 in #2534
Performance
- perf: parse buffered chunk size digits without ReadByte calls by @g4lb in #2539
- websocket: follow-up fixes and smaller buffers for large messages by @h2zi in #2545
Security and hardening
- fix: prevent asynchronous zstd writes to pooled buffers by @erikdubbelboer in #2554
- fix(stackless): prevent cross-stream data leaks under load by @erikdubbelboer in #2555
- Skip response compression after a handler times out by @erikdubbelboer in #2559
- Keep FS readers alive until response compression finishes by @erikdubbelboer in #2560
- Prevent pooled zstd decoders from returning previous output by @erikdubbelboer in https://github.com/valyala/fthttp/pull/2564
- Keep streamed requests alive after a compressed response write fails by @erikdubbelboer in #2565
- Keep the Host header for slash-prefixed request targets by @erikdubbelboer in #2572
- Reject conflicting request Content-Type headers by @erikdubbelboer in #2576
- Bound chunk extension overhead when reading HTTP bodies by @erikdubbelboer in #2573
- Keep the absolute request target host across path rewrites by @erikdubbelboer in #2575
- Strip redirect credentials regardless of header name casing by @erikdubbelboer in #2574
- Replace duplicate values when setting a header, cookie or argument by @erikdubbelboer in #2570
- Drop the POST body when following a 301 or 302 as GET by @erikdubbelboer in #2571
- Keep adapted requests on the resource checked by fasthttp by @erikdubbelboer in #2580
- Preserve empty request cookie names when values contain an equals sign by @erikdubbelboer in #2586
- Isolate shared FS compression caches by source root by @erikdubbelboer in #2584
- Reject multipart delimiters in decoded part content by @erikdubbelboer in #2581
- Reject userinfo in incoming HTTP request authorities by @erikdubbelboer in #2579
HTTP framing, streaming, and connection handling
- fix: report io.ErrShortWrite from WriteTo implementations by @CJstate in #2541
- fix: report io.ErrShortWrite from stackless compression helpers by @CJstate in #2543
- fix: report io.ErrShortWrite from fsSmallFileReader.WriteTo by @CJstate in #2542
- fix: close connections still reading their first request during Shutdown by @tony1233200 in #2536
- Correct stale framing on empty GET and HEAD requests by @erikdubbelboer in #2562
- Forward pre-parsed multipart forms in timed pipeline requests by @erikdubbelboer in #2563
- Close HTTP client connections after switching protocols by @erikdubbelboer in #2566
- Suppress timeout response bodies for HEAD requests by @erikdubbelboer in #2568
- Close connections when streamed responses encounter broken request chunks by @erikdubbelboer in #2569
- Reset the remote address override between keep-alive requests by @erikdubbelboer in #2582
- Stream multipart uploads above the request body threshold by @erikdubbelboer in #2583
Adaptor fixes
- fasthttpadaptor: discard response writes after hijacking by @erikdubbelboer in #2567
- Remove multipart upload files when an adapted handler returns by @erikdubbelboer in #2578
- Abort adapted responses with invalid status codes by @erikdubbelboer in #2577
Other fixes
- fix(fasthttpproxy): dial an HTTP proxy whose URL has a trailing slash by @Dv2Corn in #2548
- fix: keep the DNS cache entries of Dial and DialDualStack apart by @Dv2Corn in #2552
- fix(fs): percent-encode the links of generated index pages by @Dv2Corn in #2550
- fix(fs): ignore If-Modified-Since for files without a modification time by @Dv2Corn in #2549
- Keep Windows URI paths rooted for CONNECT redirects by @erikdubbelboer in #2561
Documentation
- Document request body preallocation on Server.MaxRequestBodySize by @erikdubbelboer in #2585
Dependency updates
- chore(deps): bump golang.org/x/sys from 0.49.0 to 0.50.0 by @dependabot[bot] in #2544
- chore(deps): bump github.com/klauspost/compress from 1.20.3 to 1.20.4 by @dependabot[bot] in #2553
New Contributors
- @ZXLyyds100 made their first contribution in #2534
- @g4lb made their first contribution in #2539
- @CJstate made their first contribution in #2541
- @Dv2Corn made their first contribution in #2548
- @tony1233200 made their first contribution in #2536
Full Changelog: v1.78.0...v1.79.0