Bläddra i källkod

Merge pull request #55 from e2dk4r/master

fix received and size same issue when using HTTP/2
tags/v0.9.3
Brice Figureau 4 år sedan
förälder
incheckning
68b3ab3b64
Inget konto är kopplat till bidragsgivarens mejladress
1 ändrade filer med 38 tillägg och 33 borttagningar
  1. 38
    33
      ngx_http_uploadprogress_module.c

+ 38
- 33
ngx_http_uploadprogress_module.c Visa fil

371
     sentinel = ctx->rbtree->sentinel;
371
     sentinel = ctx->rbtree->sentinel;
372
 
372
 
373
     while (node != sentinel) {
373
     while (node != sentinel) {
374
-
375
-        if (hash < node->key) {
376
-            node = node->left;
377
-            continue;
378
-        }
379
-
380
-        if (hash > node->key) {
381
-            node = node->right;
374
+        if (hash != node->key) {
375
+            node = (hash < node->key) ? node->left : node->right;
382
             continue;
376
             continue;
383
         }
377
         }
384
 
378
 
385
         /* hash == node->key */
379
         /* hash == node->key */
380
+        up = (ngx_http_uploadprogress_node_t *) node;
386
 
381
 
387
-        do {
388
-            up = (ngx_http_uploadprogress_node_t *) node;
389
-
390
-            rc = ngx_memn2cmp(id->data, up->data, id->len, (size_t) up->len);
391
-
392
-            if (rc == 0) {
393
-                ngx_log_debug0(NGX_LOG_DEBUG_HTTP, log, 0,
394
-                               "upload-progress: found node");
395
-                return up;
396
-            }
382
+        rc = ngx_memn2cmp(id->data, up->data, id->len, up->len);
397
 
383
 
398
-            node = (rc < 0) ? node->left : node->right;
384
+        /* found a key with unmatching hash (and value), let's keep comparing hashes then */
385
+        if (rc < 0) {
386
+          node = node->left;
387
+          continue;
388
+        }
399
 
389
 
400
-        } while (node != sentinel && hash == node->key);
390
+        if (rc > 0) {
391
+          node = node->right;
392
+          continue;
393
+        }
401
 
394
 
402
-        /* found a key with unmatching hash (and value), let's keep comparing hashes then */
395
+        /* found the hash */
396
+        ngx_log_debug0(NGX_LOG_DEBUG_HTTP, log, 0, "upload-progress: found node");
397
+        return up;
403
     }
398
     }
399
+
404
     ngx_log_debug0(NGX_LOG_DEBUG_HTTP, log, 0, "upload-progress: can't find node");
400
     ngx_log_debug0(NGX_LOG_DEBUG_HTTP, log, 0, "upload-progress: can't find node");
405
     return NULL;
401
     return NULL;
406
 }
402
 }
458
     ngx_str_t                                   *id, *oldid;
454
     ngx_str_t                                   *id, *oldid;
459
     ngx_slab_pool_t                             *shpool;
455
     ngx_slab_pool_t                             *shpool;
460
     ngx_shm_zone_t                              *shm_zone;
456
     ngx_shm_zone_t                              *shm_zone;
457
+    ngx_http_request_body_t                     *rb;
461
     ngx_http_uploadprogress_ctx_t               *ctx;
458
     ngx_http_uploadprogress_ctx_t               *ctx;
462
     ngx_http_uploadprogress_node_t              *up;
459
     ngx_http_uploadprogress_node_t              *up;
463
     ngx_http_uploadprogress_conf_t              *upcf;
460
     ngx_http_uploadprogress_conf_t              *upcf;
466
     off_t                                        rest;
463
     off_t                                        rest;
467
     
464
     
468
 
465
 
466
+    rb = r->request_body;
467
+
469
     ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "upload-progress: ngx_http_uploadprogress_event_handler");
468
     ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "upload-progress: ngx_http_uploadprogress_event_handler");
470
     
469
     
471
     /* find node, update rest */
470
     /* find node, update rest */
520
     if (up != NULL && !up->done) {
519
     if (up != NULL && !up->done) {
521
         ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0,
520
         ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0,
522
                        "upload-progress: read_event_handler found node: %V", id);
521
                        "upload-progress: read_event_handler found node: %V", id);
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;
522
+
523
+        #if (NGX_HTTP_V2)
524
+        if (r->http_connection->addr_conf->http2) { /* http/2 */
525
+            up->rest = up->length - r->request_length;
526
+        } else { /* http/1 */
527
+        #endif
528
+            rest = rb->rest;
529
+            size = rb->buf->last - rb->buf->pos;
530
+            if ((off_t) size < rest) {
531
+                rest -= size;
532
+            } else {
533
+                rest = 0;
534
+            }
535
+            up->rest = rest;
536
+
537
+        #if (NGX_HTTP_V2)
529
         }
538
         }
539
+        #endif
530
         
540
         
531
-        up->rest = rest;
532
         if(up->length == 0)
541
         if(up->length == 0)
533
             up->length = r->headers_in.content_length_n;
542
             up->length = r->headers_in.content_length_n;
534
         ngx_log_debug3(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0,
543
         ngx_log_debug3(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0,
1091
         return NGX_ERROR;
1100
         return NGX_ERROR;
1092
     }
1101
     }
1093
 
1102
 
1094
-    ngx_rbtree_sentinel_init(sentinel);
1095
-
1096
-    ctx->rbtree->root = sentinel;
1097
-    ctx->rbtree->sentinel = sentinel;
1098
-    ctx->rbtree->insert = ngx_http_uploadprogress_rbtree_insert_value;
1103
+    ngx_rbtree_init(ctx->rbtree, sentinel, ngx_http_uploadprogress_rbtree_insert_value);
1099
 
1104
 
1100
     return NGX_OK;
1105
     return NGX_OK;
1101
 }
1106
 }

Laddar…
Avbryt
Spara