http.Server.Response
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.ResponseFields
| Name | Type | Description |
|---|---|---|
content | string | nil | The response body, nil until assigned. Assigning calls SetContent with the current content_type. |
content_type | string | The Content-Type, defaults to "text/plain". |
status | integer | nil | The response status code (100–599), nil until assigned. |
Methods
finish | Shortcut for Request:finish of the paired request. |
send | Sets the status, body and optionally the content type in one call. |
setHeader | Sets a response header. |
setRedirect | Sets a redirect response. |
#Response:finish
function http.Server.Response:finish()
Shortcut for Request:finish of the paired request.
Does nothing for responses created by :prepare.
#Response:send
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
| Name | Type | Description |
|---|---|---|
status | integer | The response status code. |
content | string | The response body. |
content_typeoptional | http.ContentType | The Content-Type, defaults to the current content_type. |
Returns
| Type | Name | Description |
|---|---|---|
http.Server.Response | self |
#Response:setHeader
function http.Server.Response:setHeader(key: string, value: string): http.Server.Response
Sets a response header.
Parameters
| Name | Type | Description |
|---|---|---|
key | string | The header name. |
value | string | The header value. |
Returns
| Type | Name | Description |
|---|---|---|
http.Server.Response | self |
#Response:setRedirect
function http.Server.Response:setRedirect(url: string, code?: integer): http.Server.Response
Sets a redirect response.
Parameters
| Name | Type | Description |
|---|---|---|
url | string | The redirect target URL. |
codeoptional | integer | The redirect status code. Defaults to 302. |
Returns
| Type | Name | Description |
|---|---|---|
http.Server.Response | self |