Skip to content

Commit

Permalink
fix #36 - nginx reduces rquest_body->rest only on buffer recycling
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Brice Figureau committed May 16, 2014
1 parent 4b7a2c9 commit 39e4d53
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion ngx_http_uploadprogress_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,9 @@ static void ngx_http_uploadprogress_event_handler(ngx_http_request_t *r)
ngx_http_uploadprogress_node_t *up;
ngx_http_uploadprogress_conf_t *upcf;
ngx_http_uploadprogress_module_ctx_t *module_ctx;
size_t size;
off_t rest;


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

Expand Down Expand Up @@ -517,7 +520,15 @@ static void ngx_http_uploadprogress_event_handler(ngx_http_request_t *r)
if (up != NULL && !up->done) {
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0,
"upload-progress: read_event_handler found node: %V", id);
up->rest = r->request_body->rest;
rest = r->request_body->rest;
size = r->request_body->buf->last - r->request_body->buf->pos;
if ((off_t) size < rest) {
rest -= size;
} else {
rest = 0;
}

up->rest = rest;
if(up->length == 0)
up->length = r->headers_in.content_length_n;
ngx_log_debug3(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0,
Expand Down

0 comments on commit 39e4d53

Please sign in to comment.