Skip to content

Commit

Permalink
support args for rewrite plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
sumory committed Jun 14, 2016
1 parent 99a514f commit 85399d1
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions orange/plugins/rewrite/handler.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
local pairs = pairs
local ipairs = ipairs
local ngx_re_sub = ngx.re.sub
local ngx_re_find = ngx.re.find
local string_len = string.len
local string_sub = string.sub
local orange_db = require("orange.store.orange_db")
local judge_util = require("orange.utils.judge")
local extractor_util = require("orange.utils.extractor")
Expand Down Expand Up @@ -35,6 +38,8 @@ function RewriteHandler:rewrite(conf)

local ngx_var_uri = ngx.var.uri
local ngx_set_uri = ngx.req.set_uri
local ngx_set_uri_args = ngx.req.set_uri_args
local ngx_decode_args = ngx.decode_args

local rules = rewrite_config.rules
if not rules or type(rules) ~= "table" or #rules<=0 then
Expand Down Expand Up @@ -76,6 +81,18 @@ function RewriteHandler:rewrite(conf)
ngx.log(ngx.ERR, "[Rewrite] ", ngx_var_uri, " to:", to_rewrite)
end

local from, to, err = ngx_re_find(to_rewrite, "[%?]{1}", "jo")
if not err and from and from >= 1 then
--local qs = ngx_re_sub(to_rewrite, "[A-Z0-9a-z-_/]*[%?]{1}", "", "jo")
local qs = string_sub(to_rewrite, from+1)
if qs then
local args = ngx_decode_args(qs, 0)
if args then
ngx_set_uri_args(args)
end
end
end

ngx_set_uri(to_rewrite, true)
end
end
Expand Down

0 comments on commit 85399d1

Please sign in to comment.