replacing cache-control headers

Ryan Malayter malayter at gmail.com
Thu Mar 11 18:17:03 MSK 2010


I'm trying to add Cache-Control headers to an ill-behaved backend
application (that I don't control). For many requests, the backend
sets Cache-Control headers with an empty value (an RFC violation, I
know, and a bug report has been filed, but resolution is likely going
to take months from the vendor). Nginx 0.7.62 using default Ubuntu
package from Karmic.

I need to avoid using the "more Headers" module if at all possible for
administrative reasons (standard packages are much easier to deal with
administratively and make life much easier during audits).

So, I am trying to use proxy_hide_header and variables to
conditionally set the header. The problem is that using
$upstream_http_cache_control in a "set" or "if" statement always seems
to evaluate to the empty string. However, I can add a customer header
which shows the value passed from the upstream correctly if is not
empty.

Here is the relevant portion of my config (I have tried many variants
of positive and negative logic, without success):

        location / {
        proxy_pass http://backend;
        proxy_set_header Host $host;
        proxy_read_timeout 900;
        proxy_redirect default;
        proxy_hide_header Pragma;
        proxy_hide_header Cache-Control;

        set $mycc $upstream_http_cache_control;
        if ($mycc = "") {
                set $mycc "no-cache";
                }

        add_header "Cache-Control" $mycc;
        add_header "X-Upstream-Cache-Control" $upstream_http_cache_control;
        add_header "X-Upstream-Expires" $upstream_http_expires;
        }

With this configuration, I always get "Cache-Control: no-cache"
headers, even when "X-Upstream-Cache-Control" shows that the upstream
did pass a non-empty Cache-Control header. An Example response:
  HTTP/1.1 200 OK
  Server: nginx/0.7.62
  Date: Thu, 11 Mar 2010 15:10:36 GMT
  Content-Type: application/x-javascript
  Connection: keep-alive
  Content-Length: 10134
  Last-Modified: Sun, 24 Jan 2010 12:05:44 GMT
  Accept-Ranges: bytes
  ETag: "166958eed9cca1:0"
  Cache-Control: no-cache
  X-Upstream-Cache-Control: max-age=900

Is there any way do do this using default nginx modules?
-- 
RPM



More information about the nginx mailing list