dreamworkAPI
Ctrl K
GitHub
classDocs / http / Server / Response

http.Server.Response

classserversource
Object → http.Server.Response

The response writer for an http.Server route handler.

Backed by the same HolyLib HttpRequest as the paired Request (HolyLib 0.8 merged the response into it), or by an HttpResponse when used from :prepare.

Assign content, content_type, or status to build the reply, or use :send.

Constructor

http.Server.Response(exchange: http.Server.Exchange): http.Server.Response

Fields

NameTypeDescription
contentstring | nilThe response body, nil until assigned. Assigning calls SetContent with the current content_type.
content_typestringThe Content-Type, defaults to "text/plain".
statusinteger | nilThe response status code (100–599), nil until assigned.

Methods

finishShortcut for Request:finish of the paired request.
sendSets the status, body and optionally the content type in one call.
setHeaderSets a response header.
setRedirectSets a redirect response.

#Response:finish

serversource
function http.Server.Response:finish()

Shortcut for Request:finish of the paired request.

Does nothing for responses created by :prepare.

#Response:send

serversource
function http.Server.Response:send(status: integer, content: string, content_type?: http.ContentType): http.Server.Response

Sets the status, body and optionally the content type in one call.

Parameters
NameTypeDescription
statusintegerThe response status code.
contentstringThe response body.
content_typeoptionalhttp.ContentTypeThe Content-Type, defaults to the current content_type.
Returns
TypeNameDescription
http.Server.Responseself

#Response:setHeader

serversource
function http.Server.Response:setHeader(key: string, value: string): http.Server.Response

Sets a response header.

Parameters
NameTypeDescription
keystringThe header name.
valuestringThe header value.
Returns
TypeNameDescription
http.Server.Responseself

#Response:setRedirect

serversource
function http.Server.Response:setRedirect(url: string, code?: integer): http.Server.Response

Sets a redirect response.

Parameters
NameTypeDescription
urlstringThe redirect target URL.
codeoptionalintegerThe redirect status code. Defaults to 302.
Returns
TypeNameDescription
http.Server.Responseself
Generated from the dreamwork meta branch.