Welcome! Log In Create A New Profile

Advanced

Re: sent_http_HEADER Volatile under Nginx 1.2.4

Maxim Dounin
December 12, 2013 02:34PM
Hello!

On Thu, Dec 12, 2013 at 07:19:56PM +0000, Paul Taylor wrote:

> I’m in the process of making some amends to an environment,
> where my upstream servers are sending a custom header
> (X-No-Cache), which I need to detect and alter caching rules
> within the configuration.
>
> The custom header is visible within the output, and I can
> re-output it as another header through configuration (i.e.
> add_header X-Sent-No-Cache $sent_http_x_no_cache; ).
>
> However, as soon as I perform any type of testing of this custom
> header, it disappears.
>
> For example, if I was to perform a map on the custom header, try
> to set an Nginx variable to the value of the header, or test
> within an IF statement, any future call to this header is no
> longer possible. Additionally any setting or testing of the
> header fails.

Both "set" and "if" directives you mentioned are executed _before_
a request is sent to upstream, and at this point there is no
X-No-Cache header in the response. Due to this, using the
$sent_http_x_no_cache variable in "set" or "if" will result in an
empty value, and this value will be cached for later use.

It's not clear what you are trying to do so I can't advise any
further, but certainly using the $sent_http_x_no_cache variable in
"if" or "set" directives isn't going to work, and this is what
causes behaviour you see.

Just a map{} should work fine though - as long as you don't try to
call the map before the X-No-Cache header is actually available.
E.g., something like this should work fine:

map $sent_http_x_no_cache $foo {
"" empty;
default foo;
}

add_header X-Foo $foo;

It might be also a goo idea to use $upstream_http_x_no_cache
variable instead, see here:

http://nginx.org/en/docs/http/ngx_http_upstream_module.html#variables

--
Maxim Dounin
http://nginx.org/

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

sent_http_HEADER Volatile under Nginx 1.2.4

ptylr December 12, 2013 02:22PM

Re: sent_http_HEADER Volatile under Nginx 1.2.4

Maxim Dounin December 12, 2013 02:34PM

Re: sent_http_HEADER Volatile under Nginx 1.2.4

ptylr December 12, 2013 06:38PM

Re: sent_http_HEADER Volatile under Nginx 1.2.4

Maxim Dounin December 13, 2013 01:30PM

Re: sent_http_HEADER Volatile under Nginx 1.2.4

Maxim Dounin December 18, 2013 07:44AM

Re: sent_http_HEADER Volatile under Nginx 1.2.4

Jonathan Matthews December 18, 2013 07:44AM

Re: sent_http_HEADER Volatile under Nginx 1.2.4

ptylr December 18, 2013 07:44AM

Re: sent_http_HEADER Volatile under Nginx 1.2.4

ptylr December 18, 2013 07:50AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 316
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready