liuhengloveyou commented on a change in pull request #2311:
URL: https://github.com/apache/apisix/pull/2311#discussion_r494811432



##########
File path: apisix/plugins/redirect.lua
##########
@@ -133,7 +135,11 @@ function _M.rewrite(conf, ctx)
         -- TODO: add test case
         -- PR: https://github.com/apache/apisix/pull/1958
         uri = "https://$host$request_uri";
-        ret_code = 301
+        if ngx.req.get_method() == http_post then
+            ret_code = 308
+        else
+            ret_code = 301
+        end

Review comment:
       User's configuration priority
   
   `
   if not ret_code or ret_code == 302 then
               if ngx.req.get_method() == "POST" then
                   ret_code = 308
               else
                   ret_code = 301
               end
           end
   `

##########
File path: apisix/plugins/redirect.lua
##########
@@ -133,7 +135,11 @@ function _M.rewrite(conf, ctx)
         -- TODO: add test case
         -- PR: https://github.com/apache/apisix/pull/1958
         uri = "https://$host$request_uri";
-        ret_code = 301
+        if ngx.req.get_method() == http_post then
+            ret_code = 308
+        else
+            ret_code = 301
+        end

Review comment:
       User's configuration priority
   
   `
   if not ret_code or ret_code == 302 then
   
               if ngx.req.get_method() == "POST" then
   
                   ret_code = 308
   
               else
   
                   ret_code = 301
   
               end
   
           end
   `

##########
File path: apisix/plugins/redirect.lua
##########
@@ -133,7 +135,11 @@ function _M.rewrite(conf, ctx)
         -- TODO: add test case
         -- PR: https://github.com/apache/apisix/pull/1958
         uri = "https://$host$request_uri";
-        ret_code = 301
+        if ngx.req.get_method() == http_post then
+            ret_code = 308
+        else
+            ret_code = 301
+        end

Review comment:
       User's configuration priority
   
   `
       if not ret_code or ret_code == 302 then
               if ngx.req.get_method() == "POST" then
                   ret_code = 308
               else
                   ret_code = 301
               end
           end
   `

##########
File path: apisix/plugins/redirect.lua
##########
@@ -133,7 +135,11 @@ function _M.rewrite(conf, ctx)
         -- TODO: add test case
         -- PR: https://github.com/apache/apisix/pull/1958
         uri = "https://$host$request_uri";
-        ret_code = 301
+        if ngx.req.get_method() == http_post then
+            ret_code = 308
+        else
+            ret_code = 301
+        end

Review comment:
       User's configuration priority
   
   `
          if not ret_code or ret_code == 302 then
   
               if ngx.req.get_method() == "POST" then
   
                   ret_code = 308
   
               else
   
                   ret_code = 301
   
               end
   
           end
   `

##########
File path: apisix/plugins/redirect.lua
##########
@@ -133,7 +135,11 @@ function _M.rewrite(conf, ctx)
         -- TODO: add test case
         -- PR: https://github.com/apache/apisix/pull/1958
         uri = "https://$host$request_uri";
-        ret_code = 301
+        if ngx.req.get_method() == http_post then
+            ret_code = 308
+        else
+            ret_code = 301
+        end

Review comment:
       The user's configuration should take precedence. like this:
   
           if not ret_code or ret_code == 302 then
               if ngx.req.get_method() == "POST" then
                   ret_code = 308
               else
                   ret_code = 301
               end
           end

##########
File path: t/plugin/redirect.t
##########
@@ -676,3 +676,51 @@ close: 1 nil}
 --- no_error_log
 [error]
 [alert]
+
+
+
+=== TEST 26: add plugin with new uri: /test/add
+--- config
+    location /t {
+        content_by_lua_block {
+            local t = require("lib.test_admin").test
+            local code, body = t('/apisix/admin/routes/1',
+                ngx.HTTP_PUT,
+                [[{
+                    "plugins": {
+                        "redirect": {
+                            "http_to_https": true,
+                            "ret_code": 307
+                        }
+                    },
+                    "methods":["POST"],
+                    "host": "test.com",
+                    "uri": "/hello-https"
+                }]]
+                )
+
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 27: redirect
+--- request
+POST /hello-https
+--- more_headers
+Host: test.com
+--- response_headers
+Location: https://test.com/hello-https
+--- error_code: 308
+--- no_error_log
+[error]

Review comment:
       When the user has a configuration, the value of the user configuration 
should be returned

##########
File path: apisix/plugins/redirect.lua
##########
@@ -133,7 +135,11 @@ function _M.rewrite(conf, ctx)
         -- TODO: add test case
         -- PR: https://github.com/apache/apisix/pull/1958
         uri = "https://$host$request_uri";
-        ret_code = 301
+        if ngx.req.get_method() == http_post then
+            ret_code = 308
+        else
+            ret_code = 301
+        end

Review comment:
       I think,,,user can choose not to configure it。If the user's 
configuration is wrong, should get the wrong result,
   not be ignored。
   The role of the user's configuration should be very definite.




----------------------------------------------------------------
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