watson.http.headers¶
- class watson.http.headers.HeaderDict(args=None)[source]¶
A dictionary of headers and their values.
Contains a collection of key/value pairs that define a set of headers for either a http request or response (e.g. HTTP_ACCEPT)
- add(field, value, replace=False, **options)[source]¶
Adds a header to the collection.
Example:
# Content-Type: text/html; charset=utf-8 headers = HeaderCollection() headers.add('Content-Type', 'text/html', charset='utf-8')
Parameters: - field – the field name of the header
- value – the value for the header
- options – any other keyword args to add to the value
- get_option(field, option, default=None)[source]¶
Retrieve an individual option from a header.
Example:
# Content-Type: text/html; charset=utf-8 headers = HeaderCollection() headers.add('Content-Type', 'text/html', charset='utf-8') option = headers.get_option('Content-Type', 'charset') # utf-8
Parameters: - field – the header field
- option – the option to retrieve from the field
- default – the default value if the option does not exist
Returns: The default value or the value from the option
- watson.http.headers.parse_from_environ_header_field(field)[source]¶
Converts a http header field into a lowercase form.