Changes to ngx.argnot getting reflected in final response

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
';

Debug Logs:

2014/06/27 22:51:34 [debug] 9059#0: *1 http output filter “/?”
2014/06/27 22:51:34 [debug] 9059#0: *1 http copy filter: “/?”
2014/06/27 22:51:34 [debug] 9059#0: *1 lua body filter for user lua
code,
uri “/”
2014/06/27 22:51:34 [debug] 9059#0: *1 lua fetching existing ngx.ctx
table
for the current request
2014/06/27 22:51:34 [debug] 9059#0: *1 lua fetching existing ngx.ctx
table
for the current request
2014/06/27 22:51:34 [debug] 9059#0: 1 lua compiling gsub regex
“href=”(.
)"" with options “i” (compile once: 0) (dfa mode: 0) (jit
mode:
0)
2014/06/27 22:51:34 [notice] 9059#0: *1 [lua] body_filter_by_lua:5:
href=“http://10.0.9.44/?redir=http%3a%2f%2fwww.google.co.in%2f%3fgfe_rd%3dcr%26amp%3bei%3dHqitU86qKubV8gfRzYDoAQ”
while sending to client, client: 10.0.9.44, server: 127.0.0.1, request:
“GET
/?redir=www.google.com HTTP/1.1”, upstream:
http://173.194.36.52:80/”,
host: “10.0.9.44”
2014/06/27 22:51:34 [debug] 9059#0: *1 lua allocate new chainlink and
new
buf of size 261, cl:086B49B0
2014/06/27 22:51:34 [notice] 9059#0: *1 [lua] body_filter_by_lua:26:

302 Moved

302 Moved

The document has moved here.^M ^M while sending to client, client: 10.0.9.44, server: 127.0.0.1, request: "GET /?_redir_=www.google.com HTTP/1.1", upstream: "http://173.194.36.52:80/", host: "10.0.9.44" 2014/06/27 22:51:34 [debug] 9059#0: *1 lua capture body filter, uri "/"

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

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,251248,251248#msg-251248

vamshi Wrote:

            end

            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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs