Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug(proxy-rewrite): uri safe encode. #1461

Merged
merged 1 commit into from
Apr 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions apisix/core/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,22 @@ local table = require("apisix.core.table")
local ngx_re = require("ngx.re")
local resolver = require("resty.dns.resolver")
local ipmatcher= require("resty.ipmatcher")
local ffi = require("ffi")
local base = require("resty.core.base")
local open = io.open
local math = math
local sub_str = string.sub
local str_byte = string.byte
local tonumber = tonumber
local C = ffi.C
local ffi_string = ffi.string
local get_string_buf = base.get_string_buf


ffi.cdef[[
int ngx_escape_uri(char *dst, const char *src,
size_t size, int type);
]]


local _M = {
Expand Down Expand Up @@ -144,4 +155,14 @@ function _M.parse_addr(addr)
end


function _M.uri_safe_encode(uri)
local count_escaped = C.ngx_escape_uri(nil, uri, #uri, 0)
local len = #uri + 2 * count_escaped
local buf = get_string_buf(len)
C.ngx_escape_uri(buf, uri, #uri, 0)

return ffi_string(buf, len)
end


return _M
2 changes: 2 additions & 0 deletions apisix/plugins/proxy-rewrite.lua
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ function _M.rewrite(conf, ctx)
end
end

upstream_uri = core.utils.uri_safe_encode(upstream_uri)

if ctx.var.is_args == "?" then
ctx.var.upstream_uri = upstream_uri .. "?" .. (ctx.var.args or "")
else
Expand Down