Supporting ", " for Cache-Control max-age directives in ngx_http_upstream.c

Zev Blut zblut at cerego.co.jp
Fri Feb 5 13:24:19 MSK 2010


Hello,

I have started to experiment with the nginx proxy_cache settings.
During my tests I have found that a simple Rails application that 
outputs Cache-Control headers is not recognized by nginx.

Using the "expires_in(15.minutes, :public => true)" command in Rails 
will output something like this:

Cache-Control: max-age=900, public

I spent sometime trying to get this to work with nginx, but with no 
success.  I dug in the source code for nginx-0.7.64's 
ngx_http_upstream.c and found that line 3018-3020 has this:
"
         if (*p == ';' || *p == ' ') {
             break;
         }
"
I think nginx wants max-age to either be
Cache-Control: max-age=900; public
or
Cache-Control: max-age=900 public
or
Cache-Control: max-age=900


Looking at the #rule in
http://www.w3.org/Protocols/rfc2616/rfc2616-sec2.html#sec2
and the BNF definition for Cache-Control
http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9

I think nginx should also allow ',' in the *p checks.
Like so:
"        if (*p == ';' || *p == ' ' || *p == ',' ) {"


For now, without changing nginx, I can manually create a Cache-Control 
response in Rails with ";" or " " and nginx properly caches the response.

But, I think we should patch nginx to accept ','.

BTW, proxy_cache is quite cool!

Thanks,
Zev



More information about the nginx mailing list