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.http_header(field)[source]

Return the correct header field name.

watson.http.headers.is_header(field)[source]

Determine if a field is an acceptable http header.

watson.http.headers.parse_from_environ_header_field(field)[source]

Converts a http header field into a lowercase form.

watson.http.headers.parse_to_environ_header_field(field)[source]

Converts a http header field into an uppercase form.

watson.http.headers.split_headers_server_vars(environ)[source]

Splits the environ into headers and server pairs.