Mercurial > hg > nginx-site
diff xml/en/docs/njs/examples.xml @ 2332:9d502d4305ac
Removed obsolete properties and examples from njs.
author | Yaroslav Zhuravlev <yar@nginx.com> |
---|---|
date | Tue, 26 Feb 2019 18:22:40 +0300 |
parents | 8cef5ef98336 |
children | aa20cba8027c |
line wrap: on
line diff
--- a/xml/en/docs/njs/examples.xml +++ b/xml/en/docs/njs/examples.xml @@ -9,7 +9,7 @@ <article name="Examples" link="/en/docs/njs/examples.html" lang="en" - rev="3"> + rev="4"> <section id="helloword" name="Hello World"> @@ -305,134 +305,4 @@ function create_secure_link(r) { </section> - -<section id="legacy" name="Legacy Examples"> - -<section id="legacy_stream" name="Injecting HTTP header using stream proxy"> - -<para> -Starting from njs <link doc="../njs/changes.xml" id="njs0.2.4">0.2.4</link>, -stream configuration -<link doc="../stream/ngx_stream_js_module.xml" id="example">example</link> -has been changed. -For njs <link doc="../njs/changes.xml" id="njs0.2.3">0.2.3</link> -and earlier, use this configuration example: -<example> -load_module modules/ngx_stream_js_module.so; -... - -stream { - js_include stream.js; - - js_set $foo foo; - js_set $bar bar; - - server { - listen 12345; - - js_preread qux; - return $foo; - } - - server { - listen 12346; - - js_access xyz; - proxy_pass 127.0.0.1:8000; - js_filter baz; - } -} - -http { - server { - listen 8000; - location / { - return 200 $http_foo\n; - } - } -} -</example> -</para> - -<para> -The <path>stream.js</path> file: -<example> -var req = ''; -var matched = 0; -var line = ''; - -function qux(s) { - var n = s.buffer.indexOf('\n'); - if (n == -1) { - return s.AGAIN; - } - - line = s.buffer.substr(0, n); -} - -function foo(s) { - return line; -} - -function bar(s) { - var v = s.variables; - s.log("hello from bar() handler!"); - return "foo-var" + v.remote_port + "; pid=" + v.pid; -} - -// The filter processes one buffer per call. -// The buffer is available in s.buffer both for -// reading and writing. Called for both directions. - -function baz(s) { - if (s.fromUpstream || matched) { - return; - } - - // Disable certain addresses. - - if (s.remoteAddress.match('^192.*')) { - return s.ERROR; - } - - // Read HTTP request line. - // Collect bytes in 'req' until request - // line is read. Clear current buffer to - // disable output. - - req = req + s.buffer; - s.buffer = ''; - - var n = req.search('\n'); - - if (n != -1) { - // Inject a new HTTP header. - var rest = req.substr(n + 1); - req = req.substr(0, n + 1); - - var addr = s.remoteAddress; - - s.log('req:' + req); - s.log('rest:' + rest); - - // Output the result and skip further - // processing. - - s.buffer = req + 'Foo: addr_' + addr + '\r\n' + rest; - matched = 1; - } -} - -function xyz(s) { - if (s.remoteAddress.match('^192.*')) { - return s.ABORT; - } -} -</example> -</para> - -</section> - -</section> - </article>