Skip multipart preamble bytes before the first boundary
Ā
KL
12d ago+192+192+012345678901234567890123456789-4-4-0123456789
Summary
- Add a
PREAMBLEparser state that ignores bytes before the first boundary delimiter, per RFC 2046 section 5.1.1. Closes #59. - Raise
MultipartParseErrorinfinalize()if no boundary was ever found, preserving the existing behavior for garbage input. - The first non-CRLF byte determines the branch: a leading
-still routes throughSTART_BOUNDARY(unchanged), anything else entersPREAMBLEand scans forward for the boundary. This keeps all existing error cases (bad_initial_boundary,empty_message_with_bad_end) intact.
Test plan
- Two new HTTP fixtures (
preamble,preamble_mime_headers) covering the scenario from #59 (machine-generated payload with MIME-style headers before the first boundary). - Added both fixtures to
single_byte_teststo exercise the byte-by-byte path where the boundary straddles chunk boundaries. -
test_preamble_is_ignored,test_preamble_split_across_writes,test_finalize_raises_when_no_boundary_found. - All 141 tests pass, 100% line coverage, ruff + mypy clean.