wilton/DelayedResponse
Send HTTP response to client from another thread
More...
Functions | |
Object | DelayedResponse (Number responseWriterHandle, Function|Undefined callback) |
Create DelayedResponse instance. | |
Undefined | send (String|Object data, Object|Undefined options, Function|Undefined callback) |
Send string or JSON response to client. |
This module allows to send a "delayed" HTTP response to client. To create a DelayedResponse
instance, first responseWriterHandle
needs to be obtained inside the Server
request handler (view) using the req.sendResponseLater()
function.
DelayedResponse
may be created from any thread specifying the responseWriterHandle
as an argument.
Usage example:
Object DelayedResponse::DelayedResponse | ( | Number | responseWriterHandle, |
Function|Undefined | callback | ||
) |
Creates DelayedResponse
object instance that can be used to send HTTP response to client from the different thread.
responseWriterHandle | Number handle value, that must be obtained inside request handler (view) using req.sendResponseLater() call and (optionally) be passed to another thread after that |
callback | Function|Undefined callback to receive result or error |
Object
DelayedResponse
instance Undefined DelayedResponse::send | ( | String|Object | data, |
Object|Undefined | options, | ||
Function|Undefined | callback | ||
) |
Sends response to client converting specified object into JSON if necessary (Content-Type
is set to application/json
in this case).
data | String|Object response body, object will be converted to JSON |
options | Object|Undefined configuration object, see possible options below |
callback | Function|Undefined callback to receive result or error |
Undefined
Options
Object
response metadataNumber
HTTP status codeString
HTTP status messageObject
response headers in "Header-Name": "value"
format