Response

Container for an HTTP response.

Constructors

this
this(Status status, string[string] headers, string content)
Undocumented in source.
this
this(uint statusCode, string[string] headers, string content)
Undocumented in source.
this
this(Status status, string content)
Undocumented in source.
this
this(uint statusCode, string content)
Undocumented in source.

Members

Functions

toString
string toString()

Encodes the response into a string. The Content-Length header field is created automatically based on the length of the content field.

Static functions

error
Response error(Status status, string[string] headers)
Response error(uint statusCode, string[string] headers)

Creates a response for an HTTP error an automatically generates an HTML page to display it.

parse
Response parse(string str)

Parses a string and returns a Response. If the response is successfully parsed Response.valid will be true. Please note that every key in the header is converted to lowercase for an easier search in the associative array.

redirect
Response redirect(Status status, string location, string[string] headers)
Response redirect(uint statusCode, string location, string[string] headers)
Response redirect(string location, string[string] headers)

Creates a 3xx redirect response and adds the Location field to the header. If not specified status code 301 Moved Permanently will be used.

Variables

content
string content;

Content of the request. Its type should be specified in the content-type field in the headers.

headers
string[string] headers;

HTTP headers of the request.

status
Status status;

Status of the response.

valid
bool valid;

If the response was parsed, indicates whether it was in a valid HTTP format.

Examples

Response(200, ["Connection": "Close"], "<b>Hi there</b>");
Response(404, [], "Cannot find the specified path");
Response(204);

Meta