@@ -68,12 +68,14 @@ def finalize(self) -> None: ...
6868 def close (self ) -> None : ...
6969
7070 class FieldProtocol (_FormProtocol , Protocol ):
71- def __init__ (self , name : bytes | None ) -> None : ...
71+ def __init__ (self , name : bytes , headers : dict [str ,bytes ]) -> None :
72+ ...
7273
7374 def set_none (self ) -> None : ...
7475
7576 class FileProtocol (_FormProtocol , Protocol ):
76- 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 :
78+ ...
7779
7880 OnFieldCallback = Callable [[FieldProtocol ], None ]
7981 OnFileCallback = Callable [[FileProtocol ], None ]
@@ -223,9 +225,10 @@ class Field:
223225 name: The name of the form field.
224226 """
225227
226- def __init__ (self , name : bytes | None ) -> None :
228+ def __init__ (self , name : bytes , headers : dict [ str , bytes ] = {} ) -> None :
227229 self ._name = name
228230 self ._value : list [bytes ] = []
231+ self ._headers : dict [str ,bytes ] = headers
229232
230233 # We cache the joined version of _value for speed.
231234 self ._cache = _missing
@@ -317,6 +320,11 @@ def value(self) -> bytes | None:
317320 assert isinstance (self ._cache , bytes ) or self ._cache is None
318321 return self ._cache
319322
323+ @property
324+ def headers (self ) -> dict [str ,bytes ]:
325+ """This property returns the headers of the field."""
326+ return self ._headers
327+
320328 def __eq__ (self , other : object ) -> bool :
321329 if isinstance (other , Field ):
322330 return self .field_name == other .field_name and self .value == other .value
@@ -357,17 +365,18 @@ class File:
357365 config: The configuration for this File. See above for valid configuration keys and their corresponding values.
358366 """ # noqa: E501
359367
360- def __init__ (self , file_name : bytes | None , field_name : bytes | None = None , config : FileConfig = {}) -> None :
368+ def __init__ (self , file_name : bytes | None , field_name : bytes | None = None , headers : dict [ str , bytes ] = {}, config : FileConfig = {}) -> None :
361369 # Save configuration, set other variables default.
362370 self .logger = logging .getLogger (__name__ )
363371 self ._config = config
364372 self ._in_memory = True
365373 self ._bytes_written = 0
366374 self ._fileobj : BytesIO | BufferedRandom = BytesIO ()
367375
368- # Save the provided field/file name.
376+ # Save the provided field/file name and content type .
369377 self ._field_name = field_name
370378 self ._file_name = file_name
379+ self ._headers = headers
371380
372381 # Our actual file name is None by default, since, depending on our
373382 # config, we may not actually use the provided name.
@@ -420,6 +429,12 @@ def in_memory(self) -> bool:
420429 """
421430 return self ._in_memory
422431
432+ @property
433+ def headers (self ) -> dict [str ,bytes ]:
434+ """The headers for this part.
435+ """
436+ return self ._headers
437+
423438 def flush_to_disk (self ) -> None :
424439 """If the file is already on-disk, do nothing. Otherwise, copy from
425440 the in-memory buffer to a disk file, and then reassign our internal
0 commit comments