Response

Container for an HTTP response.

Constructors

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

Members

Functions

parse
bool 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
void redirect(Status status, string location)
void redirect(string location)
void redirect(uint statusCode, string location)

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

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.

Variables

status
Status status;

Status of the response.

valid
bool valid;

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

Inherited Members

From HTTP

VERSION
enum VERSION;
Undocumented in source.
GET
enum GET;
Undocumented in source.
POST
enum POST;
Undocumented in source.
method
string method;

Method used.

headers
string[string] headers;

Headers of the request/response.

_body
string _body;
Undocumented in source.
body_
string body_ [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
body_
void[] body_ [@property setter]
Undocumented in source. Be warned that the author may not have intended to support it.

Examples

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

Meta