Skip to content

Commit

Permalink
change(proxy-rewrite): remove deprecated scheme (#7695)
Browse files Browse the repository at this point in the history
  • Loading branch information
tzssangglass authored Aug 17, 2022
1 parent d41d9df commit cd306f8
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 235 deletions.
8 changes: 0 additions & 8 deletions apisix/plugins/proxy-rewrite.lua
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,6 @@ local schema = {
type = "string",
pattern = [[^[0-9a-zA-Z-.]+(:\d{1,5})?$]],
},
scheme = {
description = "new scheme for upstream",
type = "string",
enum = {"http", "https"}
},
headers = {
description = "new headers for request",
type = "object",
Expand Down Expand Up @@ -161,9 +156,6 @@ function _M.rewrite(conf, ctx)
ctx.var[upstream_vars[name]] = conf[name]
end
end
if conf["scheme"] then
ctx.upstream_scheme = conf["scheme"]
end

local upstream_uri = ctx.var.uri
if conf.use_real_request_uri_unsafe then
Expand Down
2 changes: 0 additions & 2 deletions docs/en/latest/plugins/proxy-rewrite.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ The `proxy-rewrite` Plugin rewrites Upstream proxy information such as `scheme`,

| Name | Type | Required | Default | Valid values | Description |
|-----------------------------|---------------|----------|---------|----------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| scheme | string | False | "http" | ["http", "https"] | New upstream protocol scheme. This option is deprecated. Instead, it is recommended to set the `scheme` field in the Upstream. |
| uri | string | False | | | New Upstream forwarding address. Value supports [Nginx variables](https://nginx.org/en/docs/http/ngx_http_core_module.html). For example, `$arg_name`. |
| method | string | False | | ["GET", "POST", "PUT", "HEAD", "DELETE", "OPTIONS","MKCOL", "COPY", "MOVE", "PROPFIND", "PROPFIND","LOCK", "UNLOCK", "PATCH", "TRACE"] | Rewrites the HTTP method. |
| regex_uri | array[string] | False | | | New upstream forwarding address. Regular expressions can be used to match the URL from client. If it matches, the URL template is forwarded to the Upstream otherwise, the URL from the client is forwarded. When both `uri` and `regex_uri` are configured, `uri` is used first. For example, `[" ^/iresty/(.*)/(.*)/(.*)", "/$1-$2-$3"]`. Here, the first element is the regular expression to match and the second element is the URL template forwarded to the Upstream. |
Expand All @@ -55,7 +54,6 @@ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f1
"plugins": {
"proxy-rewrite": {
"uri": "/test/home.html",
"scheme": "http",
"host": "iresty.com",
"headers": {
"X-Api-Version": "v1",
Expand Down
2 changes: 0 additions & 2 deletions docs/en/latest/terminology/plugin-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ to a Route as shown below,
"plugins": {
"proxy-rewrite": {
"uri": "/test/add",
"scheme": "https",
"host": "apisix.iresty.com"
},
"limit-count": {
Expand Down Expand Up @@ -131,7 +130,6 @@ the effective configuration will be as the one shown below:
},
"proxy-rewrite": {
"uri": "/test/add",
"scheme": "https",
"host": "apisix.iresty.com"
},
"limit-count": {
Expand Down
2 changes: 0 additions & 2 deletions docs/zh/latest/architecture-design/plugin-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ $ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f
"plugins": {
"proxy-rewrite": {
"uri": "/test/add",
"scheme": "https",
"host": "apisix.iresty.com"
},
"limit-count": {
Expand Down Expand Up @@ -127,7 +126,6 @@ $ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f
},
"proxy-rewrite": {
"uri": "/test/add",
"scheme": "https",
"host": "apisix.iresty.com"
},
"limit-count": {
Expand Down
2 changes: 0 additions & 2 deletions docs/zh/latest/plugins/proxy-rewrite.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ description: 本文介绍了关于 Apache APISIX `proxy-rewrite` 插件的基本

| 名称 | 类型 | 必选项 | 默认值 | 有效值 | 描述 |
| --------- | ------------- | ----- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| scheme | string || "http" | ["http", "https"] | 不推荐使用。应该在 Upstream 的 `scheme` 字段设置上游的 `scheme`|
| uri | string || | | 转发到上游的新 `uri` 地址。支持 [NGINX variables](https://nginx.org/en/docs/http/ngx_http_core_module.html) 变量,例如:`$arg_name`|
| method | string || | ["GET", "POST", "PUT", "HEAD", "DELETE", "OPTIONS","MKCOL", "COPY", "MOVE", "PROPFIND", "PROPFIND","LOCK", "UNLOCK", "PATCH", "TRACE"] | 将路由的请求方法代理为该请求方法。 |
| regex_uri | array[string] || | | 转发到上游的新 `uri` 地址。使用正则表达式匹配来自客户端的 `uri`,如果匹配成功,则使用模板替换转发到上游的 `uri`,如果没有匹配成功,则将客户端请求的 `uri` 转发至上游。当同时配置 `uri``regex_uri` 属性时,优先使用 `uri`。例如:["^/iresty/(.*)/(.*)/(.*)","/$1-$2-$3"] 第一个元素代表匹配来自客户端请求的 `uri` 正则表达式,第二个元素代表匹配成功后转发到上游的 `uri` 模板。 |
Expand All @@ -55,7 +54,6 @@ curl http://127.0.0.1:9080/apisix/admin/routes/1 \
"plugins": {
"proxy-rewrite": {
"uri": "/test/home.html",
"scheme": "http",
"host": "iresty.com",
"headers": {
"X-Api-Version": "v1",
Expand Down
107 changes: 6 additions & 101 deletions t/node/https-proxy.t
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ run_tests;

__DATA__
=== TEST 1: add route to HTTPS upstream (old way)
=== TEST 1: add route to HTTPS upstream
--- config
location /t {
content_by_lua_block {
Expand All @@ -44,101 +44,6 @@ __DATA__
ngx.HTTP_PUT,
[[{
"methods": ["GET"],
"plugins": {
"proxy-rewrite": {
"scheme": "https"
}
},
"upstream": {
"type": "roundrobin",
"nodes": {
"127.0.0.1:1983": 1
}
},
"uri": "/hello"
}]]
)
if code >= 300 then
ngx.status = code
end
ngx.say(body)
}
}
--- request
GET /t
--- response_body
passed
=== TEST 2: hit the upstream (old way)
--- request
GET /hello
--- more_headers
host: www.sni.com
--- error_log
Receive SNI: www.sni.com
=== TEST 3: add route to HTTPS upstream
--- 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,
[[{
"methods": ["GET"],
"upstream": {
"scheme": "https",
"type": "roundrobin",
"nodes": {
"127.0.0.1:1983": 1
}
},
"uri": "/hello"
}]]
)
if code >= 300 then
ngx.status = code
end
ngx.say(body)
}
}
--- request
GET /t
--- response_body
passed
=== TEST 4: hit the upstream
--- request
GET /hello
--- more_headers
host: www.sni.com
--- error_log
Receive SNI: www.sni.com
=== TEST 5: add route to HTTPS upstream (mix)
--- 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,
[[{
"methods": ["GET"],
"plugins": {
"proxy-rewrite": {
"scheme": "https"
}
},
"upstream": {
"scheme": "https",
"type": "roundrobin",
Expand All @@ -163,7 +68,7 @@ passed
=== TEST 6: hit the upstream
=== TEST 2: hit the upstream
--- request
GET /hello
--- more_headers
Expand All @@ -173,7 +78,7 @@ Receive SNI: www.sni.com
=== TEST 7: use 443 as the default port
=== TEST 3: use 443 as the default port
--- apisix_yaml
routes:
-
Expand All @@ -192,7 +97,7 @@ upstream: "https://127.0.0.1:443/hello"
=== TEST 8: use 80 as the http's default port
=== TEST 4: use 80 as the http's default port
--- apisix_yaml
routes:
-
Expand All @@ -210,7 +115,7 @@ upstream: "http://127.0.0.1:80/hello"
=== TEST 9: rewrite SNI
=== TEST 5: rewrite SNI
--- log_level: debug
--- apisix_yaml
routes:
Expand All @@ -237,7 +142,7 @@ x-real-ip: 127.0.0.1
=== TEST 10: node's SNI
=== TEST 6: node's SNI
--- log_level: debug
--- apisix_yaml
routes:
Expand Down
9 changes: 5 additions & 4 deletions t/node/merge-route.t
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ qr/merge_service_route.*"time_window":60/]
ngx.HTTP_PUT,
[[{
"upstream": {
"scheme": "https",
"type": "roundrobin",
"nodes": {
"httpbin.org:443": 1
Expand Down Expand Up @@ -280,11 +281,11 @@ passed
local code, body = t('/apisix/admin/routes/1',
ngx.HTTP_PUT,
[[{
"uri": "/get",
"uri": "/fake",
"host": "httpbin.org",
"plugins": {
"proxy-rewrite": {
"scheme": "https"
"uri": "/get"
}
},
"service_id": "1"
Expand All @@ -308,7 +309,7 @@ passed

=== TEST 12: hit route
--- request
GET /get
GET /fake
--- more_headers
host: httpbin.org
--- response_body eval
Expand All @@ -321,7 +322,7 @@ qr/"Host": "httpbin.org"/

=== TEST 13: not hit route
--- request
GET /get
GET /fake
--- more_headers
host: httpbin.orgxxx
--- error_code: 404
Expand Down
Loading

0 comments on commit cd306f8

Please sign in to comment.