Skip to content

v1.79.0

Latest

Choose a tag to compare

@erikdubbelboer erikdubbelboer released this 16 Nov 04:12
· 1 commit to master since this release
27e8f8e

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/websocket provides Accept, 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. Read returns connection-owned data valid until the next Read or Reader call. 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. RequestHeader and ResponseHeader now expose PeekTrailer and PeekAllTrailer. 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 Close and Reset, 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/http requests 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-Type values 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 CompressRoot are separated by source root, preventing one FS handler 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 Protocols instead 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 MaxRequestBodySize remain on the body stream so the handler can enforce its own limit before form buffering or temporary-file creation. Timed PipelineClient requests 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

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

HTTP framing, streaming, and connection handling

Adaptor fixes

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

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

Full Changelog: v1.78.0...v1.79.0