Firstsawyou commented on pull request #3556:
URL: https://github.com/apache/apisix/pull/3556#issuecomment-810912256


   Hi, @54corbin 
   This is a related test case, you can refer to it.
   
   ```shell
   diff --git a/apisix/plugins/proxy-rewrite.lua 
b/apisix/plugins/proxy-rewrite.lua
   index 07de40e..2905f90 100644
   --- a/apisix/plugins/proxy-rewrite.lua
   +++ b/apisix/plugins/proxy-rewrite.lua
   @@ -185,7 +185,7 @@ function _M.rewrite(conf, ctx)
    
        -- enum    = {"GET", "POST","PUT",""PATCH,"DELETE"}
        -- change HTTP method
   -    if conf.method ~=nil then
   +    if conf.method ~= nil then
    
          if conf.method == "GET" then
            ngx.req.set_method(ngx.HTTP_GET)
   diff --git a/t/plugin/proxy-rewrite.t b/t/plugin/proxy-rewrite.t
   index 89c5e5c..ed1d95f 100644
   --- a/t/plugin/proxy-rewrite.t
   +++ b/t/plugin/proxy-rewrite.t
   @@ -1412,10 +1412,58 @@ passed
    
    
    
   -=== TEST 48: rewrite HTTP method
   +=== TEST 48: rewrite HTTP method (GET to POST)
    --- request
    GET /hello
    --- response_body
   -method: POST
   +hello world
   +--- error_log eval
   +qr/changed HTTP method from GET to POST/
   +
   +
   +
   +=== TEST 49: set route(rewrite HTTP method)
   +--- config
   +    location /t {
   +        content_by_lua_block {
   +            local t = require("lib.test_admin").test
   +            local code, body = t('/apisix/admin/routes/1',
   +                 ngx.HTTP_PATCH,
   +                 [[{
   +                        "plugins": {
   +                            "proxy-rewrite": {
   +                                "method": "PUT"
   +                            }
   +                        },
   +                        "upstream": {
   +                            "nodes": {
   +                                "127.0.0.1:1980": 1
   +                            },
   +                            "type": "roundrobin"
   +                        },
   +                        "uri": "/hello"
   +                }]]
   +                )
   +
   +            if code >= 300 then
   +                ngx.status = code
   +            end
   +            ngx.say(body)
   +        }
   +    }
   +--- request
   +GET /t
   +--- response_body
   +passed
    --- no_error_log
    [error]
   +
   +
   +
   +=== TEST 50: rewrite HTTP method (GET to PUT)
   +--- request
   +GET /hello
   +--- response_body
   +hello world
   +--- error_log eval
   +qr/changed HTTP method from GET to PUT/
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to