Mercurial > hg > nginx-site
comparison xml/en/docs/http/ngx_http_js_module.xml @ 2664:9e39e64bff84
Documented the js_body_filter directive.
author | Yaroslav Zhuravlev <yar@nginx.com> |
---|---|
date | Thu, 04 Mar 2021 14:34:52 +0000 |
parents | b4991bbd64ee |
children | 893cd7724c8c |
comparison
equal
deleted
inserted
replaced
2663:a33d8f0f48b2 | 2664:9e39e64bff84 |
---|---|
7 <!DOCTYPE module SYSTEM "../../../../dtd/module.dtd"> | 7 <!DOCTYPE module SYSTEM "../../../../dtd/module.dtd"> |
8 | 8 |
9 <module name="Module ngx_http_js_module" | 9 <module name="Module ngx_http_js_module" |
10 link="/en/docs/http/ngx_http_js_module.html" | 10 link="/en/docs/http/ngx_http_js_module.html" |
11 lang="en" | 11 lang="en" |
12 rev="23"> | 12 rev="24"> |
13 | 13 |
14 <section id="summary"> | 14 <section id="summary"> |
15 | 15 |
16 <para> | 16 <para> |
17 The <literal>ngx_http_js_module</literal> module is used to implement | 17 The <literal>ngx_http_js_module</literal> module is used to implement |
116 </section> | 116 </section> |
117 | 117 |
118 | 118 |
119 <section id="directives" name="Directives"> | 119 <section id="directives" name="Directives"> |
120 | 120 |
121 <directive name="js_body_filter"> | |
122 <syntax><value>function</value> | <value>module.function</value> | |
123 [<value>buffer_type</value>=<value>string</value> | <value>buffer</value>]</syntax> | |
124 <default/> | |
125 <context>location</context> | |
126 <context>limit_except</context> | |
127 <appeared-in>0.5.2</appeared-in> | |
128 | |
129 <para> | |
130 Sets an njs function as a response body filter. | |
131 The filter function is called for each data chunk of a response body | |
132 with the following arguments: | |
133 | |
134 <list type="tag"> | |
135 <tag-name><literal>data</literal></tag-name> | |
136 <tag-desc> | |
137 the incoming data chunk, | |
138 may be a string or Buffer | |
139 depending on the <literal>buffer_type</literal> value, | |
140 by default is a string. | |
141 </tag-desc> | |
142 | |
143 <tag-name><literal>flags</literal></tag-name> | |
144 <tag-desc> | |
145 an object with the following properties: | |
146 <list type="tag"> | |
147 <tag-name><literal>last</literal></tag-name> | |
148 <tag-desc> | |
149 a boolean value, true if data is a last buffer. | |
150 </tag-desc> | |
151 | |
152 </list> | |
153 </tag-desc> | |
154 | |
155 </list> | |
156 </para> | |
157 | |
158 <para> | |
159 The filter function can pass its own modified version | |
160 of the input data chunk to the next body filter by calling | |
161 <link doc="../njs/reference.xml" id="r_sendbuffer"><literal>r.sendBuffer()</literal></link>. | |
162 For example, to transform all the lowercase letters in the response body: | |
163 <example> | |
164 function filter(data, flags) { | |
165 r.sendBuffer(data.toLowerCase(), flags); | |
166 } | |
167 </example> | |
168 To stop filtering (following data chunks will be passed to client | |
169 without calling <literal>js_body_filter</literal>), | |
170 <link doc="../njs/reference.xml" id="r_done"><literal>r.done()</literal></link> | |
171 can be used. | |
172 </para> | |
173 | |
174 <para> | |
175 If the filter function changes the length of the response body, then | |
176 it is required to clear out the <header>Content-Length</header> response header | |
177 (if any) in | |
178 <link id="js_header_filter"><literal>js_header_filter</literal></link> | |
179 to enforce chunked transfer encoding. | |
180 </para> | |
181 | |
182 </directive> | |
183 | |
184 | |
121 <directive name="js_content"> | 185 <directive name="js_content"> |
122 <syntax><value>function</value> | <value>module.function</value></syntax> | 186 <syntax><value>function</value> | <value>module.function</value></syntax> |
123 <default/> | 187 <default/> |
124 <context>location</context> | 188 <context>location</context> |
125 <context>limit_except</context> | 189 <context>limit_except</context> |