Skip to content

Commit

Permalink
Don't clear cookies for non-cached responses
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon-Michael Deldin and Max Spransy authored and maxjustus committed May 21, 2015
1 parent 6bff981 commit c879834
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/luchador/cache.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ function Cache:miss()
local upst = upstream.new(self.upstream_location)
local ttl = upst:ttl()
local cacheable = upst.status == 200 and ttl and not (ttl == '0')
self['upstream_filter'](ngx.var.request_uri, upst)

if cacheable then
self['upstream_filter'](ngx.var.request_uri, upst)
end

local body, encoding =
self.storage:compress(upst.body, upst.header['Content-Type'], cacheable)
Expand Down
7 changes: 7 additions & 0 deletions test/integration_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,13 @@ test("Does not cache Set-Cookie header by default", function()
assert_equal(headers:match("Set%-Cookie"), nil)
end)

test("It does not strip Set-Cookie for stuff not being cached", function()
local resp = { ["Set-Cookie"] = "blue=red;" }

local headers = get({}, resp, false)
assert_match(headers, "Set%-Cookie")
end)

test("Caches locally once min_hits_for_local is met", function()
local resp = {['Content-Type'] = 'text/html', ['Cache-Control'] = 'max-age=10, public'}
get({}, resp, false)
Expand Down

0 comments on commit c879834

Please sign in to comment.