Repository navigation
Nonseekable multipart files can send an empty payload after a redirect #3828
Unanswered
SuhrudhC
asked this question in
Potential Issue
Replies: 1 comment
|
For anyone hitting this before there's a library fix, a with tempfile.SpooledTemporaryFile(max_size=1024 * 1024) as upload:
shutil.copyfileobj(source, upload)
upload.seek(0)
response = client.post(url, files={"file": ("example.bin", upload)}, follow_redirects=True)This is a caller-side workaround when the final URL isn't known up front. The extra cost is having to finish reading the source before the request starts. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
I checked this with help from Codex on HTTPX 0.28.1 and current source b5addb6, using Python 3.12 and a local transport that consumes request.stream directly.
After a 307 redirect, a multipart upload with a nonseekable readable file succeeds but sends an empty file payload on the second request. This runnable example uses no network server:
Observed output:
The same result occurs with 308 and with AsyncClient. Seekable files replay correctly, including files initially positioned at EOF.
This reproduces the remaining corner case already described in #2382 and #2249. The #2382 description says a nonseekable IOBase should raise StreamConsumed when it cannot repeat the upload. I found no matching open issue or PR in targeted searches, though those searches do not cover every discussion.
I prepared a small local candidate that tracks file consumption, resets that state after a successful rewind and raises StreamConsumed when replay cannot rewind. Sixteen sync and async redirect controls and two partial consumption controls pass. An unchanged isolated copy of the current multipart test module also passes all 38 tests. That isolated run omits the upstream root conftest and is not a full suite claim.
With the candidate, the example prints StreamConsumed and retains only the first complete payload. Would you consider this focused approach? No PR has been submitted.
All reactions