Repository navigation
Conversation
This was referenced Nov 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR continues #5815 from my new account, @hainuoli. It preserves the same two commits and patch, including the follow-up addressing the original review. The original discussion remains in #5815.
Fixes #5820.
httpx.ParseJsonBodyskips valid JSON bodies whenContentLength == -1, as received with HTTP/1.1 chunked requests. Accept unknown lengths and preserve the existing behavior for genuinely empty bodies.For an unknown-length JSON body, read one byte through the existing bounded reader. An immediate EOF follows the empty-body mapping path, preserving optional fields, defaults, and required-field validation. Otherwise, replay the byte and continue JSON decoding. Other read errors are propagated, and whitespace-only bodies remain invalid JSON.
The parser's existing 8 MiB cap remains in place. The separately configured
MaxBytesHandlerlimit is addressed in companion PR #5879, including HTTP 413 responses for read-time size errors in the default error handlers.Regression tests cover non-empty unknown-length JSON, empty optional/default/required fields, whitespace-only bodies, and non-EOF read errors.
Validation for this migration:
go test -mod=readonly -race ./rest/httpx -count=1go vet -mod=readonly ./rest/httpxgofmtandgit diff --checkThe unchanged commit
2af395e96d67067c3f3be53996c4c6167e08dc54passed upstream Go (Linux and Windows), CodeQL, staticcheck, and patch coverage checks in #5815. Those are historical results from the original PR; checks for this replacement PR must run separately and may require maintainer approval.