Class: Response

Response

Wrapper for the ExpressJS response, exposing only the necessary minimum.


new Response()

Initializes the response.

Members


_content :string

The content of response.

Type:
  • string

_cookieTransformFunction :Object

Transform function for cookie value.

Type:
  • Object

_internalCookieStorage :Map.<string, {value: string, options: {domain: string=, expires: (number|string)=}}>

Internal cookie storage for Set-Cookie header.

Type:
  • Map.<string, {value: string, options: {domain: string=, expires: (number|string)=}}>

_isSent :boolean

It is flag for sent response for request.

Type:
  • boolean

_pageState :Object.<string, *>

The rendered page state.

Type:
  • Object.<string, *>

<nullable> _response :Express.Response

The ExpressJS response object, or null if running at the client side.

Type:
  • Express.Response

_status :number

HTTP Status code.

Type:
  • number

Methods


_prepareCookieOptionsForExpress(options)

Prepares cookie options for Express.

Parameters:
Name Type Description
options Object

Cookie attributes. Only the attributes listed in the type annotation of this field are supported. For documentation and full list of cookie attributes see http://tools.ietf.org/html/rfc2965#page-5

Returns:

Cookie options prepared for Express.

Type
Object

_setCookieHeaders()

Set cookie headers for response.


getResponseParams()

Return object which contains response status, content and rendered page state.

Returns:
Type
Object

init(response [, cookieTransformFunction])

Initializes this response wrapper with the provided ExpressJS response object.

Parameters:
Name Type Argument Description
response Express.Response <nullable>

The ExpressJS response, or null if the code is running at the client side.

cookieTransformFunction Object <optional>
Returns:

This response.

Type
ima.router.Response

isResponseSent()

Return true if response is sent from server to client.

Returns:
Type
boolean

redirect(url [, status])

Redirects the client to the specified location, with the specified redirect HTTP response code.

For full list of HTTP response status codes see http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html

Use this method only at the server side.

Parameters:
Name Type Argument Default Description
url string

The URL to which the client should be redirected.

status number <optional>
302

The HTTP status code to send to the client.

Returns:

This response.

Type
Response

send(content)

Sends the response to the client with the provided content. Use this method only at the server side.

Parameters:
Name Type Description
content string

The response body.

Returns:

This response.

Type
Response

setCookie(name, value, options)

Sets a cookie, which will be sent to the client with the response.

Parameters:
Name Type Description
name string

The cookie name.

value boolean | number | string

The cookie value, will be converted to string.

options Object

Cookie attributes. Only the attributes listed in the type annotation of this field are supported. For documentation and full list of cookie attributes see http://tools.ietf.org/html/rfc2965#page-5

Returns:

This response.

Type
Response

setPageState(pageState)

Sets the rendered page state.

Parameters:
Name Type Description
pageState Object.<string, *>

The rendered page state.

Returns:

This response.

Type
Response

status(httpStatus)

Sets the HTTP status code that will be sent to the client when the response is sent.

For full list of available response codes see http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html

Use this method only at the server side.

Parameters:
Name Type Description
httpStatus number

HTTP response status code to send to the client.

Returns:

This response.

Type
Response