Mercurial > hg > nginx-site
comparison xml/en/docs/http/ngx_http_js_module.xml @ 2187:ed905ab118c7
Updated HTTP njs module according to njs 0.2.2.
author | Yaroslav Zhuravlev <yar@nginx.com> |
---|---|
date | Tue, 19 Jun 2018 20:43:33 +0300 |
parents | cd4889fdcfa4 |
children | 523dc4cc8745 |
comparison
equal
deleted
inserted
replaced
2186:8e2b3aadc3ce | 2187:ed905ab118c7 |
---|---|
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="11"> | 12 rev="12"> |
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 |
68 </para> | 68 </para> |
69 | 69 |
70 <para> | 70 <para> |
71 The <path>http.js</path> file: | 71 The <path>http.js</path> file: |
72 <example> | 72 <example> |
73 function foo(req, res) { | 73 function foo(r) { |
74 req.log("hello from foo() handler"); | 74 r.log("hello from foo() handler"); |
75 return "foo"; | 75 return "foo"; |
76 } | 76 } |
77 | 77 |
78 function summary(req, res) { | 78 function summary(r) { |
79 var a, s, h; | 79 var a, s, h; |
80 | 80 |
81 s = "JS summary\n\n"; | 81 s = "JS summary\n\n"; |
82 | 82 |
83 s += "Method: " + req.method + "\n"; | 83 s += "Method: " + r.method + "\n"; |
84 s += "HTTP version: " + req.httpVersion + "\n"; | 84 s += "HTTP version: " + r.httpVersion + "\n"; |
85 s += "Host: " + req.headers.host + "\n"; | 85 s += "Host: " + r.headersIn.host + "\n"; |
86 s += "Remote Address: " + req.remoteAddress + "\n"; | 86 s += "Remote Address: " + r.remoteAddress + "\n"; |
87 s += "URI: " + req.uri + "\n"; | 87 s += "URI: " + r.uri + "\n"; |
88 | 88 |
89 s += "Headers:\n"; | 89 s += "Headers:\n"; |
90 for (h in req.headers) { | 90 for (h in r.headersIn) { |
91 s += " header '" + h + "' is '" + req.headers[h] + "'\n"; | 91 s += " header '" + h + "' is '" + r.headersIn[h] + "'\n"; |
92 } | 92 } |
93 | 93 |
94 s += "Args:\n"; | 94 s += "Args:\n"; |
95 for (a in req.args) { | 95 for (a in r.args) { |
96 s += " arg '" + a + "' is '" + req.args[a] + "'\n"; | 96 s += " arg '" + a + "' is '" + r.args[a] + "'\n"; |
97 } | 97 } |
98 | 98 |
99 return s; | 99 return s; |
100 } | 100 } |
101 | 101 |
102 function baz(req, res) { | 102 function baz(r) { |
103 res.headers.foo = 1234; | 103 r.status = 200; |
104 res.status = 200; | 104 r.headersOut.foo = 1234; |
105 res.contentType = "text/plain; charset=utf-8"; | 105 r.headersOut['Content-Type'] = "text/plain; charset=utf-8"; |
106 res.contentLength = 15; | 106 r.headersOut['Content-Length'] = 15; |
107 res.sendHeader(); | 107 r.sendHeader(); |
108 res.send("nginx"); | 108 r.send("nginx"); |
109 res.send("java"); | 109 r.send("java"); |
110 res.send("script"); | 110 r.send("script"); |
111 | 111 |
112 res.finish(); | 112 r.finish(); |
113 } | 113 } |
114 </example> | 114 </example> |
115 </para> | 115 </para> |
116 | 116 |
117 </section> | 117 </section> |
157 </directive> | 157 </directive> |
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 Argument"> |
163 | 163 |
164 <para> | 164 <para> |
165 Each HTTP njs handler receives two arguments, | 165 Each HTTP njs handler receives one argument, a request |
166 <link doc="../njs/njs_api.xml" id="http_request">request</link> | 166 <link doc="../njs/njs_api.xml" id="http_request">object</link>. |
167 and <link doc="../njs/njs_api.xml" id="http_response">response</link>. | |
168 </para> | 167 </para> |
169 | 168 |
170 </section> | 169 </section> |
171 | 170 |
172 </module> | 171 </module> |