Skip to content

Fix empty multipart chunk boundaries - #405

Draft
lexingtonhibiki wants to merge 1 commit into
requests:mainfrom
lexingtonhibiki:fix/empty-multipart-chunk-boundary
Draft

lexingtonhibiki wants to merge 1 commit into
requests:mainfrom
lexingtonhibiki:fix/empty-multipart-chunk-boundary

Conversation

@lexingtonhibiki

Copy link
Copy Markdown

Problem

Related to #218. The historical read-all exception is already avoided, but empty encoders still produce a malformed closing boundary when read in small chunks.

For MultipartEncoder({}, boundary='boundary'), .len is 14. Repeated read(1) currently emits b'--boundary\r\n--\r\n' (16 bytes), rather than b'--boundary--\r\n'. The initial boundary's CRLF can be consumed before the lazy closing-boundary rewrite occurs. Empty lists and partial-read-then-read-all have the same issue.

Change

Finalize the empty encoder's closing boundary during initialization, before any bytes can be consumed. Nonempty encoders keep the existing path. Add 22 parametrized regression cases for empty mappings/lists, chunk sizes and mixed read patterns; update AUTHORS and HISTORY.

Validation

Python 3.12, local offline execution with socket, DNS and subprocess guards (zero attempted operations):

These full-suite counts use pytest tests -o addopts='' -q -W ignore::DeprecationWarning through the offline guard runner. With warnings treated as errors instead, the fixed tree still has 28 preexisting deprecation failures (baseline with new tests: 42 failures, including the 14 regressions). This change does not address those unrelated failures.

An independent AI review/probe covered 184 read sequences: baseline 18 failures, fixed zero, including nonempty controls, read(0), partial/read-all and repeated EOF. A separate 12-case monitor probe checked callbacks, bytes_read and lengths for empty and nonempty bodies. Production flake8 and git diff --check pass.

AI-assisted implementation and independent AI review; no human review is claimed. Older Python runtimes and live HTTP were not exercised locally. Kept as a draft for maintainer review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants