Mercurial > hg > nginx-site
comparison xml/ru/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="Модуль ngx_http_js_module" | 9 <module name="Модуль ngx_http_js_module" |
10 link="/ru/docs/http/ngx_http_js_module.html" | 10 link="/ru/docs/http/ngx_http_js_module.html" |
11 lang="ru" | 11 lang="ru" |
12 rev="11"> | 12 rev="12"> |
13 | 13 |
14 <section id="summary"> | 14 <section id="summary"> |
15 | 15 |
16 <para> | 16 <para> |
17 Модуль <literal>ngx_http_js_module</literal> позволяет задавать | 17 Модуль <literal>ngx_http_js_module</literal> позволяет задавать |
68 </para> | 68 </para> |
69 | 69 |
70 <para> | 70 <para> |
71 Файл <path>http.js</path>: | 71 Файл <path>http.js</path>: |
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> |
158 </directive> | 158 </directive> |
159 | 159 |
160 </section> | 160 </section> |
161 | 161 |
162 | 162 |
163 <section id="arguments" name="Аргументы запроса и ответа"> | 163 <section id="arguments" name="Аргумент запроса"> |
164 | 164 |
165 <para> | 165 <para> |
166 Каждый HTTP-обработчик njs получает два аргумента, | 166 Каждый HTTP-обработчик njs получает один аргумент, |
167 <link doc="../njs/njs_api.xml" id="http_request">запрос</link> | 167 <link doc="../njs/njs_api.xml" id="http_request">объект</link> запроса. |
168 и <link doc="../njs/njs_api.xml" id="http_response">ответ</link>. | |
169 </para> | 168 </para> |
170 | 169 |
171 </section> | 170 </section> |
172 | 171 |
173 </module> | 172 </module> |