7.3 ResponseMixin Class

#
7.3 ResponseMixin Class

The `ResponseMixin` class provides functionality to manage the delivery of the application response to the browser. The class maintains headers in a case insensitive ordered dictionary that ensures the headers are sent to the browser in the same sequence as they are set (via `set_header()` or `add_header`).

The class automatically sends the headers to the browser when the first content is sent. Any attempt to modify or send headers after they have been sent will raise an `ApplicationError` exception.

All Albatross execution context classes except for `SimpleContext` inherit from this class.

`__init__`( | )

  When you inherit from the `ResponseMixin` class you must call this constructor to initialise the internal variables.

`get_header`( | name)

  Returns a list of values of the name header from the internal store. If the header does not exist then `None` is returned.

`set_header`( | name, value)

  Sets the value of the name header to value in the internal store, replacing any existing headers of the same name.

  If headers have already been sent to the browser then an `ApplicationError` exception will be raised.

`add_header`( | name, value)

  Sets the value of the name header to value in the internal store, appending the new header immediately after any existing headers of the same name.

  If headers have already been sent to the browser then an `ApplicationError` exception will be raised.

`del_header`( | name)

  Removes the name header from the internal store.

  If headers have already been sent to the browser then an `ApplicationError` exception will be raised.

`write_headers`( | )

  Writes all headers in ascending sequence to the browser. Each header is sent via the `Request` object `write_header()` method. At the end of headers the `Request` object `end_headers()` method is called.

  If headers have already been sent to the browser then an `ApplicationError` exception will be raised.

`send_content`( | data)

  Sends the content in data to the browser via the `Request` object `write_content()` method.

  If headers have not already been delivered to the browser then the `write_headers()` method is called before the data is written.

`send_redirect`( | loc)

  If a cookie header has been set it is sent to the browser then the `redirect()` method of the `request` member is called and the result is returned.