class documentation

class twisted.web.http_headers.Headers: (source)

View In Hierarchy

Stores HTTP headers in a key and multiple value format.

When passed str, header names (e.g. 'Content-Type') are encoded using ISO-8859-1 and header values (e.g. 'text/html;charset=utf-8') are encoded using UTF-8. Some methods that return values will return them in the same type as the name given.

If the header keys or values cannot be encoded or decoded using the rules above, using just bytes arguments to the methods of this class will ensure no decoding or encoding is done, and Headers will treat the keys and values as opaque byte strings.

Method __init__ Undocumented
Method __repr__ Return a string fully describing the headers set on this object.
Method __cmp__ Define Headers instances as being equal to each other if they have the same raw headers.
Method copy Return a copy of itself with the same headers set.
Method hasHeader Check for the existence of a given header.
Method removeHeader Remove the named header from this header object.
Method setRawHeaders Sets the raw representation of the given header.
Method addRawHeader Add a new raw value for the given header.
Method getRawHeaders Returns a list of headers matching the given name as the raw string given.
Method getAllRawHeaders Return an iterator of key, value pairs of all headers contained in this object, as bytes. The keys are capitalized in canonical capitalization.
Class Variable _caseMappings A dict that maps lowercase header names to their canonicalized representation.
Instance Variable _rawHeaders A dict mapping header names as bytes to lists of header values as bytes.
Method _encodeName Encode the name of a header (eg 'Content-Type') to an ISO-8859-1 encoded bytestring if required.
Class Variable _T Undocumented
Method _canonicalNameCaps Return the canonical name for the given header.
_caseMappings = (source)
A dict that maps lowercase header names to their canonicalized representation.
(type: dict[bytes, bytes])
_rawHeaders = (source)
A dict mapping header names as bytes to lists of header values as bytes.
(type: Dict[bytes, List[bytes]])
def __init__(self, rawHeaders=None): (source)

Undocumented

ParametersrawHeadersUndocumented (type: Optional[Mapping[AnyStr, Sequence[AnyStr]]])
def __repr__(self): (source)

Return a string fully describing the headers set on this object.

ReturnsUndocumented (type: str)
def __cmp__(self, other): (source)

Define Headers instances as being equal to each other if they have the same raw headers.

def _encodeName(self, name): (source)

Encode the name of a header (eg 'Content-Type') to an ISO-8859-1 encoded bytestring if required.

ParametersnameA HTTP header name (type: AnyStr)
Returnsname, encoded if required, lowercased (type: bytes)
def copy(self): (source)

Return a copy of itself with the same headers set.

ReturnsA new Headers
def hasHeader(self, name): (source)

Check for the existence of a given header.

ParametersnameThe name of the HTTP header to check for. (type: AnyStr)
ReturnsTrue if the header exists, otherwise False. (type: bool)
def removeHeader(self, name): (source)

Remove the named header from this header object.

ParametersnameThe name of the HTTP header to remove. (type: AnyStr)
ReturnsNone
def setRawHeaders(self, name, values): (source)

Sets the raw representation of the given header.

ParametersnameThe name of the HTTP header to set the values for. (type: AnyStr)
valuesA list of strings each one being a header value of the given name. (type: Sequence[AnyStr])
ReturnsNone
RaisesTypeErrorRaised if values is not a list of bytes or str strings, or if name is not a bytes or str string.
def addRawHeader(self, name, value): (source)

Add a new raw value for the given header.

ParametersnameThe name of the header for which to set the value. (type: AnyStr)
valueThe value to set for the named header. (type: AnyStr)

Undocumented

def getRawHeaders(self, name, default=None): (source)

Returns a list of headers matching the given name as the raw string given.

ParametersnameThe name of the HTTP header to get the values of. (type: AnyStr)
defaultThe value to return if no header with the given name exists. (type: Optional[_T])
ReturnsIf the named header is present, a list of its values. Otherwise, default. (type: Union[List[AnyStr], Optional[_T]])
def getAllRawHeaders(self): (source)

Return an iterator of key, value pairs of all headers contained in this object, as bytes. The keys are capitalized in canonical capitalization.

ReturnsUndocumented (type: Iterator[Tuple[bytes, List[bytes]]])
def _canonicalNameCaps(self, name): (source)

Return the canonical name for the given header.

ParametersnameThe all-lowercase header name to capitalize in its canonical form. (type: bytes)
ReturnsThe canonical name of the header. (type: bytes)
API Documentation for Twisted, generated by pydoctor 20.12.1 at 2021-02-28 19:53:36.