Permalink
Browse files

fixed issues for HEAD requests.

  • Loading branch information...
1 parent a1aae4b commit c2cbbeac2f296bcb4ae327383fc65f585b839953 @agentzh agentzh committed Sep 1, 2011
Showing with 40 additions and 3 deletions.
  1. +9 −1 src/ngx_http_lua_util.c
  2. +2 −1 t/000-sanity.t
  3. +29 −1 t/002-content.t
View
@@ -334,9 +334,13 @@ ngx_http_lua_send_chain_link(ngx_http_request_t *r, ngx_http_lua_ctx_t *ctx,
}
#endif
+ if (!r->header_only && (r->method & NGX_HTTP_HEAD)) {
+ r->header_only = 1;
+ }
+
rc = ngx_http_lua_send_header_if_needed(r, ctx);
- if (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE) {
+ if (rc == NGX_ERROR || rc > NGX_OK) {
return rc;
}
@@ -426,6 +430,10 @@ ngx_http_lua_send_http10_headers(ngx_http_request_t *r,
ctx->headers_sent = 1;
+ if (r->header_only) {
+ return ngx_http_send_header(r);
+ }
+
if (r->headers_out.content_length == NULL) {
for (size = 0, cl = ctx->out; cl; cl = cl->next) {
size += ngx_buf_size(cl->buf);
View
@@ -1,4 +1,5 @@
-# vim:set ft=perl ts=4 sw=4 et fdm=marker:
+# vim:set ft= ts=4 sw=4 et fdm=marker:
+
use lib 'lib';
use Test::Nginx::Socket;
View
@@ -10,7 +10,7 @@ use Test::Nginx::Socket;
repeat_each(2);
#repeat_each(1);
-plan tests => repeat_each() * (blocks() * 2 + 2);
+plan tests => repeat_each() * (blocks() * 2 + 3);
#no_diff();
#no_long_string();
@@ -570,3 +570,31 @@ GET /main
5
1
+
+
+=== TEST 31: basic print (HEAD + HTTP 1.1)
+--- config
+ location /lua {
+ # NOTE: the newline escape sequence must be double-escaped, as nginx config
+ # parser will unescape first!
+ content_by_lua 'ngx.print("Hello, Lua!\\n")';
+ }
+--- request
+HEAD /lua
+--- response_body
+
+
+
+=== TEST 32: basic print (HEAD + HTTP 1.0)
+--- config
+ location /lua {
+ # NOTE: the newline escape sequence must be double-escaped, as nginx config
+ # parser will unescape first!
+ content_by_lua 'ngx.print("Hello, Lua!\\n")';
+ }
+--- request
+HEAD /lua HTTP/1.0
+--- response_headers
+!Content-Length
+--- response_body
+

0 comments on commit c2cbbea

Please sign in to comment.