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

Location header rewritten coming from cache #32

Open
AlexClineBB opened this issue Feb 5, 2015 · 1 comment
Open

Location header rewritten coming from cache #32

AlexClineBB opened this issue Feb 5, 2015 · 1 comment

Comments

@AlexClineBB
Copy link

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.

agentzh added a commit that referenced this issue Feb 5, 2015
…module overwrite the Location response header's values like "/foo/bar" to the fully-qualified form (like "http://test.com/foo/bar"). thanks AlexClineBB for the report in #32.
@agentzh
Copy link
Member

agentzh commented Feb 5, 2015

@AlexClineBB Thank you for the bug report! Just fixed in git master. Will you try it out on your side?

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