HttpResponseEx

HttpResponse with some code to ease creating responses

Members

Aliases

copyTo
alias copyTo = typeof(super).copyTo
Undocumented in source.

Functions

authorize
bool authorize(HttpRequest request, bool delegate(string username, string password) authenticator)

Request a username and password.

cacheForever
void cacheForever()

Apply cacheForever on this response's headers.

copyTo
void copyTo(typeof(this) other)

For dup.

disableCache
void disableCache()

Apply disableCache on this response's headers.

dup
typeof(this) dup()
Undocumented in source. Be warned that the author may not have intended to support it.
redirect
HttpResponseEx redirect(string location, HttpStatusCode status)

Redirect the UA to another location

serveData
HttpResponseEx serveData(string data, string contentType)

Utility function to serve HTML.

serveData
HttpResponseEx serveData(DataVec data, string contentType)
HttpResponseEx serveData(Data data, string contentType)

Utility function to serve arbitrary data.

serveFile
HttpResponseEx serveFile(string path, string fsBase, bool enableIndex, string urlBase)

Send a file from the disk

serveJson
HttpResponseEx serveJson(T v)

Utility function to serialize and serve an arbitrary D value as JSON. If jsonCallback is set, use JSONP instead.

serveText
HttpResponseEx serveText(string data)

Utility function to serve plain text.

setRefresh
void setRefresh(int seconds, string location)

Set a "Refresh" header requesting a refresh after the given interval, optionally redirecting to another location.

writeError
HttpResponseEx writeError(HttpStatusCode code, string details)

Serve a nice error page using this.errorTemplate, this.errorTokens, and writePageContents.

writePage
void writePage(string title, string[] html)

Serve this.pageTemplate as HTML, substituting "<?title?>" with title, "<?content?>" with one <p> tag per html item, and other tokens according to pageTokens.

writePageContents
void writePageContents(string title, string contentHTML)

Serve this.pageTemplate as HTML, substituting "<?title?>" with title, "<?content?>" with contentHTML, and other tokens according to pageTokens.

Static functions

getStatusExplanation
string getStatusExplanation(HttpStatusCode code)

Return a likely reason (in English) for why a specified status code was served.

loadTemplate
string loadTemplate(string filename, string[string] dictionary)

Load a template from the given file name, and fill it using the given dictionary.

parseTemplate
string parseTemplate(string data, string[string] dictionary)

Fill a template using the given dictionary, substituting "<?var?>" with dictionary["var"].

Static variables

contentTemplate
auto contentTemplate;

The default template for the page's contents, used for writePage.

errorTemplate
auto errorTemplate;

The default template for error messages, used for writeError.

pageTemplate
auto pageTemplate;

The default page template, used for writePage and error pages.

Variables

errorTokens
string[string] errorTokens;

Additional variables to use when filling out error templates.

jsonCallback
string jsonCallback;

If set, this is the name of the JSONP callback function to be used in serveJson.

pageTokens
string[string] pageTokens;

Additional variables to use when filling out page templates.

Inherited Members

From HttpResponse

status
HttpStatusCode status;

HTTP status code

statusMessage
string statusMessage;

HTTP status message, if one was supplied

compressionLevel
int compressionLevel;

What Zlib compression level to use when compressing the reply. Set to a negative value to disable compression.

getStatusMessage
string getStatusMessage(HttpStatusCode code)

Returns the message corresponding to the given HttpStatusCode, or null if the code is unknown.

setStatus
void setStatus(HttpStatusCode code)

Set the response status code and message

parseStatusLine
void parseStatusLine(string statusLine)

Initializes this HttpResponse with the given statusLine.

getContent
Data getContent()

If the data is compressed, return the decompressed data

compressWithDeflate
void compressWithDeflate()
Undocumented in source. Be warned that the author may not have intended to support it.
compressWithGzip
void compressWithGzip()
Undocumented in source. Be warned that the author may not have intended to support it.
optimizeData
void optimizeData(Headers requestHeaders)

Called by the server to compress content, if possible/appropriate

sliceData
void sliceData(Headers requestHeaders)

Called by the server to apply range request.

copyTo
void copyTo(typeof(this) other)
Undocumented in source. Be warned that the author may not have intended to support it.
copyTo
alias copyTo = typeof(super).copyTo
Undocumented in source.
dup
typeof(this) dup()
Undocumented in source. Be warned that the author may not have intended to support it.

Meta