# HG changeset patch # User Yaroslav Zhuravlev # Date 1528212120 -10800 # Node ID cd4889fdcfa485a570bb590df3dcbc1b45939b69 # Parent 3b782a679237c072b1f7c6071cf96570b968840a Moved njs HTTP and Stream API to a separate page. diff --git a/xml/en/GNUmakefile b/xml/en/GNUmakefile --- a/xml/en/GNUmakefile +++ b/xml/en/GNUmakefile @@ -124,6 +124,7 @@ REFS = \ ngx_google_perftools_module \ dev/development_guide \ njs/njs_changes \ + njs/njs_api \ TOP = \ download \ diff --git a/xml/en/docs/http/ngx_http_js_module.xml b/xml/en/docs/http/ngx_http_js_module.xml --- a/xml/en/docs/http/ngx_http_js_module.xml +++ b/xml/en/docs/http/ngx_http_js_module.xml @@ -9,7 +9,7 @@ + rev="11">
@@ -160,181 +160,11 @@ Sets an njs function for the specified v
- -Each HTTP njs handler receives two arguments, request and response. - - - -The request object has the following properties: - - -uri - -current URI in a request, read-only - - -method - -request method, read-only - - -httpVersion - -HTTP version, read-only - - -remoteAddress - -client address, read-only - - -headers{} - -request headers object, read-only. - -For example, the Header-Name header -can be accessed with the syntax headers['Header-Name'] -or headers.Header_name - - - -args{} - -request arguments object, read-only - - -variables{} - -nginx variables object, read-only - - -response - -the response object (0.2.0), read-only - - - - - -The request object has the following methods: - - -log(string) - -writes a string to the error log -on the info level of logging - - -warn(string) - -writes a string to the error log -on the warning level of logging (0.2.0) - - -error(string) - -writes a string to the error log -on the error level of logging (0.2.0) - - -subrequest(uri[, options[, -callback]]) - -creates a subrequest with the given uri and -options, and installs -an optional completion callback (0.2.0). -If options is a string, then it -holds the subrequest arguments string. -Otherwise options is expected to be -an object with the following keys: - -args -arguments string - -body -request body - -method -HTTP method - - - - -The callback receives a response object -with the following properties: -uri, method, -status, contentType, -contentLength, headers, -args. -These properties have the same meaning as the request object properties. -Additionally, a reply object has the body property -holding the subrequest response body -and the parent property -referencing the parent request object. - - - - - - -The response object has the following properties: - - -status - -response status, writable - - -headers{} - -response headers object - - -contentType - -the response
Content-Type
header field value, writable -
- -contentLength - -the response
Content-Length
header field value, writable -
-
-
- - -The response object has the following methods: - - -sendHeader() - -sends the HTTP header to the client - - -send(string) - -sends a part of the response body to the client - - -finish() - -finishes sending a response to the client - - -return(status[, string]) - -sends -the entire response with the specified status to the client -(0.2.0) - -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. - - - +Each HTTP njs handler receives two arguments, +request +and response.
diff --git a/xml/en/docs/njs/njs_api.xml b/xml/en/docs/njs/njs_api.xml new file mode 100644 --- /dev/null +++ b/xml/en/docs/njs/njs_api.xml @@ -0,0 +1,354 @@ + + + + + + +
+ +
+ + +njs provides objects, methods and properties +for extending nginx functionality. + + +
+ + +
+ + +The HTTP objects are available only in the +ngx_http_js_module module. + + + +
+ + + + +req.uri + +current URI in a request, read-only + + +req.method + +request method, read-only + + +req.httpVersion + +HTTP version, read-only + + +req.remoteAddress + +client address, read-only + + +req.headers{} + +request headers object, read-only. + +For example, the Header-Name header +can be accessed with the syntax headers['Header-Name'] +or headers.Header_name + + + +req.args{} + +request arguments object, read-only + + +request.variables{} + +nginx variables object, read-only + + +req.response + +the response object (0.2.0), read-only + + +req.log(string) + +writes a string to the error log +on the info level of logging + + +req.warn(string) + +writes a string to the error log +on the warning level of logging (0.2.0) + + +req.error(string) + +writes a string to the error log +on the error level of logging (0.2.0) + + +req.subrequest(uri[, +options[, callback]]) + +creates a subrequest with the given uri and +options, and installs +an optional completion callback (0.2.0). + + +If options is a string, then it +holds the subrequest arguments string. +Otherwise, options is expected to be +an object with the following keys: + + +args + +arguments string + + +body + +request body + + +method + +HTTP method + + + + + +The completion callback +receives a reply object. + + + + + + +
+ + +
+ + + + +res.status + +response status, writable + + +res.headers{} + +response headers object + + +res.contentType + +the response
Content-Type
header field value, writable +
+ +res.contentLength + +the response
Content-Length
header field value, writable +
+ +res.sendHeader() + +sends the HTTP header to the client + + +res.send(string) + +sends a part of the response body to the client + + +res.finish() + +finishes sending a response to the client + + +res.return(status[, string]) + +sends +the entire response with the specified status to the client +(0.2.0) + +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 + + + +
+
+ +
+ + +
+ + + + +reply.uri + +current URI in a reply, read-only + + +reply.method + +reply method, read-only + + +reply.status + +reply status, writable + + +reply.contentType + +the response
Content-Type
header field value, writable +
+ +reply.contentLength + +the response
Content-Length
header field value, writable +
+ +reply.headers{} + +reply headers object, read-only + + +
+
+ + +Additionally, the reply object has +the following properties: + + + +reply.body + +holds the subrequest response body + + +reply.parent + +references the parent request object + + + + + +
+ +
+ + +
+ + +The stream objects are available only in the +ngx_stream_js_module +module. + + + +
+ + + + +s.remoteAddress + +client address, read-only + + +s.eof + +a boolean read-only property, true if the current buffer is the last buffer + + +s.fromUpstream + +a boolean read-only property, +true if the current buffer is from the upstream server to the client + + +s.buffer + +the current buffer, writable + + +s.variables{} + +nginx variables object, read-only + + +s.OK + +the OK return code + + +s.DECLINED + +the DECLINED return code + + +s.AGAIN + +the AGAIN return code + + +s.ERROR + +the ERROR return code + + +s.ABORT + +the ABORT return code + + +s.log(string) + +writes a sent string to the error log +on the info level of logging + + +s.warn(string) + +writes a sent string to the error log +on the warning level of logging (0.2.0) + + +s.error(string) + +writes a sent string to the error log +on the error level of logging (0.2.0) + + + + + +
+ +
+ + +
diff --git a/xml/en/docs/njs_about.xml b/xml/en/docs/njs_about.xml --- a/xml/en/docs/njs_about.xml +++ b/xml/en/docs/njs_about.xml @@ -9,7 +9,7 @@
+ rev="20">
@@ -252,6 +252,15 @@ The complete list of njs changes is avai
+
+ + +njs API reference is available +here. + +
+ +
diff --git a/xml/en/docs/stream/ngx_stream_js_module.xml b/xml/en/docs/stream/ngx_stream_js_module.xml --- a/xml/en/docs/stream/ngx_stream_js_module.xml +++ b/xml/en/docs/stream/ngx_stream_js_module.xml @@ -9,7 +9,7 @@ + rev="11">
@@ -230,79 +230,10 @@ Sets an njs function for the specified v
- -Each stream njs handler receives one argument, a stream session object. - -The session object has the following properties: - - - -remoteAddress - -client address, read-only - - -eof - -a boolean read-only property, true if the current buffer is the last buffer - - -fromUpstream - -a boolean read-only property, -true if the current buffer is from the upstream server to the client - - -buffer - -the current buffer, writable - - -variables{} - -nginx variables object, read-only - - -OK - -the OK return code - - -DECLINED - -the DECLINED return code - - -AGAIN - -the AGAIN return code - - -ERROR - -the ERROR return code - - -ABORT - -the ABORT return code - - - - - -The session object has the following methods: - - - -log(string) - -writes a sent string to the error log -on the info level of logging - - +Each stream njs handler receives one argument, a stream session +object.
diff --git a/xml/ru/GNUmakefile b/xml/ru/GNUmakefile --- a/xml/ru/GNUmakefile +++ b/xml/ru/GNUmakefile @@ -107,6 +107,7 @@ REFS = \ stream/ngx_stream_upstream_hc_module \ stream/stream_processing \ ngx_google_perftools_module \ + njs/njs_api \ TOP = \ download \ diff --git a/xml/ru/docs/http/ngx_http_js_module.xml b/xml/ru/docs/http/ngx_http_js_module.xml --- a/xml/ru/docs/http/ngx_http_js_module.xml +++ b/xml/ru/docs/http/ngx_http_js_module.xml @@ -9,7 +9,7 @@ + rev="11">
@@ -161,183 +161,11 @@ function baz(req, res) {
- -Каждый HTTP-обработчик njs получает два аргумента: запрос и ответ. - - - -Объект запроса имеет следующие свойства: - - -uri - -текущий URI запроса, только чтение - - -method - -метод запроса, только чтение - - -httpVersion - -версия HTTP, только чтение - - -remoteAddress - -адрес клиента, только чтение - - -headers{} - -объект заголовков запроса, только чтение. - -Например, доступ к заголовку Header-Name -можно получить при помощи синтаксиса headers['Header-Name'] -или headers.Header_name - - - -args{} - -объект аргументов запроса, только чтение - - -variables{} - -объект переменных nginx, только чтение - - -response - -объект ответа (0.2.0), только чтение - - - - - -Объект запроса имеет следующие свойства: - - -log(строка) - -записывает строку в лог-файл ошибок -на уровне лога info - - -warn(строка) - -записывает строку в лог-файл ошибок -на уровне лога warning (0.2.0) - - -error(строка) - -записывает строку в лог-файл ошибок -на уровне лога error (0.2.0) - - -subrequest(uri[, options[, -callback]]) - -создаёт подзапрос с заданными uri и -options и -устанавливает необязательный callback завершения (0.2.0). -Если options является строкой, то в ней -содержится срока аргументов подзапроса. -В противном случае ожидается, что options является объектом -со следующими ключами: - -args -строка с аргументами - -body -тело запроса - -method -метод HTTP - - - - -callback получает объект ответа -со следующими свойствами: -uri, method, -status, contentType, -contentLength, headers, -args. -Эти свойства имеют те же значения, что и свойства объекта запроса. -Дополнительно у объекта ответа есть свойство body, -содержащее тело ответа подзапроса, -и свойство parent, -ссылающееся на родительский объект запроса. - - - - - - -Объект ответа имеет следующие свойства: - - -status - -статус ответа, доступно для записи - - -headers{} - -объект заголовков ответа - - -contentType - -значение поля
Content-Type
заголовка ответа, -доступно для записи -
- -contentLength - -значение поля
Content-Length
заголовка ответа, -доступно для записи -
-
-
- - -Объект ответа имеет следующие методы: - - -sendHeader() - -отправляет заголовок HTTP клиенту - - -send(строка) - -отправляет часть тела ответа клиенту - - -finish() - -завершает отправку ответа клиенту - - -return(код[, строка]) - -отправляет -клиенту полный ответ с указанным кодом (0.2.0) - -Можно задать или URL перенаправления -(для кодов 301, 302, 303, 307 и 308), -или текст тела ответа (для остальных кодов) в качестве второго аргумента. - - - - +Каждый HTTP-обработчик njs получает два аргумента, +запрос +и ответ.
diff --git a/xml/ru/docs/njs/njs_api.xml b/xml/ru/docs/njs/njs_api.xml new file mode 100644 --- /dev/null +++ b/xml/ru/docs/njs/njs_api.xml @@ -0,0 +1,361 @@ + + + + + + +
+ +
+ + +njs предоставляет объекты, методы и свойства +для расширения функциональности nginx. + + +
+ + +
+ + +Объекты HTTP доступны только в +модуле ngx_http_js_module. + + + +
+ + + + +req.uri + +текущий URI запроса, только чтение + + +req.method + +метод запроса, только чтение + + +req.httpVersion + +версия HTTP, только чтение + + +req.remoteAddress + +адрес клиента, только чтение + + +req.headers{} + +объект заголовков запроса, только чтение. + +Например, доступ к заголовку Header-Name +можно получить при помощи синтаксиса headers['Header-Name'] +или headers.Header_name + + + +req.args{} + +объект аргументов запроса, только чтение + + +req.variables{} + +объект переменных nginx, только чтение + + +req.response + +объект ответа (0.2.0), только чтение + + +req.log(строка) + +записывает строку в лог-файл ошибок +на уровне лога info + + +req.warn(строка) + +записывает строку в лог-файл ошибок +на уровне лога warning (0.2.0) + + +req.error(строка) + +записывает строку в лог-файл ошибок +на уровне лога error (0.2.0) + + +req.subrequest(uri[, +options[, callback]]) + +создаёт подзапрос с заданными uri и +options и +устанавливает необязательный callback завершения (0.2.0). + + +Если options является строкой, то в ней +содержится срока аргументов подзапроса. +В противном случае ожидается, что options является объектом +со следующими ключами: + +args + +строка с аргументами + + +body + +тело запроса + + +method +метод HTTP + + + + + + +callback +получает объект reply. + + + + + + +
+ + +
+ + + + +res.status + +статус ответа, доступно для записи + + +res.headers{} + +объект заголовков ответа + + +res.contentType + +значение поля
Content-Type
заголовка ответа, +доступно для записи +
+ +res.contentLength + +значение поля
Content-Length
заголовка ответа, +доступно для записи +
+ +res.sendHeader() + +отправляет заголовок HTTP клиенту + + +res.send(строка) + +отправляет часть тела ответа клиенту + + +res.finish() + +завершает отправку ответа клиенту + + +res.return(код[, строка]) + +отправляет +клиенту полный ответ с указанным кодом (0.2.0) + +Можно задать или URL перенаправления +(для кодов 301, 302, 303, 307 и 308), +или текст тела ответа (для остальных кодов) в качестве второго аргумента + + + +
+
+ +
+ + +
+ + + + +reply.uri + +текущий URI, только чтение + + +reply.method + +метод, только чтение + + +reply.status + +статус, доступно для записи + + +reply.contentType + +значение поля
Content-Type
заголовка, +доступно для записи +
+ +reply.contentLength + +значение поля
Content-Length
заголовка, +доступно для записи +
+ +reply.headers{} + +объект заголовков ответа, только чтение + + +
+
+ + +Кроме того, у объект reply имеет +следующие свойства: + + + +reply.body + +хранит тело ответа подзапроса + + +reply.parent + +ссылается на родительский объект запроса + + + + + +
+ +
+ + +
+ + +Объекты stream доступны только в +модуле +ngx_stream_js_module. + + + +
+ + + + +s.remoteAddress + +адрес клиента, только чтение + + +s.eof + +логическое свойство, +true, если текущий буфер является последним буфером, +только чтение + + +s.fromUpstream + +логическое свойство, +true, если текущий буфер является буфером от проксируемого сервера к клиенту, +только чтение + + +s.buffer + +текущий буфер, доступен для записи + + +s.variables{} + +объект переменных nginx, только чтение + + +s.OK + +код OK + + +s.DECLINED + +код DECLINED + + +s.AGAIN + +код AGAIN + + +s.ERROR + +код ERROR + + +s.ABORT + +код ABORT + + +s.log(строка) + +записывает отправленную строку в лог-файл ошибок +на уровне лога info + + +s.warn(строка) + +записывает отправленную строку в лог-файл ошибок +на уровне лога warning (0.2.0) + + +s.error(строка) + +записывает отправленную строку в лог-файл ошибок +на уровне лога error (0.2.0) + + + + + +
+ +
+ + +
+ diff --git a/xml/ru/docs/njs_about.xml b/xml/ru/docs/njs_about.xml --- a/xml/ru/docs/njs_about.xml +++ b/xml/ru/docs/njs_about.xml @@ -9,7 +9,7 @@
+ rev="20">
@@ -250,6 +250,14 @@ labels
+
+ + +Справочник njs API доступен +здесь. + +
+
diff --git a/xml/ru/docs/stream/ngx_stream_js_module.xml b/xml/ru/docs/stream/ngx_stream_js_module.xml --- a/xml/ru/docs/stream/ngx_stream_js_module.xml +++ b/xml/ru/docs/stream/ngx_stream_js_module.xml @@ -9,7 +9,7 @@ + rev="11">
@@ -231,83 +231,10 @@ function xyz(s) {
- -Каждый stream-обработчик njs получает один аргумент: -объект stream-сессии. - -Объект сессии имеет следующие свойства: - - - -remoteAddress - -адрес клиента, только чтение - - -eof - -логическое свойство, -true, если текущий буфер является последним буфером, -только чтение - - -fromUpstream - -логическое свойство, -true, если текущий буфер является буфером от проксируемого сервера к клиенту, -только чтение - - -buffer - -текущий буфер, доступен для записи - - -variables{} - -объект переменных nginx, только чтение - - -OK - -код OK - - -DECLINED - -код DECLINED - - -AGAIN - -код AGAIN - - -ERROR - -код ERROR - - -ABORT - -код ABORT - - - - - -Объект сессии имеет следующие методы: - - - -log(строка) - -записывает отправленную строку в лог-файл ошибок -на уровне лога info - - +Каждый stream-обработчик njs получает один аргумент, +объект stream-сессии.