interface documentation

class IHTTPHeaders(Interface): (source)

Known subclasses: klein._imessage.IMutableHTTPHeaders

Known implementations: klein._headers.FrozenHTTPHeaders

View In Hierarchy

HTTP entity headers.

HTTP headers names and values are sort-of-but-not-quite-specifically expected to be text.

Because the specifications are somewhat vague, and implementations vary in fidelity, both header names and values must be made available as the original bytes received from the network. This interface also makes them available as an ordered sequence of name and value pairs so that they can be iterated in the same order as they were received on the network.

As such, the rawHeaders attribute provides the header data as a sequence of (name, value) tuples.

A dictionary-like interface that maps text names to an ordered sequence of text values. This interface assumes that both header name bytes and header value bytes are encoded as ISO-8859-1.

Note that header name bytes should be strictly encoded as ASCII; this interface uses ISO-8859-1 to provide interoperability with (naughty) HTTP implementations that send non-ASCII data. Because ISO-8859-1 is a superset of ASCII, this will still work for well-behaved implementations.

Method getValues Get the values associated with the given header name.
Attribute rawHeaders Raw header data as a tuple in the from: ((name, value), ...). name and value are bytes. Headers are provided in the order that they were received. Headers with multiple values are provided as separate name and value pairs.
def getValues(name): (source)

Get the values associated with the given header name.

If the given name is bytes, the value will be returned as the raw header bytes.

If the given name is str, the name will be encoded as ISO-8859-1 and the value will be returned as text, by decoding the raw header value bytes with ISO-8859-1.

Parameters
name:AnyStrThe name of the header to look for.
Returns
Iterable[AnyStr]The values of the header with the given name.
rawHeaders: RawHeaders = (source)

Raw header data as a tuple in the from: ((name, value), ...). name and value are bytes. Headers are provided in the order that they were received. Headers with multiple values are provided as separate name and value pairs.