bug: http_to_https ret_code 307 not working
Issue description
Environment
- apisix version (cmd:
apisix version):1.5 - OS:ubuntu16.04
i use plugin http_to_https and set ret_code 307, like below.
{
"priority": 0,
"plugins": {
"redirect": {
"ret_code": 307,
"http_to_https": true
}
},
"uris": [
"/*"
],
"id": "1a5f4337d",
"hosts": [
"demo-apisix.xxxxxxx.com"
],
"upstream": {
"nodes": {
"172.16.3.2:80": 100
},
"hash_on": "vars",
"type": "roundrobin"
}
}
when client sends POST reqeust with http.it's not working, apisix should return 307 and client sends a new request with https again, in fact, apisix return 301 and client sends a new request with https and the method is GET

启用http跳转https后,设置状态码为307不生效. etcd中存储的状态码是307,但是实际跳转的时候是301,导致原本POST的method在301跳转后变为GET
that is a bug. here is the test case. welcome PR to fix it
=== TEST 1: 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
}
},
"uri": "/hello"
}]]
)
if code >= 300 then
ngx.status = code
end
ngx.say(body)
}
}
--- request
GET /t
--- response_body
passed
--- no_error_log
[error]
=== TEST 2: redirect
--- request
GET /hello
--- response_headers
Location: /test/add
--- error_code: 307
--- no_error_log
[error]
@liuhengloveyou please take a look
I thinks when we send redirect to 301 ,some browser default change the request to get, so we should add some logical to handle post request , when the request is post we should send the ret_code to 307, according to https://github.com/apache/apisix/blob/master/apisix/plugins/redirect.lua#L136
If the user has explicitly configured ret_code, we should not change it.
Unless the configuration is wrong, we should indicate the range in the documentation.
I think the range of should be 400 > ret_code >= 300?
@gy09535 I think you mean 308 but not 307: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/308 Code 307 is 'Temporary'.
@gy09535 I think you mean 308 but not 307: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/308 Code 307 is 'Temporary'.
yeah, should be 308