Module ringo/jsgi/response

This module provides response helper functions for composing JSGI response objects.

Functions


charset (charset)

Get or set the character encoding used for text responses.

If this function is called without argument, it returns the name of the currently used character encoding. If called with an argument, it sets the character encoding to the given charset.

Parameters

string charset the encoding to use.

Returns

string the current character encoding.

error (message)

Create a error response with HTTP status code 500.

Parameters

String message the message of response body

html (string...)

Create a JSGI response with content-type 'text/html' with the string or binary arguments as response body.

Parameters

string string... a variable number of strings to send as response body

Returns

a JSGI response object of type text/html

json (object)

Create a JSGI response with content-type 'application/json' with the JSON representation of the given object as response body.

Parameters

object object the object whose JSON representation to return

Returns

a JSGI response object of type application/json

notFound (location)

Create a not-found response with HTTP status code 404.

Parameters

String location the location that couldn't be found

redirect (location)

Create a response with HTTP status code 303 that redirects the client to a new location.

Parameters

String location the new location

static (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.

xml (xml)

Create a JSGI response with content-type 'application/xml' with the given XML document as response body.

Parameters

xml|string xml an XML document

Returns

a JSGI response object of type application/xml