Skip to content

Location header rewritten coming from cache #32

@AlexClineBB

Description

@AlexClineBB

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions