github valyala/fasthttp v1.80.0

34 minutes ago

v1.80.0 fixes client connection desynchronization when skipping response bodies and preserves cache variation headers during compression. It also adds helper APIs for downstream frameworks, makes parser errors matchable, and improves redirects, compression negotiation, and repeated-header handling.

Security fixes and hardening

  • Skipping a response body no longer desynchronizes later requests. Reusing a Response after HEAD no longer makes subsequent requests skip their bodies. When a caller explicitly skips a potentially present body, Client and HostClient close the connection instead of pooling it with unread bytes. PipelineClient reads and discards the body so the next pipelined response starts at the correct boundary. The caller's SkipBody setting is preserved. #2533
  • Compression preserves every Vary line. Adding Accept-Encoding no longer removes later Vary fields, such as Vary: Cookie. This fixes a regression that could let a shared cache reuse a response without considering all of its original variation criteria. Both CompressHandler and compressed static-file serving are covered. #2598
  • Unsigned float parsing rejects non-finite values and negative zero. ParseUfloat and the argument getters that use it now reject NaN, infinity, and -0. Finite formats accepted by strconv.ParseFloat, including a leading +, digit separators, and hexadecimal floats, remain supported. #2546

Features

  • Bounded decompression helpers work directly on byte slices. AppendGunzipBytesWithLimit, AppendInflateBytesWithLimit, AppendUnbrotliBytesWithLimit, and AppendUnzstdBytesWithLimit append decoded data while enforcing a limit on newly decoded bytes. Existing data in the destination does not count toward the limit. Exceeding the limit returns ErrBodyTooLarge; a non-positive limit leaves output unlimited. The zstd helper also limits decoder window size when a positive limit is supplied. #2520
  • Frameworks can inspect header normalization and reuse redirect helpers. RequestHeader.NormalizingDisabled() and ResponseHeader.NormalizingDisabled() expose the current setting. HasNonHTTPSchemeWithoutAuthority identifies locations such as mailto: and native-app callbacks, and DefaultMaxRedirectsCount exports the existing default of 16. DoRedirects continues to use the count explicitly supplied by its caller. #2520
  • Unsupported methods and unknown transfer codings have matchable errors. errors.Is can identify ErrUnsupportedRequestMethod regardless of SecureErrorLogMessage. The new ErrUnknownTransferCoding distinguishes a well-formed but unsupported transfer coding from malformed framing and also matches ErrUnsupportedTransferEncoding. Custom error handlers can use these distinctions to choose between 501 and 400 responses; malformed request fields and targets still take precedence over an unknown coding. #2594

HTTP compatibility and redirects

  • Compression negotiation checks all supplied encodings. HasAcceptEncoding scans every Accept-Encoding header line and continues after a matching q=0 member, so a later acceptable occurrence is considered. Compressible media types are also recognized case-insensitively. #2600, #2590, #2606
  • Directory redirects preserve the client-facing path. For ordinary origin-form request targets, FS adds the trailing slash to the original encoded path and retains the query string. Prefix stripping and virtual-host rewriting no longer expose the internal filesystem lookup path in the redirect. #2551
  • DoRedirects preserves URL credentials on the initial request. Relative redirects retain URI credentials, while absolute redirects use only their own userinfo. An explicit Authorization header still takes precedence and follows the existing host-based forwarding rules. #2531
  • URI updates separate queries from fragments. Updating a URI with ?next=2#new now stores next=2 as the query and new as the fragment, keeping the fragment out of the HTTP request line. Explicit empty query delimiters are preserved, including a redirect target ending in ?. Hosts with an empty port, such as example.com: or [::1]:, now receive the scheme's default port when dialing. #2592, #2603
  • Repeated cookies and suppressed content types retain their meaning. ResponseHeader.PeekAll("Set-Cookie") returns each cookie separately instead of joining them into one value; Peek is unchanged. Adapted net/http handlers that set Content-Type to nil or empty now send no default content type, on both buffered and flushed responses. #2599, #2556

This release also adds a WebSocket README, reorganizes its tests, addresses intermittent CI failures, and clarifies retry callback eligibility and fragmented input to Request.Read.

What's Changed

Security and hardening

Features

  • feat: add helper APIs for downstream frameworks by @gaby in #2520
  • feat: make the unsupported method and unknown transfer coding errors matchable by @gaby in #2594

Fixes

  • fix(header): keep scanning Accept-Encoding after a q=0 member by @CJstate in #2590
  • fix(fs): redirect a directory request to the path the client sent by @Dv2Corn in #2551
  • fix: don't drop the URI userinfo in DoRedirects by @LuisFigueroaG in #2531
  • fix(client): add the default port to a host with an empty port by @ruziba3vich in #2603
  • fix(header): read every Accept-Encoding line in HasAcceptEncoding by @ruziba3vich in #2600
  • fix: separate fragments in query-only URI updates by @anishpentyala in #2592
  • fix(header): return each Set-Cookie value from ResponseHeader.PeekAll by @ruziba3vich in #2599
  • fasthttpadaptor: send no Content-Type when the handler sets it to nil by @jaeminbird in #2556
  • fix: recognize compressible media types case-insensitively by @Twiink in #2606

Documentation and tests

Dependency updates

  • chore(deps): bump golang.org/x/crypto from 0.58.0 to 0.59.0 by @dependabot[bot] in #2588

New Contributors

Full Changelog: v1.79.0...v1.80.0

Don't miss a new fasthttp release

NewReleases is sending notifications on new releases.