Map is not matching correctly against upstream custom header

Hi, I’m trying to configure my proxy cache settings based in a response
custom header, using proxy_no_cache and proxy_cache_bypass directives.

First question: is it possible at all?
Second question: If it is, why this map is always hitting the default
value?

map $sent_http_x_my_custom_header $no_cache {
default 0;
1 0;
true 0;
false 1;
“~*false” 1;
}

....

location ~ ^/ {

proxy_no_cache $no_cache;^M
proxy_cache_bypass $no_cache;^M
}

I’ve already tried the map with $sent_http_x_my_custom_header,
$upstream_http_x_my_custom_header and $http_x_my_custom_header. It’s
always the same result.

obs: I’ve already tried with if but if is resolved in request time so it
didn’t work.

Thank you in advance.

Hello!

On Thu, Jun 02, 2016 at 07:51:06PM +0200, Gabriel Arrais wrote:

    1          0;
   proxy_cache_bypass  $no_cache;^M

}

I’ve already tried the map with $sent_http_x_my_custom_header,
$upstream_http_x_my_custom_header and $http_x_my_custom_header. It’s
always the same result.

obs: I’ve already tried with if but if is resolved in request time so it
didn’t work.

The problem is that you are trying to lookup response headers when
there is no response yet. Both “if” and “proxy_cache_bypass” are
checked before the request is sent to a backend, and hence they
can’t do anything good.

Additionally, map{} results are always cached, and when you try to
lookup it again via “proxy_no_cache” it just return a previously
cached value (the one computed when there were no response yet).

Consider removing “proxy_cache_bypass” from your cofiguration.
Just

map $upstream_http_x_my_custom_header $no_cache {
    ...
}

proxy_no_cache $no_cache;

is expected to work fine.


Maxim D.
http://nginx.org/

Maxim D. wrote in post #1183769:

Hello!

On Thu, Jun 02, 2016 at 07:51:06PM +0200, Gabriel Arrais wrote:

    1          0;
   proxy_cache_bypass  $no_cache;^M

}

I’ve already tried the map with $sent_http_x_my_custom_header,
$upstream_http_x_my_custom_header and $http_x_my_custom_header. It’s
always the same result.

obs: I’ve already tried with if but if is resolved in request time so it
didn’t work.

The problem is that you are trying to lookup response headers when
there is no response yet. Both “if” and “proxy_cache_bypass” are
checked before the request is sent to a backend, and hence they
can’t do anything good.

Additionally, map{} results are always cached, and when you try to
lookup it again via “proxy_no_cache” it just return a previously
cached value (the one computed when there were no response yet).

Consider removing “proxy_cache_bypass” from your cofiguration.
Just

map $upstream_http_x_my_custom_header $no_cache {
    ...
}

proxy_no_cache $no_cache;

is expected to work fine.


Maxim D.
http://nginx.org/

Hello Maxim!

Thank you very much for the response, I think that I can’t remove the
“proxy_cache_bypass” from my configuration because other mecanisms are
using this directive, in other situations…

I will try to use two different variables for proxy_no_cache and
proxy_cache_bypass.

Again, thank you!

How did you solve this issue?
I have the same scenario, unresolved :frowning:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs