Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

now for HTTP 1.0 requests, we disable the automatic full buffering mo…

…de if the user sets the Content-Length response header before sending out the headers. this allows streamming output for HTTP 1.0 requests if the content length can be calculated beforehand. thanks 李子义.
  • Loading branch information...
commit 3cbf39f3aa1eee37b3585246d8d144b08f92a7f7 1 parent 752be5d
@agentzh agentzh authored
Showing with 36 additions and 6 deletions.
  1. +5 −4 src/ngx_http_lua_util.c
  2. +30 −1 t/002-content.t
  3. +1 −1  t/042-crc32.t
View
9 src/ngx_http_lua_util.c
@@ -315,7 +315,7 @@ ngx_http_lua_send_header_if_needed(ngx_http_request_t *r,
ngx_http_clear_accept_ranges(r);
}
- if (r->http_version >= NGX_HTTP_VERSION_11) {
+ if (r->http_version >= NGX_HTTP_VERSION_11 || r->headers_out.content_length) {
/* Send response headers for HTTP version <= 1.0 elsewhere */
dd("sending headers");
rc = ngx_http_send_header(r);
@@ -356,7 +356,8 @@ ngx_http_lua_send_chain_link(ngx_http_request_t *r, ngx_http_lua_ctx_t *ctx,
if (r->header_only) {
ctx->eof = 1;
- if (r->http_version < NGX_HTTP_VERSION_11) {
+ if (!ctx->headers_sent && r->http_version < NGX_HTTP_VERSION_11)
+ {
return ngx_http_lua_send_http10_headers(r, ctx);
}
@@ -364,7 +365,7 @@ ngx_http_lua_send_chain_link(ngx_http_request_t *r, ngx_http_lua_ctx_t *ctx,
}
if (in == NULL) {
- if (r->http_version < NGX_HTTP_VERSION_11) {
+ if (!ctx->headers_sent && r->http_version < NGX_HTTP_VERSION_11) {
rc = ngx_http_lua_send_http10_headers(r, ctx);
if (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE) {
return rc;
@@ -589,7 +590,7 @@ ngx_http_lua_add_copy_chain(ngx_http_request_t *r, ngx_http_lua_ctx_t *ctx,
b->last = b->pos;
b->memory = 1;
-#if 0
+#if 1
b->tag = (ngx_buf_tag_t) &ngx_http_lua_module;
#endif
View
31 t/002-content.t
@@ -10,7 +10,7 @@ use Test::Nginx::Socket;
repeat_each(2);
#repeat_each(1);
-plan tests => repeat_each() * (blocks() * 2 + 3);
+plan tests => repeat_each() * (blocks() * 2 + 4);
#no_diff();
#no_long_string();
@@ -633,3 +633,32 @@ false
true
true
+
+
+=== TEST 35: HTTP 1.0 response with Content-Length
+--- config
+ location /lua {
+ content_by_lua '
+ data = "hello,\\nworld\\n"
+ -- ngx.header["Content-Length"] = #data
+ ngx.say("hello,")
+ ngx.flush()
+ -- ngx.location.capture("/sleep")
+ ngx.say("world")
+ ';
+ }
+ location /sleep {
+ echo_sleep 2;
+ }
+ location /main {
+ proxy_pass http://127.0.0.1:$server_port/lua;
+ }
+--- request
+GET /main
+--- response_headers
+Content-Length: 13
+--- response_body
+hello,
+world
+--- timeout: 5
+
View
2  t/042-crc32.t
@@ -44,7 +44,7 @@ GET /test
-=== TEST 2: long sanity (empty)
+=== TEST 3: long sanity (empty)
--- config
location = /test {
content_by_lua '
Please sign in to comment.
Something went wrong with that request. Please try again.