<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">Yup, again, you’re right! I’ve moved the config around, so that I’m testing for any ‘true’ value in the proxy_no_cache & proxy_bypass_cache directives (removing the existing set_by_lua block).<div><br></div><div>However, it’s still not behaving as I’d expect.</div><div><br></div><div>In the following scenario (note comments):</div><div><br></div><div><div>map $upstream_http_x_no_cache $no_cache_header {</div><div> "" 0;</div><div> default 1;</div><div>}</div></div><div><br></div><div><div>proxy_cache_bypass $no_cache_dirs $logged_in; # $no_cache_header;</div><div>proxy_no_cache<span class="Apple-tab-span" style="white-space:pre"> </span> $no_cache_dirs $logged_in; # $no_cache_header;</div></div><div><br></div><div>X-Cache-Status value is MISS, which is correct. Output of $no_cache_header is 1 (as set in the map).</div><div><br></div><div>However, when adding back in the compare on $no_cache_header:</div><div><br></div><div><div>proxy_cache_bypass $no_cache_dirs $logged_in $no_cache_header;</div><div>proxy_no_cache<span class="Apple-tab-span" style="white-space: pre;"> </span> $no_cache_dirs $logged_in $no_cache_header;</div></div><div><br></div><div>X-Cache-Status value is still MISS, which is not correct, as it should be BYPASS. Output of $no_cache_header is 0.</div><div><br></div><div>Unless I’m missing something, it still looks like touching the variable kills it?</div><div><br></div><div>Thanks again,</div><div><br></div><div>Paul</div><div><br><div><div>On 13 Dec 2013, at 16:31, Maxim Dounin <<a href="mailto:mdounin@mdounin.ru">mdounin@mdounin.ru</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">Hello!<br><br>On Thu, Dec 12, 2013 at 11:36:21PM +0000, Paul Taylor wrote:<br><br><blockquote type="cite">Hi Maxim,<br>Thanks for your response. You’re right! Using the map did work<span class="Apple-converted-space"> </span><br>(I thought I’d tried that, but must have been tired!).<br>So, now I have one other challenge, the value of $foo that you<span class="Apple-converted-space"> </span><br>define below is needed to identify whether to cache the response<span class="Apple-converted-space"> </span><br>of not. The only issue is that I have a number of other<span class="Apple-converted-space"> </span><br>directives that I also need to add into the mix - therefore I<span class="Apple-converted-space"> </span><br>use the set_by_lua code to nest/combine OR within an if<span class="Apple-converted-space"> </span><br>statement…code below (I’ve kept the variable name as foo, so<span class="Apple-converted-space"> </span><br>it’s clear which I’m referring to):<br>map $upstream_http_x_no_cache $foo {<br> "" 0;<br> default 1;<br>}<br>set_by_lua $bypass_cache '<br> local no_cache_dirs = tonumber(<a href="http://ngx.var.no">ngx.var.no</a>_cache_dirs) or 0<br> local logged_in = tonumber(ngx.var.logged_in) or 0<br> local no_cache_header = tonumber(ngx.var.foo) or 0<br><br> if((no_cache_dirs == 1) or (no_cache_header == 1) or<span class="Apple-converted-space"> </span><br> (logged_in == 1)) then<br> return 1;<br> end<br><br> return 0;<br>';<br>Now when I make the Lua local variable declaration in order to<span class="Apple-converted-space"> </span><br>use it, the value of $upstream_http_x_no_cache is reset to 0,<span class="Apple-converted-space"> </span><br>even when it was set as 1 originally. If I comment out the line<span class="Apple-converted-space"> </span><br>declaring the local variable within the Lua call, it returns to<span class="Apple-converted-space"> </span><br>being a value of 1 again.<br>Am I getting the sequencing of events wrong again? Is there any<span class="Apple-converted-space"> </span><br>way that I can get the value of $upstream_http_x_no_cache into<span class="Apple-converted-space"> </span><br>this Lua block, or would I need to do it another way?<br></blockquote><br>Are you going to use the result in proxy_no_cache? If yes, you<span class="Apple-converted-space"> </span><br>can just use multiple variables there, something like this should<span class="Apple-converted-space"> </span><br>work:<br><br> proxy_no_cache $upstream_http_x_no_cache<br> $no_cache_dirs<br> $logged_in;<br><br>See here for details:<br><br><a href="http://nginx.org/r/proxy_no_cache">http://nginx.org/r/proxy_no_cache</a><br><br><blockquote type="cite">Thanks very much for your help so far Maxim.<br>Paul<br>__________________________________________________________________<br>Hello!<br><br>On Thu, Dec 12, 2013 at 07:19:56PM +0000, Paul Taylor wrote:<br><br><blockquote type="cite">I’m in the process of making some amends to an environment,<span class="Apple-converted-space"> </span><br>where my upstream servers are sending a custom header<span class="Apple-converted-space"> </span><br>(X-No-Cache), which I need to detect and alter caching rules<span class="Apple-converted-space"> </span><br>within the configuration.<br><br>The custom header is visible within the output, and I can<span class="Apple-converted-space"> </span><br>re-output it as another header through configuration (i.e.<span class="Apple-converted-space"> </span><br>add_header X-Sent-No-Cache $sent_http_x_no_cache; ).<br><br>However, as soon as I perform any type of testing of this custom<span class="Apple-converted-space"> </span><br>header, it disappears.<br><br>For example, if I was to perform a map on the custom header, try<span class="Apple-converted-space"> </span><br>to set an Nginx variable to the value of the header, or test<span class="Apple-converted-space"> </span><br>within an IF statement, any future call to this header is no<span class="Apple-converted-space"> </span><br>longer possible. Additionally any setting or testing of the<span class="Apple-converted-space"> </span><br>header fails.<br></blockquote><br>Both "set" and "if" directives you mentioned are executed _before_<span class="Apple-converted-space"> </span><br>a request is sent to upstream, and at this point there is no<span class="Apple-converted-space"> </span><br>X-No-Cache header in the response. Due to this, using the<span class="Apple-converted-space"> </span><br>$sent_http_x_no_cache variable in "set" or "if" will result in an<span class="Apple-converted-space"> </span><br>empty value, and this value will be cached for later use.<br><br>It's not clear what you are trying to do so I can't advise any<span class="Apple-converted-space"> </span><br>further, but certainly using the $sent_http_x_no_cache variable in<span class="Apple-converted-space"> </span><br>"if" or "set" directives isn't going to work, and this is what<span class="Apple-converted-space"> </span><br>causes behaviour you see.<br><br>Just a map{} should work fine though - as long as you don't try to<span class="Apple-converted-space"> </span><br>call the map before the X-No-Cache header is actually available. <br>E.g., something like this should work fine:<br><br> map $sent_http_x_no_cache $foo {<br> "" empty;<br> default foo;<br> }<br><br> add_header X-Foo $foo;<br><br>It might be also a goo idea to use $upstream_http_x_no_cache<span class="Apple-converted-space"> </span><br>variable instead, see here:<br><br><a href="http://nginx.org/en/docs/http/ngx_http_upstream_module.html#variables">http://nginx.org/en/docs/http/ngx_http_upstream_module.html#variables</a><br><br>--<span class="Apple-converted-space"> </span><br>Maxim Dounin<br>http://nginx.org/<br><br></blockquote><br><blockquote type="cite">_______________________________________________<br>nginx mailing list<br><a href="mailto:nginx@nginx.org">nginx@nginx.org</a><br><a href="http://mailman.nginx.org/mailman/listinfo/nginx">http://mailman.nginx.org/mailman/listinfo/nginx</a><br></blockquote><br><br>--<span class="Apple-converted-space"> </span><br>Maxim Dounin<br><a href="http://nginx.org/">http://nginx.org/</a><br><br>_______________________________________________<br>nginx mailing list<br><a href="mailto:nginx@nginx.org">nginx@nginx.org</a><br><a href="http://mailman.nginx.org/mailman/listinfo/nginx">http://mailman.nginx.org/mailman/listinfo/nginx</a></div></blockquote></div><br></div></body></html>