From 375eb8a150976f0b6150af9d5a839038d4252a76 Mon Sep 17 00:00:00 2001 From: soulbird Date: Tue, 24 May 2022 15:01:27 +0800 Subject: [PATCH] fix(proxy-cache): bypass when method mismatch cache_method (#7111) Co-authored-by: soulbird --- apisix/plugins/proxy-cache/disk_handler.lua | 5 +++++ t/plugin/proxy-cache/disk.t | 15 ++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/apisix/plugins/proxy-cache/disk_handler.lua b/apisix/plugins/proxy-cache/disk_handler.lua index bf131b158a8c..70d3532aca1b 100644 --- a/apisix/plugins/proxy-cache/disk_handler.lua +++ b/apisix/plugins/proxy-cache/disk_handler.lua @@ -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 diff --git a/t/plugin/proxy-cache/disk.t b/t/plugin/proxy-cache/disk.t index a1b09d184aa0..954f967f725d 100644 --- a/t/plugin/proxy-cache/disk.t +++ b/t/plugin/proxy-cache/disk.t @@ -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