Repository navigation
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
Responseafter HEAD no longer makes subsequent requests skip their bodies. When a caller explicitly skips a potentially present body,ClientandHostClientclose the connection instead of pooling it with unread bytes.PipelineClientreads and discards the body so the next pipelined response starts at the correct boundary. The caller'sSkipBodysetting is preserved. #2533 - Compression preserves every
Varyline. AddingAccept-Encodingno longer removes laterVaryfields, such asVary: Cookie. This fixes a regression that could let a shared cache reuse a response without considering all of its original variation criteria. BothCompressHandlerand compressed static-file serving are covered. #2598 - Unsigned float parsing rejects non-finite values and negative zero.
ParseUfloatand the argument getters that use it now reject NaN, infinity, and-0. Finite formats accepted bystrconv.ParseFloat, including a leading+, digit separators, and hexadecimal floats, remain supported. #2546
Features
- Bounded decompression helpers work directly on byte slices.
AppendGunzipBytesWithLimit,AppendInflateBytesWithLimit,AppendUnbrotliBytesWithLimit, andAppendUnzstdBytesWithLimitappend decoded data while enforcing a limit on newly decoded bytes. Existing data in the destination does not count toward the limit. Exceeding the limit returnsErrBodyTooLarge; 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()andResponseHeader.NormalizingDisabled()expose the current setting.HasNonHTTPSchemeWithoutAuthorityidentifies locations such asmailto:and native-app callbacks, andDefaultMaxRedirectsCountexports the existing default of 16.DoRedirectscontinues to use the count explicitly supplied by its caller. #2520 - Unsupported methods and unknown transfer codings have matchable errors.
errors.Iscan identifyErrUnsupportedRequestMethodregardless ofSecureErrorLogMessage. The newErrUnknownTransferCodingdistinguishes a well-formed but unsupported transfer coding from malformed framing and also matchesErrUnsupportedTransferEncoding. 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.
HasAcceptEncodingscans everyAccept-Encodingheader line and continues after a matchingq=0member, 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,
FSadds 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 DoRedirectspreserves URL credentials on the initial request. Relative redirects retain URI credentials, while absolute redirects use only their own userinfo. An explicitAuthorizationheader still takes precedence and follows the existing host-based forwarding rules. #2531- URI updates separate queries from fragments. Updating a URI with
?next=2#newnow storesnext=2as the query andnewas 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 asexample.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;Peekis unchanged. Adaptednet/httphandlers that setContent-Typeto 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
- fix(client): don't let SkipBody desync reused responses and connections by @waw666waw666 in #2533
- fix: don't drop later Vary lines when adding Accept-Encoding by @waw666waw666 in #2598
- fix: reject NaN, infinity and negative zero in ParseUfloat by @Kernel-Hunter in #2546
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
- websocket: sort the tests by file, tidy names and comments, add a README by @h2zi in #2558
- websocket: skip the tests that are flaky on Windows by @h2zi in #2587
- Fix five tests that fail intermittently in CI by @h2zi in #2589
- Fix typos in test comments by @ninglinLiu in #2596
- docs: clarify retry callback eligibility by @wozhenbang2004 in #2604
- docs: explain fragmented input to Request.Read by @wozhenbang2004 in #2605
Dependency updates
- chore(deps): bump golang.org/x/crypto from 0.58.0 to 0.59.0 by @dependabot[bot] in #2588
New Contributors
- @waw666waw666 made their first contribution in #2533
- @Kernel-Hunter made their first contribution in #2546
- @ninglinLiu made their first contribution in #2596
- @ruziba3vich made their first contribution in #2603
- @anishpentyala made their first contribution in #2592
- @wozhenbang2004 made their first contribution in #2604
- @Twiink made their first contribution in #2606
Full Changelog: v1.79.0...v1.80.0