Skip to content

Commit

Permalink
fix(proxy-cache): bypass when method mismatch cache_method (#7111)
Browse files Browse the repository at this point in the history
Co-authored-by: soulbird <[email protected]>
  • Loading branch information
2 people authored and spacewander committed Jun 20, 2022
1 parent 6702131 commit 375eb8a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
5 changes: 5 additions & 0 deletions apisix/plugins/proxy-cache/disk_handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ function _M.access(conf, ctx)
ctx.var.upstream_cache_bypass = value
core.log.info("proxy-cache cache bypass value:", value)
end

if not util.match_method(conf, ctx) then
ctx.var.upstream_cache_bypass = "1"
core.log.info("proxy-cache cache bypass method: ", ctx.var.request_method)
end
end


Expand Down
15 changes: 8 additions & 7 deletions t/plugin/proxy-cache/disk.t
Original file line number Diff line number Diff line change
Expand Up @@ -451,21 +451,22 @@ Apisix-Cache-Status: MISS
=== TEST 17: hit route (HEAD method)
=== TEST 17: hit route (will be cached)
--- request
HEAD /hello-world
--- error_code: 200
GET /hello
--- response_body chop
hello world!
--- response_headers
Apisix-Cache-Status: MISS
Apisix-Cache-Status: HIT
=== TEST 18: hit route (HEAD method there's no cache)
=== TEST 18: hit route (HEAD method mismatch cache_method)
--- request
HEAD /hello-world
HEAD /hello
--- error_code: 200
--- response_headers
Apisix-Cache-Status: MISS
Apisix-Cache-Status: BYPASS
Expand Down

0 comments on commit 375eb8a

Please sign in to comment.