Quellcode durchsuchen

fix #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 <brice-puppet@daysofwonder.com>
tags/v0.9.1
Brice Figureau vor 12 Jahren
Ursprung
Commit
39e4d53987
1 geänderte Dateien mit 12 neuen und 1 gelöschten Zeilen
  1. 12
    1
      ngx_http_uploadprogress_module.c

+ 12
- 1
ngx_http_uploadprogress_module.c Datei anzeigen

@@ -462,6 +462,9 @@ static void ngx_http_uploadprogress_event_handler(ngx_http_request_t *r)
462 462
     ngx_http_uploadprogress_node_t              *up;
463 463
     ngx_http_uploadprogress_conf_t              *upcf;
464 464
     ngx_http_uploadprogress_module_ctx_t        *module_ctx;
465
+    size_t                                       size;
466
+    off_t                                        rest;
467
+    
465 468
 
466 469
     ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "upload-progress: ngx_http_uploadprogress_event_handler");
467 470
     
@@ -517,7 +520,15 @@ static void ngx_http_uploadprogress_event_handler(ngx_http_request_t *r)
517 520
     if (up != NULL && !up->done) {
518 521
         ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0,
519 522
                        "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;
521 532
         if(up->length == 0)
522 533
             up->length = r->headers_in.content_length_n;
523 534
         ngx_log_debug3(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0,

Laden…
Abbrechen
Speichern