Hello!
On Fri, Aug 3, 2012 at 8:36 AM, Nginx User wrote:
> Got another issue. Can you help?
>
> Here is the test case:
> location /test/some_string {
> rewrite ^/test/path/(.+)/index.html$ /test/index.php?some_param=$1 last;
> try_files $uri $uri/ @proxy;
> }
> location @proxy {
> rewrite_by_lua '
> local args = ngx.req.get_uri_args()
> for key, val in pairs(args) do
> if ngx.re.match(key, "some_param", "io") then
> if ngx.re.match(val, "some_string/", "io") then
> return ngx.exit(204)
> end
> end
> end
> ';
> }
>
>
> Here is the header received:
> Request URL:http://www.example.com/test/path/some_string/index.html
> Request Method:GET
> Status Code:200 OK
> Request Headersview source
> Accept:text/plain, */*; q=0.01
> Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
> Accept-Encoding:gzip,deflate,sdch
> Accept-Language:en-US,en;q=0.8
> Cache-Control:max-age=0
> Connection:keep-alive
> Host:www.example.com
> Referer:http://www.example.com/test/index.html
> User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_5_8)
> AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.47
> Safari/536.11
> X-Moz:prefetch
> X-Requested-With:XMLHttpRequest
> Response Headersview source
> Connection:Keep-Alive
> Content-Type:application/octet-stream
> Date:Fri, 03 Aug 2012 15:08:14 GMT
> Server:nginx
> Transfer-Encoding:chunked
> X-UA-Compatible:chrome=1
>
>
> Basically, I wanted it to terminate the whole process with a "204 no
> content" header
> The wiki says "When status >= 200 (i.e., ngx.HTTP_OK and above), it
> will interrupt the execution of the current request and return status
> code to nginx."
> I notice the 204 header is sent but it proceeds to send a "200 OK"
This is indeed a bug. I've just committed a patch to the git repository:
https://github.com/chaoslawful/lua-nginx-module/commit/d577a38
Please try out ngx_lua v0.5.12rc1 on your side:
https://github.com/chaoslawful/lua-nginx-module/tags/
or you can just try out the latest prerelease of ngx_openresty that
already includes this version of ngx_lua:
http://agentzh.org/misc/nginx/ngx_openresty-1.2.1.11rc1.tar.gz
BTW, I've cc'd the openresty mailing list:
http://groups.google.com/group/openresty You're very welcome to join
there too :)
Thanks!
-agentzh
> (See Log Below)
>
> 2012/08/03 11:08:14 [debug] 31575#0: *6 http upstream send request handler
> 2012/08/03 11:08:14 [debug] 31575#0: *6 http upstream send request
> 2012/08/03 11:08:14 [debug] 31575#0: *6 chain writer buf fl:1 s:590
> 2012/08/03 11:08:14 [debug] 31575#0: *6 chain writer in: 0926EC68
> 2012/08/03 11:08:14 [debug] 31575#0: *6 writev: 590
> 2012/08/03 11:08:14 [debug] 31575#0: *6 chain writer out: 00000000
> 2012/08/03 11:08:14 [debug] 31575#0: *6 event timer del: 17: 3976788450
> 2012/08/03 11:08:14 [debug] 31575#0: *6 event timer add: 17: 90000:3976788450
> 2012/08/03 11:08:14 [debug] 31575#0: *9 event timer del: 19: 3976772650
> 2012/08/03 11:08:14 [debug] 31575#0: *9 rewrite phase: 0
> 2012/08/03 11:08:14 [debug] 31575#0: *9 test location: "/path/some_string"
> 2012/08/03 11:08:14 [debug] 31575#0: *9 test location: ~ ".+\.php$"
> 2012/08/03 11:08:14 [debug] 31575#0: *9 test location: ~ "^/display(.*)$"
> 2012/08/03 11:08:14 [debug] 31575#0: *9 test location: ~ "/test/path(/?)$"
> 2012/08/03 11:08:14 [debug] 31575#0: *9 test location: ~ "/\.(.*)$"
> 2012/08/03 11:08:14 [debug] 31575#0: *9 test location: ~ "^/proxy_purge(.*)"
> 2012/08/03 11:08:14 [debug] 31575#0: *9 using configuration
> "/test/path/some_string"
> 2012/08/03 11:08:14 [debug] 31575#0: *9 http cl:-1 max:8388608
> 2012/08/03 11:08:14 [debug] 31575#0: *9 rewrite phase: 2
> 2012/08/03 11:08:14 [debug] 31575#0: *9 http script regex: "^/test/path/(.+)/$"
> 2012/08/03 11:08:14 [notice] 31575#0: *9 "^/test/path/(.+)/$" does not
> match "/test/path/some_string/index.html", client: 84.255.142.124,
> server: www.example.com, request: "GET
> /test/path/some_string/index.html HTTP/1.1", host: "www.example.com",
> referrer: "http://www.example.com/test/index.html"
> 2012/08/03 11:08:14 [debug] 31575#0: *9 http script regex:
> "^/test/path/(.+)index\.html$"
> 2012/08/03 11:08:14 [notice] 31575#0: *9
> "^/test/path/(.+)index\.html$" matches
> "/test/path/some_string/index.html", client: 84.255.142.124, server:
> www.example.com, request: "GET /test/path/some_string/index.html
> HTTP/1.1", host: "www.example.com", referrer:
> "http://www.example.com/test/index.html"
> 2012/08/03 11:08:14 [debug] 31575#0: *9 http script copy: "/test/index.php"
> 2012/08/03 11:08:14 [debug] 31575#0: *9 http script args
> 2012/08/03 11:08:14 [debug] 31575#0: *9 http script copy: "some_param="
> 2012/08/03 11:08:14 [debug] 31575#0: *9 http script capture: "some_string/"
> 2012/08/03 11:08:14 [debug] 31575#0: *9 http script regex end
> 2012/08/03 11:08:14 [notice] 31575#0: *9 rewritten data:
> "/test/index.php", args: "some_param=some_string/", client:
> 84.255.142.124, server: www.example.com, request: "GET
> /test/path/some_string/index.html HTTP/1.1", host: "www.example.com",
> referrer: "http://www.example.com/test/index.html"
> 2012/08/03 11:08:14 [debug] 31575#0: *9 rewrite phase: 3
> 2012/08/03 11:08:14 [debug] 31575#0: *9 post rewrite phase: 4
> 2012/08/03 11:08:14 [debug] 31575#0: *9 uri changes: 11
> 2012/08/03 11:08:14 [debug] 31575#0: *9 test location: "/static"
> 2012/08/03 11:08:14 [debug] 31575#0: *9 test location: "/outlet/admin"
> 2012/08/03 11:08:14 [debug] 31575#0: *9 test location: ~ "/\.ht"
> 2012/08/03 11:08:14 [debug] 31575#0: *9 test location: ~
> "(?:\.(inc|class|tpl)$)"
> 2012/08/03 11:08:14 [debug] 31575#0: *9 test location: ~ "^/test/$"
> 2012/08/03 11:08:14 [debug] 31575#0: *9 test location: ~ ".+\.php$"
> 2012/08/03 11:08:14 [debug] 31575#0: *9 test location: ~ "\..*/.*\.php$"
> 2012/08/03 11:08:14 [debug] 31575#0: *9 test location: ~ "^/test/main\.php$"
> 2012/08/03 11:08:14 [debug] 31575#0: *9 using configuration ".+\.php$"
> 2012/08/03 11:08:14 [debug] 31575#0: *9 http cl:-1 max:8388608
> 2012/08/03 11:08:14 [debug] 31575#0: *9 rewrite phase: 2
> 2012/08/03 11:08:14 [debug] 31575#0: *9 rewrite phase: 3
> 2012/08/03 11:08:14 [debug] 31575#0: *9 lua rewrite handler, uri
> "/test/index.php"
> 2012/08/03 11:08:14 [debug] 31575#0: *9 lua creating new thread
> 2012/08/03 11:08:14 [debug] 31575#0: *9 lua reset ctx
> 2012/08/03 11:08:14 [debug] 31575#0: *9 http cleanup add: 09260B60
> 2012/08/03 11:08:14 [debug] 31575#0: *9 lua run thread
> 2012/08/03 11:08:14 [debug] 31575#0: *9 lua exec "@proxy?"
> 2012/08/03 11:08:14 [debug] 31575#0: *9 lua resume returned 1
> 2012/08/03 11:08:14 [debug] 31575#0: *9 lua thread yielded
> 2012/08/03 11:08:14 [debug] 31575#0: *9 lua thread initiated internal
> redirect to @proxy
> 2012/08/03 11:08:14 [debug] 31575#0: *9 lua deleting thread
> 2012/08/03 11:08:14 [debug] 31575#0: *9 lua request cleanup
> 2012/08/03 11:08:14 [debug] 31575#0: *9 test location: "@proxy"
> 2012/08/03 11:08:14 [debug] 31575#0: *9 using location: @proxy
> "/test/index.php?some_param=some_string/"
> 2012/08/03 11:08:14 [debug] 31575#0: *9 rewrite phase: 2
> 2012/08/03 11:08:14 [debug] 31575#0: *9 http script var
> 2012/08/03 11:08:14 [debug] 31575#0: *9 http geo started: 84.255.142.124
> 2012/08/03 11:08:14 [debug] 31575#0: *9 http geo: 0
> 2012/08/03 11:08:14 [debug] 31575#0: *9 http script var: "0"
> 2012/08/03 11:08:14 [debug] 31575#0: *9 http script value: "1"
> 2012/08/03 11:08:14 [debug] 31575#0: *9 http script equal
> 2012/08/03 11:08:14 [debug] 31575#0: *9 http script equal: no
> 2012/08/03 11:08:14 [debug] 31575#0: *9 http script if
> 2012/08/03 11:08:14 [debug] 31575#0: *9 http script if: false
> 2012/08/03 11:08:14 [debug] 31575#0: *9 http cleanup add: 09260C84
> 2012/08/03 11:08:14 [debug] 31575#0: *9 http script value (post filter): "1"
> 2012/08/03 11:08:14 [debug] 31575#0: *9 http script set $no_cache
> 2012/08/03 11:08:14 [debug] 31575#0: *9 rewrite phase: 3
> 2012/08/03 11:08:14 [debug] 31575#0: *9 lua rewrite handler, uri
> "/test/index.php"
> 2012/08/03 11:08:14 [debug] 31575#0: *9 lua creating new thread
> 2012/08/03 11:08:14 [debug] 31575#0: *9 lua reset ctx
> 2012/08/03 11:08:14 [debug] 31575#0: *9 lua run thread
> 2012/08/03 11:08:14 [debug] 31575#0: *9 lua regex cache hit for match
> regex "some_param" with options "io"
> 2012/08/03 11:08:14 [debug] 31575#0: *9 lua regex cache hit for match
> regex "some_string/" with options "io"
> 2012/08/03 11:08:14 [debug] 31575#0: *9 lua exit with code 204
> 2012/08/03 11:08:14 [debug] 31575#0: *9 lua resume returned 1
> 2012/08/03 11:08:14 [debug] 31575#0: *9 lua thread yielded
> 2012/08/03 11:08:14 [debug] 31575#0: *9 lua thread aborting request
> with status 204
> 2012/08/03 11:08:14 [debug] 31575#0: *9 lua deleting thread
> 2012/08/03 11:08:14 [debug] 31575#0: *9 lua request cleanup
> 2012/08/03 11:08:14 [debug] 31575#0: *9 headers more header filter,
> uri "/test/index.php"
> 2012/08/03 11:08:14 [debug] 31575#0: *9 lua capture header filter, uri
> "/test/index.php"
> 2012/08/03 11:08:14 [debug] 31575#0: *9 HTTP/1.1 200 OK
> Server: nginx
> Date: Fri, 03 Aug 2012 15:08:14 GMT
> Content-Type: application/octet-stream
> Transfer-Encoding: chunked
> Connection: keep-alive
> X-UA-Compatible: chrome=1