# HG changeset patch # User Yaroslav Zhuravlev # Date 1529430213 -10800 # Node ID ed905ab118c703868dfae96e603e3dc7b46b1d08 # Parent 8e2b3aadc3ceeea2d40ca77e75f2735e7f48e583 Updated HTTP njs module according to njs 0.2.2. 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="12">
@@ -70,46 +70,46 @@ server { The http.js file: -function foo(req, res) { - req.log("hello from foo() handler"); +function foo(r) { + r.log("hello from foo() handler"); return "foo"; } -function summary(req, res) { +function summary(r) { var a, s, h; s = "JS summary\n\n"; - s += "Method: " + req.method + "\n"; - s += "HTTP version: " + req.httpVersion + "\n"; - s += "Host: " + req.headers.host + "\n"; - s += "Remote Address: " + req.remoteAddress + "\n"; - s += "URI: " + req.uri + "\n"; + s += "Method: " + r.method + "\n"; + s += "HTTP version: " + r.httpVersion + "\n"; + s += "Host: " + r.headersIn.host + "\n"; + s += "Remote Address: " + r.remoteAddress + "\n"; + s += "URI: " + r.uri + "\n"; s += "Headers:\n"; - for (h in req.headers) { - s += " header '" + h + "' is '" + req.headers[h] + "'\n"; + for (h in r.headersIn) { + s += " header '" + h + "' is '" + r.headersIn[h] + "'\n"; } s += "Args:\n"; - for (a in req.args) { - s += " arg '" + a + "' is '" + req.args[a] + "'\n"; + for (a in r.args) { + s += " arg '" + a + "' is '" + r.args[a] + "'\n"; } return s; } -function baz(req, res) { - res.headers.foo = 1234; - res.status = 200; - res.contentType = "text/plain; charset=utf-8"; - res.contentLength = 15; - res.sendHeader(); - res.send("nginx"); - res.send("java"); - res.send("script"); +function baz(r) { + r.status = 200; + r.headersOut.foo = 1234; + r.headersOut['Content-Type'] = "text/plain; charset=utf-8"; + r.headersOut['Content-Length'] = 15; + r.sendHeader(); + r.send("nginx"); + r.send("java"); + r.send("script"); - res.finish(); + r.finish(); } @@ -159,12 +159,11 @@ Sets an njs function for the specified v
-
+
-Each HTTP njs handler receives two arguments, -request -and response. +Each HTTP njs handler receives one argument, a request +object.
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="12">
@@ -70,46 +70,46 @@ server { Файл http.js: -function foo(req, res) { - req.log("hello from foo() handler"); +function foo(r) { + r.log("hello from foo() handler"); return "foo"; } -function summary(req, res) { +function summary(r) { var a, s, h; s = "JS summary\n\n"; - s += "Method: " + req.method + "\n"; - s += "HTTP version: " + req.httpVersion + "\n"; - s += "Host: " + req.headers.host + "\n"; - s += "Remote Address: " + req.remoteAddress + "\n"; - s += "URI: " + req.uri + "\n"; + s += "Method: " + r.method + "\n"; + s += "HTTP version: " + r.httpVersion + "\n"; + s += "Host: " + r.headersIn.host + "\n"; + s += "Remote Address: " + r.remoteAddress + "\n"; + s += "URI: " + r.uri + "\n"; s += "Headers:\n"; - for (h in req.headers) { - s += " header '" + h + "' is '" + req.headers[h] + "'\n"; + for (h in r.headersIn) { + s += " header '" + h + "' is '" + r.headersIn[h] + "'\n"; } s += "Args:\n"; - for (a in req.args) { - s += " arg '" + a + "' is '" + req.args[a] + "'\n"; + for (a in r.args) { + s += " arg '" + a + "' is '" + r.args[a] + "'\n"; } return s; } -function baz(req, res) { - res.headers.foo = 1234; - res.status = 200; - res.contentType = "text/plain; charset=utf-8"; - res.contentLength = 15; - res.sendHeader(); - res.send("nginx"); - res.send("java"); - res.send("script"); +function baz(r) { + r.status = 200; + r.headersOut.foo = 1234; + r.headersOut['Content-Type'] = "text/plain; charset=utf-8"; + r.headersOut['Content-Length'] = 15; + r.sendHeader(); + r.send("nginx"); + r.send("java"); + r.send("script"); - res.finish(); + r.finish(); } @@ -160,12 +160,11 @@ function baz(req, res) {
-
+
-Каждый HTTP-обработчик njs получает два аргумента, -запрос -и ответ. +Каждый HTTP-обработчик njs получает один аргумент, +объект запроса.