JsonResponse

Response represents an HTTP response in JSON format.

Note that this class does not force the returned JSON content to be an object. It is however recommended that you do return an object as it protects yourself against XSSI and JSON-JavaScript Hijacking.

@see https://www.owasp.org/index.php/OWASP_AJAX_Security_Guidelines#Always_return_JSON_with_an_Object_on_the_outside

Constructors

this
this()
Undocumented in source.
this
this(T data)
Undocumented in source.

Members

Functions

setJson
JsonResponse setJson(JSONValue data)

Sets a raw string containing a JSON document to be sent.

Inherited Members

From Response

_response
HttpServerResponse _response;
Undocumented in source.
httpResponse
HttpServerResponse httpResponse()
Undocumented in source. Be warned that the author may not have intended to support it.
getFields
HttpFields getFields()
Undocumented in source. Be warned that the author may not have intended to support it.
header
Response header(string header, T value)
Undocumented in source. Be warned that the author may not have intended to support it.
header
Response header(HttpHeader header, T value)
Undocumented in source. Be warned that the author may not have intended to support it.
headers
Response headers(T[string] headers)
Undocumented in source. Be warned that the author may not have intended to support it.
setRestContent
Response setRestContent(T content)
Undocumented in source. Be warned that the author may not have intended to support it.
setContent
Response setContent(T content, string contentType)

Sets the response content.

setHtmlContent
Response setHtmlContent(string content)
Undocumented in source. Be warned that the author may not have intended to support it.
setStatus
Response setStatus(int status)

set http status code eg. 404 200

status
int status()
Undocumented in source. Be warned that the author may not have intended to support it.
setReason
Response setReason(string reason)
Undocumented in source. Be warned that the author may not have intended to support it.
download
Response download(string filename, ubyte[] file, string content_type)

download file

withCookie
Response withCookie(Cookie cookie)

Add a cookie to the response.

do404
void do404(string body_, string contentype)
Undocumented in source. Be warned that the author may not have intended to support it.
do403
void do403(string body_, string contentype)
Undocumented in source. Be warned that the author may not have intended to support it.
doError
void doError(ushort code, string body_, string contentype)
Undocumented in source. Be warned that the author may not have intended to support it.
doError
void doError(ushort code, Throwable exception, string contentype)
Undocumented in source. Be warned that the author may not have intended to support it.
setHttpError
void setHttpError(ushort code)
Undocumented in source. Be warned that the author may not have intended to support it.
setHeader
alias setHeader = header
Undocumented in source.
withHeaders
alias withHeaders = headers
Undocumented in source.
withContent
alias withContent = setContent
Undocumented in source.

Meta