# HG changeset patch # User Yaroslav Zhuravlev # Date 1614868492 0 # Node ID 9e39e64bff84a03f3e58325ecec6ffe6bf0d2d42 # Parent a33d8f0f48b233f115f507bb2fd9824b02514e40 Documented the js_body_filter directive. 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="24">
@@ -118,6 +118,70 @@ export default {foo, summary, baz, hello
+ +function | module.function +[buffer_type=string | buffer] + +location +limit_except +0.5.2 + + +Sets an njs function as a response body filter. +The filter function is called for each data chunk of a response body +with the following arguments: + + +data + +the incoming data chunk, +may be a string or Buffer +depending on the buffer_type value, +by default is a string. + + +flags + +an object with the following properties: + +last + +a boolean value, true if data is a last buffer. + + + + + + + + + +The filter function can pass its own modified version +of the input data chunk to the next body filter by calling +r.sendBuffer(). +For example, to transform all the lowercase letters in the response body: + +function filter(data, flags) { + r.sendBuffer(data.toLowerCase(), flags); +} + +To stop filtering (following data chunks will be passed to client +without calling js_body_filter), +r.done() +can be used. + + + +If the filter function changes the length of the response body, then +it is required to clear out the
Content-Length
response header +(if any) in +js_header_filter +to enforce chunked transfer encoding. +
+ +
+ + function | module.function 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="24">
@@ -118,6 +118,70 @@ export default {foo, summary, baz, hello
+ +функция | модуль.функция +[buffer_type=строка | буфер] + +location +limit_except +0.5.2 + + +Задаёт функцию njs в качестве фильтра тела ответа. +Функция фильтра вызывается для каждого блока данных тела ответа +со следующими аргументами: + + +data + +входящий блок данных +может быть строкой или буфером +в зависимости от значения buffer_type, +по умолчанию является строкой. + + +flags + +объект со следующими свойствами: + +last + +логическое значение, true, если данные являются последним буфером. + + + + + + + + + +Функция фильтра может передавать свою модифицированную версию +входящего блока данных следующему фильтру тела ответа при помощи вызова +r.sendBuffer(). +Пример преобразования букв в нижний регистр в теле ответа: + +function filter(data, flags) { + r.sendBuffer(data.toLowerCase(), flags); +} + +Для отмены фильтра (блоки данных будут передаваться клиенту +без вызова js_body_filter), +можно использовать +r.done(). + + + +Если функция фильтра изменяет длину тела ответа, то +необходимо очистить заголовок ответа
Content-Length
+(если присутствует) в +js_header_filter, +чтобы применить поблочное кодирование. +
+ +
+ + функция | модуль.функция