Extract multipart header-size validation into a method

Closed
KL
3d ago
+46-11

Replace the advance_header_size closure with inline counter increments and a shared _check_header_size(size, offset) method. This keeps i and current_header_size as ordinary locals without duplicating validation or changing when errors are raised.

This targets main after #370, independently of #369. Callback handling and workflows are unchanged. Use the existing CodSpeed benchmarks to check whether this isolated change improves performance; no speedup is assumed.

Add public-API tests for limits in header names, leading spaces, and values, including exact limits, split writes, error offsets, and size-check-before-validation ordering. The new cases also pass against unchanged main.

Validation on Python 3.13.18: scripts/check, scripts/test --strict-config --strict-markers (201 tests, 100% coverage), and scripts/rename pass.

Session: pi --session 01a1e0a2-78a9-7473-86ce-b992bd92cf74