该模块提供了用于组成 JSGI 响应对象的响应帮助函数。为了更加灵活,JsgiResponse 是可链接的。
一个 JSGI 响应对象的包装器。 JsgiResponse 是可链接的。
// Using the constructor
var {JsgiResponse} = require('ringo/jsgi/response');
return (new JsgiResponse()).text('Hello World!').setCharset('ISO-8859-1');
// Using a static helper
var response = require('ringo/jsgi/response');
return response.json({'foo': 'bar'}).error();
Object | base | a base object for the new JSGI response with the
initial |
将给定的对象合并到 JSGI 响应的头文件中。请注意,标题字段名称在 JsgiResponse 对象中区分大小写,但它们不在 Jetty 发送的最终 HTTP 响应消息中。
Object | headers | new header fields to merge with the current ones. |
JsgiResponse | JSGI response with the new headers |
将 HTTP 状态设置为 400。
JsgiResponse | a JSGI response object to send back |
用 Binary 对象创建一个 JSGI 响应作为响应主体。
ByteString|ByteArray | binary | the binary object to write |
String | contentType | optional MIME type. If not defined,
the MIME type is |
JsgiResponse | JSGI response |
将 HTTP 状态设置为 201。
JsgiResponse | a JSGI response object to send back |
将 HTTP 状态设置为 500。
JsgiResponse | a JSGI response object to send back |
将 HTTP 状态设置为 403。
JsgiResponse | a JSGI response object to send back |
将 HTTP 状态设置为 410。
JsgiResponse | a JSGI response object to send back |
将 JSGI 响应内容类型设置为“text / html”,并将字符串作为响应主体。
String... | html... | a variable number of strings to send as response body |
JsgiResponse | JSGI response with content-type 'text/html' |
用给定对象的 JSON 表示作为响应主体,创建一个带有内容类型 'application / json' 的 JSGI 响应。
Object | object | the object whose JSON representation to return |
JsgiResponse | JSGI response with content-type 'application/json' |
创建一个 JSGI 响应,其内容类型为 'application / javascript',给定对象的 JSONP 表示作为由回调名称包装的响应主体。
String | callback | the callback function name for a JSONP request |
Object | object | the object whose JSON representation to return |
JsgiResponse | JSGI response with content-type 'application/javascript' |
将 HTTP 状态设置为 404。
JsgiResponse | a JSGI response object to send back |
使用 HTTP 状态代码 304 创建一个响应,指示文档未被修改。
JsgiResponse | a JSGI response object to send back |
将 HTTP 状态设置为 200。
JsgiResponse | a JSGI response object to send back |
使用 HTTP 状态代码 303 创建一个响应,将客户端重定向到新的位置。
String | location | the new location |
JsgiResponse | a JSGI response object to send back |
设置用于文本响应的字符编码。
String | charsetName | the encoding to use. |
JsgiResponse | JSGI response with the given charset |
设置当前响应的内容类型。
String | contentType | the content type header value. |
JsgiResponse | JSGI response with the given charset |
将给定的对象合并到JSGI响应的头文件中。待发送头文件中的现有头文件将被替换为新头文件。请注意,标题字段名称在 JsgiResponse 对象中区分大小写,但它们不在 Jetty 发送的最终 HTTP 响应消息中。
Object | headers | new headers to be set |
JsgiResponse | JSGI response with the new headers |
设置 JSGI 响应状态。这不会提交请求并继续 JsgiReponse 链。
Number | code | the status code to use |
JsgiResponse | JSGI response with the new status code |
用流作为响应主体创建一个JSGI响应
Stream | stream | the stream to write |
String | contentType | optional MIME type. If not defined,
the MIME type is |
JsgiResponse | JSGI response |
将 JSGI 响应内容类型设置为“text / plain”,并将字符串作为响应主体。
String... | text... | a variable number of strings to send as response body |
JsgiResponse | JSGI response with content-type 'text/plain' |
将 HTTP 状态设置为 401。
JsgiResponse | a JSGI response object to send back |
将 HTTP 状态设置为 503。
JsgiResponse | a JSGI response object to send back |
使用给定的 XML 作为响应主体,创建一个带有内容类型“application / xml”的 JSGI 响应。
XML|String | xml | an XML document |
JsgiResponse | JSGI response with content-type 'application/xml' |
将给定的对象合并到 JSGI 响应的头文件中。
Object | headers | new header fields to merge with the current ones. |
JsgiResponse | JSGI response with the new headers |
将 JSGI 响应内容类型设置为“text / html”,并将字符串作为响应主体。
String... | html... | a variable number of strings to send as response body |
JsgiResponse | JSGI response with content-type 'text/html' |
用给定对象的JSON表示作为响应主体,创建一个带有内容类型'application / json'的JSGI响应。
Object | object | the object whose JSON representation to return |
JsgiResponse | JSGI response with content-type 'application/json' |
创建一个 JSGI 响应,其内容类型为'application / javascript',给定对象的 JSONP 表示作为由回调名称包装的响应主体。
String | callback | the callback function name for a JSONP request |
Object | object | the object whose JSON representation to return |
JsgiResponse | JSGI response with content-type 'application/javascript' |
使用 HTTP 状态代码 304 创建一个响应,指示文档未被修改。
JsgiResponse | a JSGI response object to send back |
表示资源为单个或多个部分响应的异步响应。多个或重叠的字节范围合并为一个规范的响应范围。
Object | request | a JSGI request object |
String|Resource|Stream | representation | path of a file as string, a resource, or a readable io.Stream |
Number | size | optional size of the resource in bytes, -1 indicates an unknown size. |
String | contentType | optional content type to send for single range responses |
Number | timeout | optional timeout to send back the ranges, defaults to 30 seconds, -1 indicates an infinite timeout. |
Number | maxRanges | optional maximum number of ranges in a request, defaults to 20. Similar to Apache's |
AsyncResponse | async response filled with the give ranges |
使用 HTTP 状态代码 303 创建一个响应,将客户端重定向到新的位置。
String | location | the new location |
JsgiResponse | a JSGI response object to send back |
设置用于文本响应的字符编码。
String | charsetName | the encoding to use. |
JsgiResponse | JSGI response with the given charset |
设置当前响应的内容类型。
String | contentType | the content type header value. |
JsgiResponse | JSGI response with the given charset |
将给定的对象合并到 JSGI 响应的头文件中。待发送头文件中的现有头文件将被替换为新头文件。
Object | headers | new headers to be set |
JsgiResponse | JSGI response with the new headers |
使用给定的状态码创建 JsgiResponse 的静态帮助器。
Number | code | the status code to use |
JsgiResponse | JSGI response with the new status code |
表示静态资源的响应。
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. |
将 JSGI 响应内容类型设置为“text / plain”,并将字符串作为响应主体。
String... | text... | a variable number of strings to send as response body |
JsgiResponse | JSGI response with content-type 'text/plain' |
使用给定的 XML 作为响应主体,创建一个带有内容类型“application / xml”的JSGI响应。
XML|String | xml | an XML document |
JsgiResponse | JSGI response with content-type 'application/xml' |