Reject oversized streams before buffering them
An input size limit is ineffective if the server reads the entire body before checking it. Enforce the byte budget incrementally while consuming chunks, and stop as soon as the accepted prefix plus the next chunk exceeds the bound.
Text characters and encoded bytes are different units. This exercise accepts byte chunks and returns exact bytes without decoding. It also tests that the producer is not consumed after rejection. A service must apply corresponding limits at ingress and decompression boundaries, because a small compressed request can expand far beyond its wire size.
text="я"
print(len(text))
print(len(text.encode("utf-8")))Review the design
The bound limits accepted bytes and buffering, but the producer may already have allocated a large individual chunk. A complete transport should also bound chunk allocation and decoded or decompressed output.
Your task
Implement bounded_body(chunks,limit) joining byte chunks only while the cumulative length is <=limit. Reject negative limit or oversized input with ValueError; stop consuming immediately on overflow.
The explanation opens here once every check passes.