Mercurial > hg > nginx-site
changeset 2149:6df1a86a60b8
Added new njs HTTP properties and methods.
author | Roman Arutyunyan <arut@nginx.com> |
---|---|
date | Fri, 06 Apr 2018 20:34:26 +0300 |
parents | 94a598ee1d49 |
children | af5751930f95 |
files | xml/en/docs/http/ngx_http_js_module.xml xml/ru/docs/http/ngx_http_js_module.xml |
diffstat | 2 files changed, 150 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/xml/en/docs/http/ngx_http_js_module.xml +++ b/xml/en/docs/http/ngx_http_js_module.xml @@ -9,7 +9,7 @@ <module name="Module ngx_http_js_module" link="/en/docs/http/ngx_http_js_module.html" lang="en" - rev="9"> + rev="10"> <section id="summary"> @@ -208,11 +208,73 @@ request arguments object, read-only nginx variables object, read-only </tag-desc> +<tag-name><literal>response</literal></tag-name> +<tag-desc> +the response object (0.2.0), read-only +</tag-desc> +</list> +</para> + +<para> +The request object has the following methods: +<list type="tag"> + <tag-name><literal>log(<value>string</value>)</literal></tag-name> <tag-desc> writes a <literal>string</literal> to the error log on the <literal>info</literal> level of logging </tag-desc> + +<tag-name><literal>warn(<value>string</value>)</literal></tag-name> +<tag-desc> +writes a <literal>string</literal> to the error log +on the <literal>warning</literal> level of logging (0.2.0) +</tag-desc> + +<tag-name><literal>error(<value>string</value>)</literal></tag-name> +<tag-desc> +writes a <literal>string</literal> to the error log +on the <literal>error</literal> level of logging (0.2.0) +</tag-desc> + +<tag-name><literal>subrequest(<value>uri</value>[, <value>options</value>[, +<value>callback</value>]])</literal></tag-name> +<tag-desc> +creates a subrequest with the given <literal>uri</literal> and +<literal>options</literal>, and installs +an optional completion <literal>callback</literal> (0.2.0). + +<para> +If <literal>options</literal> is a string, then it +holds the subrequest arguments string. +Otherwise <literal>options</literal> is expected to be +an object with the following keys: +<list type="tag"> +<tag-name><literal>args</literal></tag-name> +<tag-desc>arguments string</tag-desc> + +<tag-name><literal>body</literal></tag-name> +<tag-desc>request body</tag-desc> + +<tag-name><literal>method</literal></tag-name> +<tag-desc>HTTP method</tag-desc> +</list> +</para> + +<para> +The <literal>callback</literal> receives a response object +with the following properties: +<literal>uri</literal>, <literal>method</literal>, +<literal>status</literal>, <literal>contentType</literal>, +<literal>contentLength</literal>, <literal>headers</literal>, +<literal>args</literal>. +These properties have the same meaning as the request object properties. +Additionally, a reply object has the <literal>body</literal> property +holding the subrequest response body +and the <literal>parent</literal> property +referencing the parent request object. +</para> +</tag-desc> </list> </para> @@ -260,6 +322,18 @@ sends a part of the response body to the <tag-desc> finishes sending a response to the client </tag-desc> + +<tag-name><literal>return(status[, string])</literal></tag-name> +<tag-desc> +sends +the entire response with the specified <literal>status</literal> to the client +(0.2.0) +<para> +It is possible to specify either a redirect URL +(for codes 301, 302, 303, 307, and 308) +or the response body text (for other codes) as the second argument. +</para> +</tag-desc> </list> </para>
--- a/xml/ru/docs/http/ngx_http_js_module.xml +++ b/xml/ru/docs/http/ngx_http_js_module.xml @@ -9,7 +9,7 @@ <module name="Модуль ngx_http_js_module" link="/ru/docs/http/ngx_http_js_module.html" lang="ru" - rev="9"> + rev="10"> <section id="summary"> @@ -209,11 +209,73 @@ function baz(req, res) { объект переменных nginx, только чтение </tag-desc> +<tag-name><literal>response</literal></tag-name> +<tag-desc> +объект ответа (0.2.0), только чтение +</tag-desc> +</list> +</para> + +<para> +Объект запроса имеет следующие свойства: +<list type="tag"> + <tag-name><literal>log(<value>строка</value>)</literal></tag-name> <tag-desc> записывает <literal>строку</literal> в лог-файл ошибок на уровне лога <literal>info</literal> </tag-desc> + +<tag-name><literal>warn(<value>строка</value>)</literal></tag-name> +<tag-desc> +записывает <literal>строку</literal> в лог-файл ошибок +на уровне лога <literal>warning</literal> (0.2.0) +</tag-desc> + +<tag-name><literal>error(<value>строка</value>)</literal></tag-name> +<tag-desc> +записывает <literal>строку</literal> в лог-файл ошибок +на уровне лога <literal>error</literal> (0.2.0) +</tag-desc> + +<tag-name><literal>subrequest(<value>uri</value>[, <value>options</value>[, +<value>callback</value>]])</literal></tag-name> +<tag-desc> +создаёт подзапрос с заданными <literal>uri</literal> и +<literal>options</literal> и +устанавливает необязательный <literal>callback</literal> завершения (0.2.0). + +<para> +Если <literal>options</literal> является строкой, то в ней +содержится срока аргументов подзапроса. +В противном случае ожидается, что <literal>options</literal> является объектом +со следующими ключами: +<list type="tag"> +<tag-name><literal>args</literal></tag-name> +<tag-desc>строка с аргументами</tag-desc> + +<tag-name><literal>body</literal></tag-name> +<tag-desc>тело запроса</tag-desc> + +<tag-name><literal>method</literal></tag-name> +<tag-desc>метод HTTP</tag-desc> +</list> +</para> + +<para> +<literal>callback</literal> получает объект ответа +со следующими свойствами: +<literal>uri</literal>, <literal>method</literal>, +<literal>status</literal>, <literal>contentType</literal>, +<literal>contentLength</literal>, <literal>headers</literal>, +<literal>args</literal>. +Эти свойства имеют те же значения, что и свойства объекта запроса. +Дополнительно у объекта ответа есть свойство <literal>body</literal>, +содержащее тело ответа подзапроса, +и свойство <literal>parent</literal>, +ссылающееся на родительский объект запроса. +</para> +</tag-desc> </list> </para> @@ -263,6 +325,18 @@ function baz(req, res) { <tag-desc> завершает отправку ответа клиенту </tag-desc> + +<tag-name><literal>return(код[, строка])</literal></tag-name> +<tag-desc> +отправляет +клиенту полный ответ с указанным <literal>кодом</literal> (0.2.0) +<para> +Можно задать или URL перенаправления +(для кодов 301, 302, 303, 307 и 308), +или текст тела ответа (для остальных кодов) в качестве второго аргумента. +</para> +</tag-desc> + </list> </para>