You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by me...@apache.org on 2019/11/19 00:15:09 UTC
[incubator-apisix] branch master updated:
optimization(proxy-rewrite): performance upgrade for proxy-rewrite by avoid
luajit NYI (#872)
This is an automated email from the ASF dual-hosted git repository.
membphis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-apisix.git
The following commit(s) were added to refs/heads/master by this push:
new 722e42f optimization(proxy-rewrite): performance upgrade for proxy-rewrite by avoid luajit NYI (#872)
722e42f is described below
commit 722e42ffcc7557af04f6c02fe8e7d86271622ea6
Author: Lien <li...@users.noreply.github.com>
AuthorDate: Tue Nov 19 08:14:59 2019 +0800
optimization(proxy-rewrite): performance upgrade for proxy-rewrite by avoid luajit NYI (#872)
---
lua/apisix/plugins/proxy-rewrite.lua | 28 ++++++++++++++++++++++++----
1 file changed, 24 insertions(+), 4 deletions(-)
diff --git a/lua/apisix/plugins/proxy-rewrite.lua b/lua/apisix/plugins/proxy-rewrite.lua
index 0541a08..37abf95 100644
--- a/lua/apisix/plugins/proxy-rewrite.lua
+++ b/lua/apisix/plugins/proxy-rewrite.lua
@@ -18,6 +18,8 @@ local core = require("apisix.core")
local plugin_name = "proxy-rewrite"
local pairs = pairs
local ipairs = ipairs
+local ngx = ngx
+local type = type
local schema = {
@@ -67,6 +69,24 @@ function _M.check_schema(conf)
if not ok then
return false, err
end
+
+ --reform header from object into array, so can avoid use pairs, which is NYI
+ if conf.headers then
+ conf.headers_arr = {}
+
+ for field, value in pairs(conf.headers) do
+ if type(field) == 'string'
+ and (type(value) == 'string' or type(value) == 'number') then
+ if #field == 0 then
+ return false, 'invalid field length in header'
+ end
+ core.table.insert(conf.headers_arr, field)
+ core.table.insert(conf.headers_arr, value)
+ else
+ return false, 'invalid type as header value'
+ end
+ end
+ end
return true
end
@@ -102,10 +122,10 @@ function _M.rewrite(conf, ctx)
ctx.var.upstream_connection = ctx.var.http_connection
end
- -- TODO: support deleted header
- if conf.headers then
- for header_name, header_value in pairs(conf.headers) do
- core.request.set_header(header_name, header_value)
+ if conf.headers_arr then
+ local field_cnt = #conf.headers_arr
+ for i = 1, field_cnt, 2 do
+ ngx.req.set_header(conf.headers_arr[i], conf.headers_arr[i+1])
end
end
end