openresty / openresty/srcache-nginx-module
Location header rewritten coming from cache
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 486
- Forks
- 101
- Avg merge
- 1h 28m
- Merged PRs (30d)
- 2
Description
We're running into an issue where the Location header sent in a 302 request is getting changed depending on if the response is a cache MISS or HIT. On misses, a relative URL is returned (as desired). On hits, an absolute URL is returned despite a relative URL being saved to the cache.
The srcache configuration:
srcache_response_cache_control on;
srcache_default_expire 0s;
set $key $scheme$host$request_uri$bb_accept$requested_with$cookie__bb_locale$cookie__bb_country;
set_escape_uri $escaped_key $key;
srcache_fetch GET /redis $key;
srcache_store PUT /redis2 key=$escaped_key&exptime=$srcache_expire;
When submitting a request that returns 302 response that is a cache MISS, the Location header is relative.
curl -i -H "Host: foobar.example.com" localhost/categories/non-gmo
HTTP/1.1 302 Moved Temporarily
Server: openresty
Date: Thu, 05 Feb 2015 21:03:42 GMT
Content-Type: text/plain; charset=UTF-8
Content-Length: 64
Connection: keep-alive
Vary: X-HTTP-Method-Override, Accept
Cache-Control: public, max-age=3600
Location: /categories/non-gmo-2/products
127.0.0.1 - - [05/Feb/2015:20:59:49 +0000] "GET /categories/non-gmo HTTP/1.1" 302 64 "-" "curl/7.35.0" 0.003 0.001 - - foobar.example.com public, max-age=3600 - MISS
We can see that the response is now cached in our redis instance:
redis-cache:6379> GET foobar.example:938810f609eeeddf722e3ac68ecca339
"HTTP/1.1 302 Moved Temporarily\r\nContent-Type: text/plain; charset=UTF-8\r\nVary: X-HTTP-Method-Override, Accept\r\nCache-Control: public, max-age=3600\r\nLocation: /categories/non-gmo-2/products\r\n\r\nMoved Temporarily. Redirecting to /categories/non-gmo-2/products"
Subsequent requests that generate a cache HIT are returned with a FQDN in the Location header rather than the relative path:
curl -i -H "Host: foobar.example.com" localhost/categories/non-gmo
HTTP/1.1 302 Moved Temporarily
Server: openresty
Date: Thu, 05 Feb 2015 21:08:15 GMT
Content-Type: text/plain; charset=UTF-8
Content-Length: 64
Location: http://foobar.example.com/categories/non-gmo-2/products
Connection: keep-alive
Vary: X-HTTP-Method-Override, Accept
Cache-Control: public, max-age=3600
127.0.0.1 - - [05/Feb/2015:21:08:15 +0000] "GET /categories/non-gmo HTTP/1.1" 302 64 "-" "curl/7.35.0" 0.003 - - - foobar.example.com - - HIT
I've tried using proxy_redirect off; in the nginx configuration, but it doesn't seem to have an affect on the responses coming from srcache.
If I use srcache_store_statuses 200; to explicitly not cache redirect pages, responses include relative Location headers and aren't cached. This is less desirable in our environment, but is a temporary workaround.
Can you confirm that srcache rewriting the Location header being returned in cached responses? Is there an option for disabling the behavior we're experiencing?
Thank you.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the MISS and HIT behavior with the shown srcache_fetch, srcache_store, and srcache_store_statuses settings, then trace how cached response headers are processed. Confirm whether the Location header is rewritten during cache fetch and identify whether disabling that behavior is supported; done means the behavior is explained and covered by a regression check.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, nginx
- Domain
- backend, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100