# `paste.response` – Utility functions for producing responses

Routines to generate WSGI responses

## Module Contents

class `paste.response.``HeaderDict`

  This represents response headers. It handles the headers as a dictionary, with case-insensitive keys.

  Also there is an `.add(key, value)` method, which sets the key, or adds the value to the current value (turning it into a list if necessary).

  For passing to WSGI there is a `.headeritems()` method which is like `.items()` but unpacks value that are lists. It also handles encoding – all headers are encoded in ASCII (if they are unicode).

  @@: Should that encoding be ISO-8859-1 or UTF-8? I’m not sure what the spec says.

`paste.response.``has_header`(headers, name)

  Is header named `name` present in headers?

`paste.response.``header_value`(headers, name)

  Returns the header’s value, or None if no such header. If a header appears more than once, all the values of the headers are joined with ‘,’. Note that this is consistent /w RFC 2616 section 4.2 which states:

  > It MUST be possible to combine the multiple header fields into one “field-name: field-value” pair, without changing the semantics of the message, by appending each subsequent field-value to the first, each separated by a comma.

  However, note that the original netscape usage of ‘Set-Cookie’, especially in MSIE which contains an ‘expires’ date will is not compatible with this particular concatination method.

`paste.response.``remove_header`(headers, name)

  Removes the named header from the list of headers. Returns the value of that header, or None if no header found. If multiple headers are found, only the last one is returned.

`paste.response.``replace_header`(headers, name, value)

  Updates the headers replacing the first occurance of the given name with the value provided; asserting that no further occurances happen. Note that this is _not_ the same as remove_header and then append, as two distinct operations (del followed by an append) are not atomic in a threaded environment. Returns the previous header value for the provided name, if any. Clearly one should not use this function with `set-cookie` or other names that may have more than one occurance in the headers.