changes to ngx.arg[1] not getting reflected in final response
jdewald
nginx-forum at nginx.us
Tue Jul 1 23:45:58 UTC 2014
vamshi Wrote:
-------------------------------------------------------
> header_filter_by_lua '
> ngx.header.content_length = nil
> ngx.header.set_cookie = nil
>
> if ngx.header.location then
> local _location = ngx.header.location
> _location = ngx.escape_uri(_location)
> _location = "http://10.0.9.44/?_redir_=" ..
> _location
> ngx.header.location = _location
> end
> ';
>
> body_filter_by_lua '
>
> local escUri = function (m)
> local _esc = "href=\\"http://10.0.9.44/?_redir_="
> .. ngx.escape_uri(m[1]) .. "\\""
> print(_esc)
> return _esc
> end
>
> local chunk, eof = ngx.arg[1], ngx.arg[2]
> local buffered = ngx.ctx.buffered
> if not buffered then
> buffered = {}
> ngx.ctx.buffered = buffered
> end
>
> if chunk ~= "" then
> buffered[#buffered + 1] = chunk
> ngx.arg[1] = nil
> end
>
> if eof then
> local whole = table.concat(buffered)
> ngx.ctx.buffered = nil
> local newStr, n, err = ngx.re.gsub(whole,
> "href=\\"(.*)\\"", escUri, "i")
> ngx.arg[1] = whole
> print(whole)
> end
> ';
> ...
>
>
> As you can see, print(_esc) show that the URL was successfully
> URLencoded. Yet, the print(whole) line does not reflect the gsub()
>
> What could be issue here ?
>
> -Vamshi
gsub is going to return the results of the substitution, not do it inline.
You should be outputting/assigning newStr not whole.
Cheers,
Josh
Posted at Nginx Forum: http://forum.nginx.org/read.php?2,251248,251425#msg-251425
More information about the nginx
mailing list