Welcome! Log In Create A New Profile

Advanced

Re: changes to ngx.arg[1] not getting reflected in final response

July 01, 2014 07:45PM
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
Subject Author Posted

changes to ngx.arg[1] not getting reflected in final response

vamshi June 27, 2014 01:34PM

Re: changes to ngx.arg[1] not getting reflected in final response

jdewald July 01, 2014 07:45PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 288
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready