<div dir="ltr">Hi!<div><br></div><div>It's still a problem when the variable generated by map and including itself. For example:</div><div><br></div><div><div>map $host $abc {</div><div>    default  $abc;</div><div>}</div><div><br></div><div>server {</div><div>    listen  80;</div><div><br></div><div>    location / {</div><div>        return 200 $abc;</div><div>    }</div><div>}</div></div><div><br></div><div>Thanks.</div><div>B.R~</div></div><div class="gmail_extra"><br><div class="gmail_quote">2016-12-09 2:46 GMT+08:00 Ruslan Ermilov <span dir="ltr"><<a href="mailto:ru@nginx.com" target="_blank">ru@nginx.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">details:   <a href="http://hg.nginx.org/nginx/rev/ec10ce307dc0" rel="noreferrer" target="_blank">http://hg.nginx.org/nginx/rev/<wbr>ec10ce307dc0</a><br>
branches:<br>
changeset: 6832:ec10ce307dc0<br>
user:      Ruslan Ermilov <<a href="mailto:ru@nginx.com">ru@nginx.com</a>><br>
date:      Thu Dec 08 17:51:49 2016 +0300<br>
description:<br>
Map: the "volatile" parameter.<br>
<br>
By default, "map" creates cacheable variables [1].  With this<br>
parameter it creates a non-cacheable variable.<br>
<br>
An original idea was to deduce the cacheability of the "map"<br>
variable by checking the cacheability of variables specified<br>
in source and resulting values, but it turned to be too hard.<br>
For example, a cacheable variable can be overridden with the<br>
"set" directive or with the SSI "set" command.  Also, keeping<br>
"map" variables cacheable by default is good for performance<br>
reasons.  This required adding a new parameter.<br>
<br>
[1] Before db699978a33f (1.11.0), the cacheability of the<br>
"map" variable could vary depending on the cacheability of<br>
variables specified in resulting values (ticket #1090).<br>
This is believed to be a bug rather than a feature.<br>
<br>
diffstat:<br>
<br>
 src/http/modules/ngx_http_map_<wbr>module.c |  15 ++++++++++++++-<br>
 src/stream/ngx_stream_map_<wbr>module.c     |  15 ++++++++++++++-<br>
 2 files changed, 28 insertions(+), 2 deletions(-)<br>
<br>
diffs (92 lines):<br>
<br>
diff -r 014905eb7b3d -r ec10ce307dc0 src/http/modules/ngx_http_map_<wbr>module.c<br>
--- a/src/http/modules/ngx_http_<wbr>map_module.c    Thu Dec 08 17:29:01 2016 +0300<br>
+++ b/src/http/modules/ngx_http_<wbr>map_module.c    Thu Dec 08 17:51:49 2016 +0300<br>
@@ -26,7 +26,8 @@ typedef struct {<br>
<br>
     ngx_http_variable_value_t  *default_value;<br>
     ngx_conf_t                 *cf;<br>
-    ngx_uint_t                  hostnames;      /* unsigned  hostnames:1 */<br>
+    unsigned                    hostnames:1;<br>
+    unsigned                    no_cacheable:1;<br>
 } ngx_http_map_conf_ctx_t;<br>
<br>
<br>
@@ -265,6 +266,7 @@ ngx_http_map_block(ngx_conf_t *cf, ngx_c<br>
     ctx.default_value = NULL;<br>
     <a href="http://ctx.cf" rel="noreferrer" target="_blank">ctx.cf</a> = &save;<br>
     ctx.hostnames = 0;<br>
+    ctx.no_cacheable = 0;<br>
<br>
     save = *cf;<br>
     cf->pool = pool;<br>
@@ -281,6 +283,10 @@ ngx_http_map_block(ngx_conf_t *cf, ngx_c<br>
         return rv;<br>
     }<br>
<br>
+    if (ctx.no_cacheable) {<br>
+        var->flags |= NGX_HTTP_VAR_NOCACHEABLE;<br>
+    }<br>
+<br>
     map->default_value = ctx.default_value ? ctx.default_value:<br>
                                              &ngx_http_variable_null_value;<br>
<br>
@@ -395,6 +401,13 @@ ngx_http_map(ngx_conf_t *cf, ngx_command<br>
         return NGX_CONF_OK;<br>
     }<br>
<br>
+    if (cf->args->nelts == 1<br>
+        && ngx_strcmp(value[0].data, "volatile") == 0)<br>
+    {<br>
+        ctx->no_cacheable = 1;<br>
+        return NGX_CONF_OK;<br>
+    }<br>
+<br>
     if (cf->args->nelts != 2) {<br>
         ngx_conf_log_error(NGX_LOG_<wbr>EMERG, cf, 0,<br>
                            "invalid number of the map parameters");<br>
diff -r 014905eb7b3d -r ec10ce307dc0 src/stream/ngx_stream_map_<wbr>module.c<br>
--- a/src/stream/ngx_stream_map_<wbr>module.c        Thu Dec 08 17:29:01 2016 +0300<br>
+++ b/src/stream/ngx_stream_map_<wbr>module.c        Thu Dec 08 17:51:49 2016 +0300<br>
@@ -26,7 +26,8 @@ typedef struct {<br>
<br>
     ngx_stream_variable_value_t  *default_value;<br>
     ngx_conf_t                   *cf;<br>
-    ngx_uint_t                    hostnames;      /* unsigned  hostnames:1 */<br>
+    unsigned                      hostnames:1;<br>
+    unsigned                      no_cacheable:1;<br>
 } ngx_stream_map_conf_ctx_t;<br>
<br>
<br>
@@ -264,6 +265,7 @@ ngx_stream_map_block(ngx_conf_<wbr>t *cf, ngx<br>
     ctx.default_value = NULL;<br>
     <a href="http://ctx.cf" rel="noreferrer" target="_blank">ctx.cf</a> = &save;<br>
     ctx.hostnames = 0;<br>
+    ctx.no_cacheable = 0;<br>
<br>
     save = *cf;<br>
     cf->pool = pool;<br>
@@ -280,6 +282,10 @@ ngx_stream_map_block(ngx_conf_<wbr>t *cf, ngx<br>
         return rv;<br>
     }<br>
<br>
+    if (ctx.no_cacheable) {<br>
+        var->flags |= NGX_STREAM_VAR_NOCACHEABLE;<br>
+    }<br>
+<br>
     map->default_value = ctx.default_value ? ctx.default_value:<br>
                                              &ngx_stream_variable_null_<wbr>value;<br>
<br>
@@ -394,6 +400,13 @@ ngx_stream_map(ngx_conf_t *cf, ngx_comma<br>
         return NGX_CONF_OK;<br>
     }<br>
<br>
+    if (cf->args->nelts == 1<br>
+        && ngx_strcmp(value[0].data, "volatile") == 0)<br>
+    {<br>
+        ctx->no_cacheable = 1;<br>
+        return NGX_CONF_OK;<br>
+    }<br>
+<br>
     if (cf->args->nelts != 2) {<br>
         ngx_conf_log_error(NGX_LOG_<wbr>EMERG, cf, 0,<br>
                            "invalid number of the map parameters");<br>
______________________________<wbr>_________________<br>
nginx-devel mailing list<br>
<a href="mailto:nginx-devel@nginx.org">nginx-devel@nginx.org</a><br>
<a href="http://mailman.nginx.org/mailman/listinfo/nginx-devel" rel="noreferrer" target="_blank">http://mailman.nginx.org/<wbr>mailman/listinfo/nginx-devel</a><br>
</blockquote></div><br></div>