Response Builder¶
-
class
eynnyd.response_builder.
ResponseBuilder
[source]¶ A builder allowing for the easy and validated building of a Response.
-
set_status
(status)[source]¶ Sets the HTTP status of the response. Raises if the type conflicts with other attributes of the response.
- Parameters
status – a value indicating response status (can be an int, http.HTTPStatus or Eynnyd HttpStatus)
- Returns
This builder to allow for fluent design.
-
set_utf8_body
(body)[source]¶ Sets a utf8 body on the request (overwriting any other set body). Raises if setting the body conflicts with the status. Sets a content-length header if one has not already been set.
- Parameters
body – The utf-8 encoded body
- Returns
This builder to allow for fluent design.
-
set_byte_body
(body)[source]¶ Sets a byte body on the request (overwriting any other set body). Raises if setting the body conflicts with the status. Sets a content-length header if one has not already been set.
- Parameters
body – The bytes encoded body
- Returns
This builder to allow for fluent design.
-
set_stream_body
(body)[source]¶ Sets a streaming body on the request (overwriting any other set body). Raises if setting the body conflicts with the status.
- Parameters
body – A streamable object with a read method taking 1 parameter (and an optional close method)
- Returns
This builder to allow for fluent design.
-
set_iterable_body
(body)[source]¶ Sets an iterable body on the request (overwriting any other set body). Raises if setting the body conflicts with the status.
For simple strings you should use the utf-8 body as using this would be highly inefficient.
- Parameters
body – The iterable body
- Returns
This builder to allow for fluent design.
-
unset_body
()[source]¶ Unsets the body on the request.
- Returns
This builder to allow for fluent design.
-
set_headers
(headers_by_name)[source]¶ Sets the headers on the response (deleting/overwriting all current headers).
Raises if this method is attempted to be used to set cookies. Use the set_cookies/add_cookie methods for that.
- Parameters
headers_by_name – a dictionary of header values keyed by name
- Returns
This builder to allow for fluent design.
-
add_header
(name, value)[source]¶ Adds a single header to the response.
Raises if this method is attempted to be used to set cookies. Use the set_cookies/add_cookie methods for that.
- Parameters
name – the name to use for the header
value – the value to store in the header
- Returns
This builder to allow for fluent design.
-
remove_header
(name)[source]¶ Removes a header from the response by name.
- Parameters
name – The name for the header to remove.
- Returns
This builder to allow for fluent design.
Sets all the cookies on the response (deleting/overwriting any previously set).
- Parameters
cookies – An iterable of Eynnyd ResponseCookie objects.
- Returns
This builder to allow for fluent design.
Adds a single cookie to the response.
- Parameters
cookie – an Eynnyd ResponseCookie object.
- Returns
This builder to allow for fluent design.
Adds a simple cookie to the response (allowing the skipping of using Eynnyd specific objects).
- Parameters
name – An rfc valid name for the cookie.
value – An rfc valid value for the cookie.
- Returns
This builder to allow for fluent design.
Removes a cookie from the response by name.
- Parameters
name – the name of the cookie to remove.
- Returns
This builder to allow for fluent design.
-