bugger.
All challenges/Pythonhardthe-response-that-never-finishes-v1
THE INVESTIGATION

The response that never finishes

A bounded HTTP client still accepts unbounded interim replies and discarded trailers.

HTTPResource limitsProtocol parsing

What’s going wrong

A client caps normal response headers but can remain occupied by a peer that keeps sending informational replies or chunked trailers. Read the response phases and trace the lifetime of each resource budget.

Stdin JSON has limits.fields and limits.interim (nonnegative integers at most 20) plus responses, a list of independent ASCII HTTP wire strings. Each string contains zero or more 100/103 informational responses, followed by a final 200 chunked response or a 204 with no body. Every header section ends with CRLF CRLF. For 200, chunks use hex lengths and CRLF, ending with a zero chunk and a trailer section ending in a blank line. Inputs are otherwise valid; size extensions, transfer encoding negotiation, 101 upgrades, malformed input and pipelining are outside this contract.

Enforce limits.fields separately on EACH header section and on the trailer section: nonempty field lines count; the terminating blank line does not. At most limits.interim informational responses are allowed per wire string. Exact limits are valid. Body bytes do not count as fields. Check a header section before deciding whether its status is informational. Each response starts fresh budgets.

Print one JSON array. Successful entries contain status and concatenated body (empty for 204). Reject excess headers, trailers or informational responses with a single object {"error":"headers_limit"}, {"error":"trailers_limit"}, or {"error":"interim_limit"}. Stop that wire string at its first violation and continue with the next independent string. Do not replace bounded reading with blanket rejection of legal trailers or informational responses.

Expected behavior

A bounded HTTP client still accepts unbounded interim replies and discarded trailers.

Reproduction

01 Trailers bypass the header budget
{"limits":{"fields":1,"interim":1},"responses":["HTTP/1.1 200 Final\r\nX: v\r\n\r\n2\r\nok\r\n0\r\nT: v\r\nT: v\r\n\r\n"]}
[{"error":"trailers_limit"}]
02 Ordinary chunked response
{"limits":{"fields":2,"interim":1},"responses":["HTTP/1.1 200 Final\r\nX: v\r\n\r\n2\r\nok\r\n0\r\nT: v\r\n\r\n"]}
[{"status":200,"body":"ok"}]
03 Informational responses keep arriving
{"limits":{"fields":2,"interim":1},"responses":["HTTP/1.1 103 Early Hints\r\nLink: /a\r\n\r\nHTTP/1.1 103 Early Hints\r\nLink: /a\r\n\r\nHTTP/1.1 200 Final\r\nX: v\r\n\r\n2\r\nok\r\n0\r\n\r\n"]}
[{"error":"interim_limit"}]

Before you begin

  • Python state machines
  • Event ordering and invariants
  • Regression test design

Need a nudge?

Reveal one investigation hint at a time. Try each clue before opening the next.

    The bug is intentional. Run the starter code to see it fail, then work toward a fix. Difficulty is provisional.
    Read-only preview
    Ready when you are
    Every fix starts with a failing test.

    Read the report, then sign in to start your investigation.