The upload that cannot replay
A redirected upload reuses its advertised length after its stream has already been consumed.
What’s going wrong
A POST upload succeeds once but sends an empty payload after a body-preserving redirect. Its advertised length still describes the original body. Fix the stream lifecycle without replaying discarded bodies.
Stdin JSON has body (ASCII text), start (integer offset from 0 through its length), seekable (boolean), and redirects (at most 20 status codes chosen from 301,302,303,307,308). One POST is sent first using the suffix beginning at start. Reading consumes the stream. Every listed status triggers another send; final success is implicit. 301/302/303 change the request to GET and permanently remove its body and length. 307/308 preserve the current method/body. For each preserved redirect with a nonempty body, restore the recorded initial cursor before sending. A nonseekable stream cannot be restored: stop before the next send with error unrewindable. A zero-length body needs no rewind.
Print {"sent":[...],"error":null or "unrewindable"}. Each sent record has method, length (advertised byte count), and body (actual text sent). Retain history on failure. ASCII makes characters equal bytes in this later exercise; focus on cursor ownership, not encoding.
Expected behavior
Maintain framing invariants across consumed resources, replay failures and method changes.
Reproduction
{"body":"data","start":0,"seekable":true,"redirects":[307]}{"sent":[{"method":"POST","length":4,"body":"data"},{"method":"POST","length":4,"body":"data"}],"error":null}{"body":"data","start":0,"seekable":false,"redirects":[]}{"sent":[{"method":"POST","length":4,"body":"data"}],"error":null}{"body":"data","start":0,"seekable":false,"redirects":[303]}{"sent":[{"method":"POST","length":4,"body":"data"},{"method":"GET","length":0,"body":""}],"error":null}Before you begin
- Build on byte lengths and redirect state: immutable request metadata must stay consistent with mutable stream position.
- Python strings, lists and dictionaries
- Read the report contract before changing code
Need a nudge?
Reveal one investigation hint at a time. Try each clue before opening the next.
Read the report, then sign in to start your investigation.