Skip to content

Commit 39e4d53

Browse files
author
Brice Figureau
committed
fix masterzen#36 - nginx reduces rquest_body->rest only on buffer recycling
Since nginx 1.3.9, the request body handler is able to decode chunked encoding. This feature changed the behavior of the request body handler, whereas before the request_body->rest was decremented on each call to recv and the upload progress module was showing the correct rest decrement. Now, request_body->rest is only decremented when the incoming body buffer is reused. If this buffer is large (it's size depends on client_body_buffer_size), then it can never be reused, thus the rest field is never decremented until the end of the file. This hasn't been detected and reproduced before, because I happen to run the tests with small client_body_buffer_size (ie less than 10% from the file uploaded). The solution is to never use rest, but compute the correct rest by tracking the current buffer size. Signed-off-by: Brice Figureau <[email protected]>
1 parent 4b7a2c9 commit 39e4d53

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

ngx_http_uploadprogress_module.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,9 @@ static void ngx_http_uploadprogress_event_handler(ngx_http_request_t *r)
462462
ngx_http_uploadprogress_node_t *up;
463463
ngx_http_uploadprogress_conf_t *upcf;
464464
ngx_http_uploadprogress_module_ctx_t *module_ctx;
465+
size_t size;
466+
off_t rest;
467+
465468

466469
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "upload-progress: ngx_http_uploadprogress_event_handler");
467470

@@ -517,7 +520,15 @@ static void ngx_http_uploadprogress_event_handler(ngx_http_request_t *r)
517520
if (up != NULL && !up->done) {
518521
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0,
519522
"upload-progress: read_event_handler found node: %V", id);
520-
up->rest = r->request_body->rest;
523+
rest = r->request_body->rest;
524+
size = r->request_body->buf->last - r->request_body->buf->pos;
525+
if ((off_t) size < rest) {
526+
rest -= size;
527+
} else {
528+
rest = 0;
529+
}
530+
531+
up->rest = rest;
521532
if(up->length == 0)
522533
up->length = r->headers_in.content_length_n;
523534
ngx_log_debug3(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0,

0 commit comments

Comments
 (0)