Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How are vary headers treated? #5

Open
hedleyroos opened this issue Mar 27, 2017 · 2 comments
Open

How are vary headers treated? #5

hedleyroos opened this issue Mar 27, 2017 · 2 comments

Comments

@hedleyroos
Copy link

I have a scenario where the upstream server (in this case Django) may set a few vary headers. I do ignore Set-Cookie in the Nginx configuration.

  1. Visit /path/ from a web browser -> creates a file in the cache directory.
  2. Visit same /path/ with curl -X GET from a command line on the webserver -> creates another file in the cache directory.

I assume this is because of different Accept-Encoding's and I understand the reasoning.

Now, when I issue curl -X PURGE http://localhost/path/ only the cached file from (2) is deleted.

Is there a way to tell the module to consider only the cache key, no other headers, when determining which cached files to delete?

@sharpobject
Copy link

sharpobject commented May 24, 2017

Hi hedleyroos,

A good place to read about how this works is ngx_http_do_file_cache_read and ngx_http_file_cache_reopen. I'll summarize it here for you.

When nginx gets a file from the cache using ngx_http_file_cache_open (for a GET or a single-key PURGE), it has some hash function H and it calculates H(cachekey) and uses that to look up a file. That file might say "this resource varies on these headers". If it does say that, it compares the header values stored in the file to the header values in the request. If they do not match, it looks up the file at H(H(cachekey)+values of headers) instead. Or something like that.

In your scenario, if you want to purge both files, you should purge with curl headers first, then purge with your web browser's headers. If you do it in the opposite order, after purging the file created in step 1, the file created in step 2 will not be able to be found by ngx_http_file_cache_open, so you will get a 404, but the content will still be in the cache. At this point if you GET with your web browser, then GET with curl, curl will be served the cached content you tried to purge.

@sharpobject
Copy link

If you use the partial key feature in this fork, it will successfully purge all variants of all matching keys.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants