|
|
@@ -371,36 +371,32 @@ find_node(ngx_str_t * id, ngx_http_uploadprogress_ctx_t * ctx, ngx_log_t * log)
|
|
371
|
371
|
sentinel = ctx->rbtree->sentinel;
|
|
372
|
372
|
|
|
373
|
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
|
376
|
continue;
|
|
383
|
377
|
}
|
|
384
|
378
|
|
|
385
|
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
|
400
|
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, log, 0, "upload-progress: can't find node");
|
|
405
|
401
|
return NULL;
|
|
406
|
402
|
}
|
|
|
@@ -458,6 +454,7 @@ static void ngx_http_uploadprogress_event_handler(ngx_http_request_t *r)
|
|
458
|
454
|
ngx_str_t *id, *oldid;
|
|
459
|
455
|
ngx_slab_pool_t *shpool;
|
|
460
|
456
|
ngx_shm_zone_t *shm_zone;
|
|
|
457
|
+ ngx_http_request_body_t *rb;
|
|
461
|
458
|
ngx_http_uploadprogress_ctx_t *ctx;
|
|
462
|
459
|
ngx_http_uploadprogress_node_t *up;
|
|
463
|
460
|
ngx_http_uploadprogress_conf_t *upcf;
|
|
|
@@ -466,6 +463,8 @@ static void ngx_http_uploadprogress_event_handler(ngx_http_request_t *r)
|
|
466
|
463
|
off_t rest;
|
|
467
|
464
|
|
|
468
|
465
|
|
|
|
466
|
+ rb = r->request_body;
|
|
|
467
|
+
|
|
469
|
468
|
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "upload-progress: ngx_http_uploadprogress_event_handler");
|
|
470
|
469
|
|
|
471
|
470
|
/* find node, update rest */
|
|
|
@@ -520,15 +519,25 @@ static void ngx_http_uploadprogress_event_handler(ngx_http_request_t *r)
|
|
520
|
519
|
if (up != NULL && !up->done) {
|
|
521
|
520
|
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0,
|
|
522
|
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
|
541
|
if(up->length == 0)
|
|
533
|
542
|
up->length = r->headers_in.content_length_n;
|
|
534
|
543
|
ngx_log_debug3(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0,
|
|
|
@@ -1091,11 +1100,7 @@ ngx_http_uploadprogress_init_zone(ngx_shm_zone_t * shm_zone, void *data)
|
|
1091
|
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
|
1105
|
return NGX_OK;
|
|
1101
|
1106
|
}
|