changeset 2926:237a77d8565b

Extended description of r_variables in njs.
author Yaroslav Zhuravlev <yar@nginx.com>
date Thu, 05 Jan 2023 16:34:01 +0000
parents 3be061a0941a
children decdcc6e9938
files xml/en/docs/njs/reference.xml
diffstat 1 files changed, 25 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/xml/en/docs/njs/reference.xml
+++ b/xml/en/docs/njs/reference.xml
@@ -9,7 +9,7 @@
 <article name="Reference"
         link="/en/docs/njs/reference.html"
         lang="en"
-        rev="94">
+        rev="95">
 
 <section id="summary">
 
@@ -578,6 +578,30 @@ writable
 (since <link doc="changes.xml" id="njs0.2.8">0.2.8</link>).
 
 <para>
+For example, to get the <literal>$foo</literal> variable,
+one of the following syntax can be used:
+<example>
+r.variables['foo']
+r.variables.foo
+</example>
+nginx treats variables referenced in <literal>nginx.conf</literal>
+and unreferenced variables differently.
+When a variable is referenced, it may be cacheable,
+but when it is unreferenced it is always uncacheable.
+For example, when the
+<link doc="../http/ngx_http_core_module.xml" id="var_request_id">$request_id</link>
+variable is only accessed from njs,
+it has a new value every time it is evaluated.
+But, when the
+<link doc="../http/ngx_http_core_module.xml" id="var_request_id">$request_id</link>
+is referenced, for example:
+<example>
+proxy_set_header X-Request-Id $request_id;
+</example>
+the <literal>r.variables.request_id</literal> returns the same value every time.
+</para>
+
+<para>
 A variable is writable if:
 <list type="bullet">