]> git.kaiwu.me - nginx.git/commitdiff
Merging r3986, r4006, r4007, r4073:
authorIgor Sysoev <igor@sysoev.ru>
Fri, 30 Sep 2011 14:36:19 +0000 (14:36 +0000)
committerIgor Sysoev <igor@sysoev.ru>
Fri, 30 Sep 2011 14:36:19 +0000 (14:36 +0000)
Request body related fixes:

*) Always set timer in discard body handler, this fixes the cases
when request for static file is redirected by error_page to an SSI page.

*) Correctly set body if it's preread and there are extra data.

Previously all available data was used as body, resulting in garbage after
real body e.g. in case of pipelined requests.  Make sure to use only as many
bytes as request's Content-Length specifies.

*) Fix body with request_body_in_single_buf.

If there were preread data and request body was big enough first part
of the request body was duplicated.

See report here:
http://mailman.nginx.org/pipermail/nginx/2011-July/027756.html

*) Bugfix: read event was not blocked after reading body.

Read event should be blocked after reading body, else undefined behaviour
might occur on additional client activity.  This fixes segmentation faults
observed with proxy_ignore_client_abort set.

src/http/ngx_http_request.c
src/http/ngx_http_request_body.c

index d11b13e4addd9cc4aa25155168e1ed9e6ae52e69..5e0b8e8915e27349ceeb77af28c306f94e16dffa 100644 (file)
@@ -2123,11 +2123,11 @@ ngx_http_finalize_connection(ngx_http_request_t *r)
 
         if (r->discard_body) {
             r->read_event_handler = ngx_http_discarded_request_body_handler;
+            ngx_add_timer(r->connection->read, clcf->lingering_timeout);
 
             if (r->lingering_time == 0) {
                 r->lingering_time = ngx_time()
                                       + (time_t) (clcf->lingering_time / 1000);
-                ngx_add_timer(r->connection->read, clcf->lingering_timeout);
             }
         }
 
index be311a6129f7c75c485d00d5db34c3269238620c..817b48e4555780e6992b77aa22bea15f11d0f8a6 100644 (file)
@@ -143,6 +143,7 @@ ngx_http_read_client_request_body(ngx_http_request_t *r,
 
             r->header_in->pos += (size_t) r->headers_in.content_length_n;
             r->request_length += r->headers_in.content_length_n;
+            b->last = r->header_in->pos;
 
             if (r->request_body_in_file_only) {
                 if (ngx_http_write_request_body(r, rb->bufs) != NGX_OK) {
@@ -371,10 +372,14 @@ ngx_http_do_read_client_request_body(ngx_http_request_t *r)
         }
     }
 
-    if (r->request_body_in_file_only && rb->bufs->next) {
+    if (rb->bufs->next
+        && (r->request_body_in_file_only || r->request_body_in_single_buf))
+    {
         rb->bufs = rb->bufs->next;
     }
 
+    r->read_event_handler = ngx_http_block_reading;
+
     rb->post_handler(r);
 
     return NGX_OK;