Skip multipart preamble bytes before the first boundary

KL
12d ago
+192-4

Summary

  • Add a PREAMBLE parser state that ignores bytes before the first boundary delimiter, per RFC 2046 section 5.1.1. Closes #59.
  • Raise MultipartParseError in finalize() 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 through START_BOUNDARY (unchanged), anything else enters PREAMBLE and 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_tests to 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.