comparison xml/en/docs/http/ngx_http_js_module.xml @ 2175:cd4889fdcfa4

Moved njs HTTP and Stream API to a separate page.
author Yaroslav Zhuravlev <yar@nginx.com>
date Tue, 05 Jun 2018 18:22:00 +0300
parents 6df1a86a60b8
children ed905ab118c7
comparison
equal deleted inserted replaced
2174:3b782a679237 2175:cd4889fdcfa4
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="10"> 12 rev="11">
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
158 158
159 </section> 159 </section>
160 160
161 161
162 <section id="arguments" name="Request and Response Arguments"> 162 <section id="arguments" name="Request and Response Arguments">
163 <para>
164 Each HTTP njs handler receives two arguments, request and response.
165 </para>
166 163
167 <para> 164 <para>
168 The request object has the following properties: 165 Each HTTP njs handler receives two arguments,
169 <list type="tag"> 166 <link doc="../njs/njs_api.xml" id="http_request">request</link>
170 167 and <link doc="../njs/njs_api.xml" id="http_response">response</link>.
171 <tag-name><literal>uri</literal></tag-name>
172 <tag-desc>
173 current URI in a request, read-only
174 </tag-desc>
175
176 <tag-name><literal>method</literal></tag-name>
177 <tag-desc>
178 request method, read-only
179 </tag-desc>
180
181 <tag-name><literal>httpVersion</literal></tag-name>
182 <tag-desc>
183 HTTP version, read-only
184 </tag-desc>
185
186 <tag-name><literal>remoteAddress</literal></tag-name>
187 <tag-desc>
188 client address, read-only
189 </tag-desc>
190
191 <tag-name><literal>headers{}</literal></tag-name>
192 <tag-desc>
193 request headers object, read-only.
194 <para>
195 For example, the <literal>Header-Name</literal> header
196 can be accessed with the syntax <literal>headers['Header-Name']</literal>
197 or <literal>headers.Header_name</literal>
198 </para>
199 </tag-desc>
200
201 <tag-name><literal>args{}</literal></tag-name>
202 <tag-desc>
203 request arguments object, read-only
204 </tag-desc>
205
206 <tag-name><literal>variables{}</literal></tag-name>
207 <tag-desc>
208 nginx variables object, read-only
209 </tag-desc>
210
211 <tag-name><literal>response</literal></tag-name>
212 <tag-desc>
213 the response object (0.2.0), read-only
214 </tag-desc>
215 </list>
216 </para>
217
218 <para>
219 The request object has the following methods:
220 <list type="tag">
221
222 <tag-name><literal>log(<value>string</value>)</literal></tag-name>
223 <tag-desc>
224 writes a <literal>string</literal> to the error log
225 on the <literal>info</literal> level of logging
226 </tag-desc>
227
228 <tag-name><literal>warn(<value>string</value>)</literal></tag-name>
229 <tag-desc>
230 writes a <literal>string</literal> to the error log
231 on the <literal>warning</literal> level of logging (0.2.0)
232 </tag-desc>
233
234 <tag-name><literal>error(<value>string</value>)</literal></tag-name>
235 <tag-desc>
236 writes a <literal>string</literal> to the error log
237 on the <literal>error</literal> level of logging (0.2.0)
238 </tag-desc>
239
240 <tag-name><literal>subrequest(<value>uri</value>[, <value>options</value>[,
241 <value>callback</value>]])</literal></tag-name>
242 <tag-desc>
243 creates a subrequest with the given <literal>uri</literal> and
244 <literal>options</literal>, and installs
245 an optional completion <literal>callback</literal> (0.2.0).
246
247 <para>
248 If <literal>options</literal> is a string, then it
249 holds the subrequest arguments string.
250 Otherwise <literal>options</literal> is expected to be
251 an object with the following keys:
252 <list type="tag">
253 <tag-name><literal>args</literal></tag-name>
254 <tag-desc>arguments string</tag-desc>
255
256 <tag-name><literal>body</literal></tag-name>
257 <tag-desc>request body</tag-desc>
258
259 <tag-name><literal>method</literal></tag-name>
260 <tag-desc>HTTP method</tag-desc>
261 </list>
262 </para>
263
264 <para>
265 The <literal>callback</literal> receives a response object
266 with the following properties:
267 <literal>uri</literal>, <literal>method</literal>,
268 <literal>status</literal>, <literal>contentType</literal>,
269 <literal>contentLength</literal>, <literal>headers</literal>,
270 <literal>args</literal>.
271 These properties have the same meaning as the request object properties.
272 Additionally, a reply object has the <literal>body</literal> property
273 holding the subrequest response body
274 and the <literal>parent</literal> property
275 referencing the parent request object.
276 </para>
277 </tag-desc>
278 </list>
279 </para>
280
281 <para>
282 The response object has the following properties:
283 <list type="tag">
284
285 <tag-name><literal>status</literal></tag-name>
286 <tag-desc>
287 response status, writable
288 </tag-desc>
289
290 <tag-name><literal>headers{}</literal></tag-name>
291 <tag-desc>
292 response headers object
293 </tag-desc>
294
295 <tag-name><literal>contentType</literal></tag-name>
296 <tag-desc>
297 the response <header>Content-Type</header> header field value, writable
298 </tag-desc>
299
300 <tag-name><literal>contentLength</literal></tag-name>
301 <tag-desc>
302 the response <header>Content-Length</header> header field value, writable
303 </tag-desc>
304 </list>
305 </para>
306
307 <para>
308 The response object has the following methods:
309 <list type="tag">
310
311 <tag-name><literal>sendHeader()</literal></tag-name>
312 <tag-desc>
313 sends the HTTP header to the client
314 </tag-desc>
315
316 <tag-name><literal>send(<value>string</value>)</literal></tag-name>
317 <tag-desc>
318 sends a part of the response body to the client
319 </tag-desc>
320
321 <tag-name><literal>finish()</literal></tag-name>
322 <tag-desc>
323 finishes sending a response to the client
324 </tag-desc>
325
326 <tag-name><literal>return(status[, string])</literal></tag-name>
327 <tag-desc>
328 sends
329 the entire response with the specified <literal>status</literal> to the client
330 (0.2.0)
331 <para>
332 It is possible to specify either a redirect URL
333 (for codes 301, 302, 303, 307, and 308)
334 or the response body text (for other codes) as the second argument.
335 </para>
336 </tag-desc>
337 </list>
338 </para> 168 </para>
339 169
340 </section> 170 </section>
341 171
342 </module> 172 </module>