You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by sp...@apache.org on 2022/06/20 06:13:55 UTC

[apisix] 02/07: fix(proxy-cache): bypass when method mismatch cache_method (#7111)

This is an automated email from the ASF dual-hosted git repository.

spacewander pushed a commit to branch release/2.13
in repository https://gitbox.apache.org/repos/asf/apisix.git

commit 375eb8a150976f0b6150af9d5a839038d4252a76
Author: soulbird <zh...@outlook.com>
AuthorDate: Tue May 24 15:01:27 2022 +0800

    fix(proxy-cache): bypass when method mismatch cache_method (#7111)
    
    Co-authored-by: soulbird <zh...@gmail.com>
---
 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 bf131b158..70d3532ac 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 a1b09d184..954f967f7 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