Skip to content

Commit

Permalink
Fix headers being carried between parts. fixes #63 (#135)
Browse files Browse the repository at this point in the history
The contents of the headers dict wasn't cleared when a new part started, If the second part didn't overwrite the header value, it would appear in the wrong part.
  • Loading branch information
jhnstrk authored Apr 18, 2024
1 parent 3ea51c7 commit 8b85d35
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
4 changes: 3 additions & 1 deletion multipart/multipart.py
Original file line number Diff line number Diff line change
Expand Up @@ -1613,7 +1613,9 @@ def _on_end() -> None:
is_file = False

def on_part_begin():
pass
# Reset headers in case this isn't the first part.
nonlocal headers
headers = {}

def on_part_data(data: bytes, start: int, end: int) -> None:
nonlocal writer
Expand Down
23 changes: 23 additions & 0 deletions tests/test_data/http/mixed_plain_and_base64_encoding.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
----boundary
Content-Type: text/plain; charset="UTF-8"
Content-Disposition: form-data; name=field1
Content-Transfer-Encoding: base64

VGVzdCAxMjM=
----boundary
Content-Type: text/plain; charset="UTF-8"
Content-Disposition: form-data; name=field2

This is a test.
----boundary
Content-Type: text/plain; charset="UTF-8"
Content-Disposition: form-data; name=field3
Content-Transfer-Encoding: base64

VGVzdCBzdHJpbmcuCg==
----boundary
Content-Type: text/plain; charset="UTF-8"
Content-Disposition: form-data; name=field4

This is also a test.
----boundary--
18 changes: 18 additions & 0 deletions tests/test_data/http/mixed_plain_and_base64_encoding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
boundary: --boundary
expected:
- name: field1
type: field
data: !!binary |
VGVzdCAxMjM=
- name: field2
type: field
data: !!binary |
VGhpcyBpcyBhIHRlc3Qu
- name: field3
type: field
data: !!binary |
VGVzdCBzdHJpbmcuCg==
- name: field4
type: field
data: !!binary |
VGhpcyBpcyBhbHNvIGEgdGVzdC4=

0 comments on commit 8b85d35

Please sign in to comment.