Fork me on GitHub

Module ringo/webapp/response

Functions

Class Response

Instance Methods

Instance Properties


Response.prototype.addHeader (key, value)

Add a header to be sent to the client. If a header with this name was previously set it will not be replaced.

Parameters

String key the header name
String value the header value

Returns

Response this response for chainability

Response.prototype.charset


Response.prototype.close ()

Close and convert this response into a JSGI response object.

Returns

a JSGI 0.2 response object

Response.prototype.contentType


Response.prototype.debug ()

Print a debug message to the rendered page.


Response.prototype.flushDebug ()

Write the debug buffer to the response's main buffer.


Response.prototype.getHeader (key)

Parameters

key

Response.prototype.redirect (location)

Parameters

location

Response.prototype.render (skin, context)

Render a skin to the response's buffer

Parameters

skin path to skin resource
context context object

Response.prototype.setCookie (key, value, days, options)

Sets a cookie to be sent to the client. All arguments except for key and value are optional. The days argument specifies the number of days until the cookie expires. To delete a cookie immediately, set the days argument to 0. If days is undefined or negative, the cookie is set for the current browser session.

Example

res.setCookie("username", "michi");
res.setCookie("password", "strenggeheim", 10,
              {path: "/mypath", domain: ".mydomain.org"});

Parameters

String key the cookie name
String value the cookie value
Number days optional the number of days to keep the cookie. If this is undefined or -1, the cookie is set for the current session. If this is 0, the cookie will be deleted immediately.
Object options optional options argument which may contain the following properties:
  • path - the path on which to set the cookie (defaults to /)
  • domain - the domain on which to set the cookie (defaults to current domain)
  • secure - to only use this cookie for secure connections
  • httpOnly - to make the cookie inaccessible to client side scripts

Returns

Response this response object for chainability;

Response.prototype.setHeader (key, value)

Set a header to be sent to the client. If a header with this name was previously set it will be replaced.

Parameters

String key the header name
String value the header value

Returns

Response this response for chainability

Response.prototype.status


Response.prototype.write ()


Response.prototype.writeln ()


errorResponse (msg)

Create a 500 error response.

Parameters

String msg the message of response body

jsonResponse (object)

Create a response object containing the JSON representation of an object.

Parameters

Object object the object whose JSON representation to return

notFoundResponse (location)

Create a 404 not-found response.

Parameters

String location the location that couldn't be found

redirectResponse (location)

Create a response that redirects the client to a different URL.

Parameters

String location the new location

skinResponse (skin, context)

A response object rendered from a skin.

Parameters

Resource|String skin the skin resource or path.
Object context the skin context object

staticResponse (resource, contentType)

A response representing a static resource.

Parameters

String|Resource resource the resource to serve
String contentType optional MIME type. If not defined, the MIME type is detected from the file name extension.

xmlResponse (xml)

Create a response containing the given XML document

Parameters

XML|String xml an XML document