Repository navigation
Decode chunked request bodies before passing them to httpbin - #101
Open
pylaterreur wants to merge 1 commit into
Open
pylaterreur wants to merge 1 commit into
pylaterreur wants to merge 1 commit into
Conversation
wsgiref doesn't decode chunked request bodies, and httpbin answers them with a 501 without reading them, unless it runs under gunicorn. So a chunked upload got a 501 instead of an echo, and since the server then closed the connection, a client still sending the body got a broken pipe. Decode the body in Handler, and give it to the application with a Content-Length. A malformed chunked body gets a 400. Fixes kevin1024#33 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GwUvhmzgfkiZ6vo4uGyesN
This was referenced Oct 2, 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.
Fixes #33.
Chunked uploads don't work against the local server:
requests.post(httpbin + "/post", data=some_generator)gets a 501 instead of an echo. wsgiref doesn't decode chunked request bodies. httpbin answers chunked requests with a 501, without reading them, unless it runs under gunicorn, which decodes them for it (see itsbefore_requesthook). The server then closes the connection, so a client still sending the body gets a broken pipe instead of the 501.That broken pipe is why VCR.py's tests for chunked uploads fail now and then. kevin1024/vcrpy#1002 tried to work around it in VCR.py, but as noted there, the limitation is in the wsgiref server pytest-httpbin uses.
Fix
When a request has
Transfer-Encoding: chunked,Handlernow reads and decodes the body itself, and gives it to the application with aContent-Length, like any other request. Chunk extensions and trailer fields are ignored, and a malformed chunked body gets a 400.As a result, httpbin echoes the body of chunked uploads, and reports a
Content-Lengthheader instead ofTransfer-Encoding.Tests
tests/test_server.py, all of which fail on master:test_dont_crash_on_handshake_timeoutfailed once on PyPy 3.11 on macOS, then passed when re-run. Its captured log line lacked the final newline: the test reads the output as soon as the server closes the socket, possibly before the server thread has finished printing. This change doesn't touch that test or the code it covers.Server.url. flake8 6.0.0 reports the same on master when run on Python 3.12 or later.🤖 Generated with Claude Code
https://claude.ai/code/session_01GwUvhmzgfkiZ6vo4uGyesN