diff --git a/xml/en/docs/http/ngx_http_js_module.xml b/xml/en/docs/http/ngx_http_js_module.xml index 6bc6595fd..17638915d 100644 --- 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="59">
@@ -267,6 +267,68 @@ since 0.7.7. + +module.function + +location +if in location +limit_except +0.9.9 + + +Sets an njs function as a handler in the +access phase. +Asynchronous operations such as +r.subrequest(), +ngx.fetch(), +and setTimeout() +are supported. + + + +A handler that returns without calling +r.return() +or +r.decline() +grants access. +To deny access or send a custom response (for example, a redirect), +the handler may call +r.return(). +To make the handler express no opinion, deferring the decision to other +access checkers under +satisfy any, +the handler may call +r.decline(). + + + +For example: + +example.conf: + location /protected/ { + js_access main.auth; + proxy_pass http://upstream; + } + +example.js: + async function auth(r) { + let reply = await ngx.fetch('http://authsvc/check', { + headers: {Authorization: r.headersIn.Authorization} + }); + + if (reply.status != 200) { + r.return(401); + return; + } + } + + export default {auth}; + + + + + + module.function diff --git a/xml/en/docs/njs/compatibility.xml b/xml/en/docs/njs/compatibility.xml index c55b7763b..040d7ea86 100644 --- a/xml/en/docs/njs/compatibility.xml +++ b/xml/en/docs/njs/compatibility.xml @@ -9,7 +9,7 @@
@@ -1178,6 +1178,14 @@ nginx object properties: r.internal, r.method, r.parent, +r.readRequestArrayBuffer +(0.9.9), +r.readRequestForm +(0.9.9), +r.readRequestJSON +(0.9.9), +r.readRequestText +(0.9.9), r.rawHeadersIn (0.4.1), r.rawHeadersOut diff --git a/xml/en/docs/njs/reference.xml b/xml/en/docs/njs/reference.xml index da9d0110b..4ecb50426 100644 --- a/xml/en/docs/njs/reference.xml +++ b/xml/en/docs/njs/reference.xml @@ -9,7 +9,7 @@
+ rev="135">
@@ -40,6 +40,7 @@ List of all njs properties and methods can be found in + @@ -51,6 +52,10 @@ List of all njs properties and methods can be found in + + + + @@ -135,6 +140,23 @@ method can be used. +r.decline() + +makes the + handler +express no opinion about access, deferring the decision to other access +checkers under +satisfy any +(0.9.9). +A handler that returns without calling +r.decline() +or +r.return() +implicitly grants access. +May be called only from the + function. + + r.done() after calling this function, @@ -374,6 +396,137 @@ references the parent request object client address, read-only +r.readRequestArrayBuffer() + +returns a Promise that resolves with the client +request body as an ArrayBuffer +(0.9.9). +See +r.readRequestText() +for availability, body caching, and concurrency semantics. + + +r.readRequestForm([options]) + +reads the client request body and parses it as an HTML form, +returning a Promise that resolves with a form object +(0.9.9). +Supported content types are +application/x-www-form-urlencoded +and multipart/form-data. + + +The form object provides the following methods: + + +get(name) + +returns the first value for name, +or null if absent. + + +getAll(name) + +returns an array with all values for name. + + +has(name) + +returns true if at least one entry exists +for name. + + +forEach(callback[, +thisArg]) + +invokes callback for each entry with arguments +(value, key, form). + + +hasFiles() + +returns true if the form contains any file parts. + + + + + + +For text fields, values are decoded strings. +For file parts, the value is an object with the client-supplied +filename available as the name property; +file contents are not exposed. +The filename is client-supplied and is not sanitized. + + + +The optional options object accepts the following +properties: + + +maxKeys +number + +the maximum number of fields to parse, +by default is 128. +Exceeding the limit rejects the returned promise. + + + + + + +See +r.readRequestText() +for availability, body caching, and concurrency semantics. +The parsed form is itself cached on the request: +a subsequent call returns the same form object and ignores any +new options argument. + + + +r.readRequestJSON() + +returns a Promise that resolves with the client +request body parsed as JSON +(0.9.9). +See +r.readRequestText() +for availability, body caching, and concurrency semantics. + + +r.readRequestText() + +returns a Promise that resolves with the client +request body as a string +(0.9.9). +The size of the request body is limited by +. +The method is available in the + +and + directives. + + +The body is read once and cached on the request: +subsequent calls to +r.readRequestText(), +r.readRequestArrayBuffer(), +r.readRequestJSON(), +or +r.readRequestForm() +resolve from the cached body without re-reading the wire. +A second call issued while a previous read is still pending throws +"request body is already being read". + + + +Note that +it may convert bytes invalid in UTF-8 encoding into the replacement +character. + + + r.requestBody the property was made obsolete in @@ -395,6 +548,10 @@ and a sufficient buffer size should be set using . The property is available only in the directive. +For asynchronous access, or for use in +, see +r.readRequestText() +and other “r.readRequest*()” methods. r.requestText @@ -403,6 +560,9 @@ the same as r.requestBufferstring. Note that it may convert bytes invalid in UTF-8 encoding into the replacement character. +For asynchronous access, or for use in +, see +r.readRequestText(). r.rawHeadersIn[] @@ -486,6 +646,12 @@ with the specified status to the client. The response can be a string or Buffer (0.5.0). +May be called from the + +or, since 0.9.9, + handler. + + 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 diff --git a/xml/ru/docs/http/ngx_http_js_module.xml b/xml/ru/docs/http/ngx_http_js_module.xml index 1153d2452..b5afb1682 100644 --- 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="57">
@@ -148,7 +148,7 @@ export default {foo, summary, baz, hello, fetch, hash};
-функция | модуль.функция +модуль.функция [buffer_type=string | buffer] location @@ -243,8 +243,69 @@ function filter(r, data, flags) { + +модуль.функция + +location +if in location +limit_except +0.9.9 + + +Задаёт функцию njs в качестве обработчика +фазы доступа. +Поддерживаются асинхронные операции, такие как +r.subrequest(), +ngx.fetch() +и setTimeout(). + + + +Обработчик, завершившийся без вызова +r.return() +или +r.decline(), +разрешает доступ. +Чтобы запретить доступ или отправить произвольный ответ +(например, перенаправление), обработчик может вызвать +r.return(). +Чтобы обработчик не выражал мнения о доступе, передавая решение другим +проверкам доступа при использовании +satisfy any, +обработчик может вызвать +r.decline(). + + + +Например: + +example.conf: + location /protected/ { + js_access main.auth; + proxy_pass http://upstream; + } + +example.js: + async function auth(r) { + let reply = await ngx.fetch('http://authsvc/check', { + headers: {Authorization: r.headersIn.Authorization} + }); + + if (reply.status != 200) { + r.return(401); + return; + } + } + + export default {auth}; + + + + + + -функция | модуль.функция +модуль.функция location if in location @@ -580,7 +641,7 @@ location /fetch { -функция | модуль.функция +модуль.функция location if in location @@ -771,8 +832,7 @@ let result = mylib.add(5, 10); -функция | - модуль.функция +модуль.функция [interval=время] [jitter=число] [worker_affinity=маска] @@ -879,7 +939,7 @@ js_preload_object map.json; $переменная - функция | модуль.функция + модуль.функция [nocache] http diff --git a/xml/ru/docs/njs/compatibility.xml b/xml/ru/docs/njs/compatibility.xml index c30d553d9..05f0264ee 100644 --- a/xml/ru/docs/njs/compatibility.xml +++ b/xml/ru/docs/njs/compatibility.xml @@ -9,7 +9,7 @@
@@ -1178,6 +1178,14 @@ ES6 поддержка стрелочных функций r.internal, r.method, r.parent, +r.readRequestArrayBuffer +(0.9.9), +r.readRequestForm +(0.9.9), +r.readRequestJSON +(0.9.9), +r.readRequestText +(0.9.9), r.rawHeadersIn (0.4.1), r.rawHeadersOut diff --git a/xml/ru/docs/stream/ngx_stream_js_module.xml b/xml/ru/docs/stream/ngx_stream_js_module.xml index 1dae0ad10..aa3f5414d 100644 --- 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="53">
@@ -130,7 +130,7 @@ export default {bar, preread, req_line, header_inject, access};
-функция | модуль.функция +модуль.функция stream server @@ -475,7 +475,7 @@ server { -функция | модуль.функция +модуль.функция stream server @@ -630,7 +630,7 @@ js_preload_object map.json; -функция | модуль.функция +модуль.функция stream server @@ -776,8 +776,7 @@ let result = mylib.add(5, 10); -функция | - модуль.функция +модуль.функция [interval=время] [jitter=число] [worker_affinity=маска] @@ -853,7 +852,7 @@ async function handler(s) { $переменная - функция | модуль.функция + модуль.функция [nocache] stream
r.args{}
r.decline()
r.done()
r.error()
r.finish()
r.log()
r.method
r.parent
r.readRequestArrayBuffer()
r.readRequestForm()
r.readRequestJSON()
r.readRequestText()
r.remoteAddress
r.requestBody
r.requestBuffer