Skip to content

Commit 79866ba

Browse files
committed
Adding headers
1 parent 8b85d35 commit 79866ba

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

multipart/multipart.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,14 @@ def close(self) -> None:
6767
...
6868

6969
class FieldProtocol(_FormProtocol, Protocol):
70-
def __init__(self, name: bytes) -> None:
70+
def __init__(self, name: bytes, headers: dict[str,bytes]) -> None:
7171
...
7272

7373
def set_none(self) -> None:
7474
...
7575

7676
class FileProtocol(_FormProtocol, Protocol):
77-
def __init__(self, file_name: bytes | None, field_name: bytes | None, config: FileConfig) -> None:
77+
def __init__(self, file_name: bytes | None, field_name: bytes | None, headers: dict[str,bytes], config: FileConfig) -> None:
7878
...
7979

8080
OnFieldCallback = Callable[[FieldProtocol], None]
@@ -214,9 +214,10 @@ class Field:
214214
name: The name of the form field.
215215
"""
216216

217-
def __init__(self, name: bytes) -> None:
217+
def __init__(self, name: bytes, headers: dict[str,bytes]={}) -> None:
218218
self._name = name
219219
self._value: list[bytes] = []
220+
self._headers: dict[str,bytes] = headers
220221

221222
# We cache the joined version of _value for speed.
222223
self._cache = _missing
@@ -307,6 +308,11 @@ def value(self) -> bytes | None:
307308

308309
return self._cache
309310

311+
@property
312+
def headers(self) -> dict[str,bytes]:
313+
"""This property returns the headers of the field."""
314+
return self._headers
315+
310316
def __eq__(self, other: object) -> bool:
311317
if isinstance(other, Field):
312318
return self.field_name == other.field_name and self.value == other.value
@@ -347,17 +353,18 @@ class File:
347353
config: The configuration for this File. See above for valid configuration keys and their corresponding values.
348354
""" # noqa: E501
349355

350-
def __init__(self, file_name: bytes | None, field_name: bytes | None = None, config: FileConfig = {}) -> None:
356+
def __init__(self, file_name: bytes | None, field_name: bytes | None = None, headers: dict[str,bytes] = {}, config: FileConfig = {}) -> None:
351357
# Save configuration, set other variables default.
352358
self.logger = logging.getLogger(__name__)
353359
self._config = config
354360
self._in_memory = True
355361
self._bytes_written = 0
356362
self._fileobj = BytesIO()
357363

358-
# Save the provided field/file name.
364+
# Save the provided field/file name and content type.
359365
self._field_name = field_name
360366
self._file_name = file_name
367+
self._headers = headers
361368

362369
# Our actual file name is None by default, since, depending on our
363370
# config, we may not actually use the provided name.
@@ -410,6 +417,12 @@ def in_memory(self) -> bool:
410417
"""
411418
return self._in_memory
412419

420+
@property
421+
def headers(self) -> dict[str,bytes]:
422+
"""The headers for this part.
423+
"""
424+
return self._headers
425+
413426
def flush_to_disk(self) -> None:
414427
"""If the file is already on-disk, do nothing. Otherwise, copy from
415428
the in-memory buffer to a disk file, and then reassign our internal

0 commit comments

Comments
 (0)