Skip to content

Commit 8b85d35

Browse files
authored
Fix headers being carried between parts. fixes #63 (#135)
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.
1 parent 3ea51c7 commit 8b85d35

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

multipart/multipart.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1613,7 +1613,9 @@ def _on_end() -> None:
16131613
is_file = False
16141614

16151615
def on_part_begin():
1616-
pass
1616+
# Reset headers in case this isn't the first part.
1617+
nonlocal headers
1618+
headers = {}
16171619

16181620
def on_part_data(data: bytes, start: int, end: int) -> None:
16191621
nonlocal writer
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
----boundary
2+
Content-Type: text/plain; charset="UTF-8"
3+
Content-Disposition: form-data; name=field1
4+
Content-Transfer-Encoding: base64
5+
6+
VGVzdCAxMjM=
7+
----boundary
8+
Content-Type: text/plain; charset="UTF-8"
9+
Content-Disposition: form-data; name=field2
10+
11+
This is a test.
12+
----boundary
13+
Content-Type: text/plain; charset="UTF-8"
14+
Content-Disposition: form-data; name=field3
15+
Content-Transfer-Encoding: base64
16+
17+
VGVzdCBzdHJpbmcuCg==
18+
----boundary
19+
Content-Type: text/plain; charset="UTF-8"
20+
Content-Disposition: form-data; name=field4
21+
22+
This is also a test.
23+
----boundary--
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
boundary: --boundary
2+
expected:
3+
- name: field1
4+
type: field
5+
data: !!binary |
6+
VGVzdCAxMjM=
7+
- name: field2
8+
type: field
9+
data: !!binary |
10+
VGhpcyBpcyBhIHRlc3Qu
11+
- name: field3
12+
type: field
13+
data: !!binary |
14+
VGVzdCBzdHJpbmcuCg==
15+
- name: field4
16+
type: field
17+
data: !!binary |
18+
VGhpcyBpcyBhbHNvIGEgdGVzdC4=

0 commit comments

Comments
 (0)