Skip to content

fix received and size same issue when using HTTP/2 #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 24, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 38 additions & 33 deletions ngx_http_uploadprogress_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -371,36 +371,32 @@ find_node(ngx_str_t * id, ngx_http_uploadprogress_ctx_t * ctx, ngx_log_t * log)
sentinel = ctx->rbtree->sentinel;

while (node != sentinel) {

if (hash < node->key) {
node = node->left;
continue;
}

if (hash > node->key) {
node = node->right;
if (hash != node->key) {
node = (hash < node->key) ? node->left : node->right;
continue;
}

/* hash == node->key */
up = (ngx_http_uploadprogress_node_t *) node;

do {
up = (ngx_http_uploadprogress_node_t *) node;

rc = ngx_memn2cmp(id->data, up->data, id->len, (size_t) up->len);

if (rc == 0) {
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, log, 0,
"upload-progress: found node");
return up;
}
rc = ngx_memn2cmp(id->data, up->data, id->len, up->len);

node = (rc < 0) ? node->left : node->right;
/* found a key with unmatching hash (and value), let's keep comparing hashes then */
if (rc < 0) {
node = node->left;
continue;
}

} while (node != sentinel && hash == node->key);
if (rc > 0) {
node = node->right;
continue;
}

/* found a key with unmatching hash (and value), let's keep comparing hashes then */
/* found the hash */
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, log, 0, "upload-progress: found node");
return up;
}

ngx_log_debug0(NGX_LOG_DEBUG_HTTP, log, 0, "upload-progress: can't find node");
return NULL;
}
Expand Down Expand Up @@ -458,6 +454,7 @@ static void ngx_http_uploadprogress_event_handler(ngx_http_request_t *r)
ngx_str_t *id, *oldid;
ngx_slab_pool_t *shpool;
ngx_shm_zone_t *shm_zone;
ngx_http_request_body_t *rb;
ngx_http_uploadprogress_ctx_t *ctx;
ngx_http_uploadprogress_node_t *up;
ngx_http_uploadprogress_conf_t *upcf;
Expand All @@ -466,6 +463,8 @@ static void ngx_http_uploadprogress_event_handler(ngx_http_request_t *r)
off_t rest;


rb = r->request_body;

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

/* find node, update rest */
Expand Down Expand Up @@ -520,15 +519,25 @@ 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);
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;

#if (NGX_HTTP_V2)
if (r->http_connection->addr_conf->http2) { /* http/2 */
up->rest = up->length - r->request_length;
} else { /* http/1 */
#endif
rest = rb->rest;
size = rb->buf->last - rb->buf->pos;
if ((off_t) size < rest) {
rest -= size;
} else {
rest = 0;
}
up->rest = rest;

#if (NGX_HTTP_V2)
}
#endif

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 Expand Up @@ -1091,11 +1100,7 @@ ngx_http_uploadprogress_init_zone(ngx_shm_zone_t * shm_zone, void *data)
return NGX_ERROR;
}

ngx_rbtree_sentinel_init(sentinel);

ctx->rbtree->root = sentinel;
ctx->rbtree->sentinel = sentinel;
ctx->rbtree->insert = ngx_http_uploadprogress_rbtree_insert_value;
ngx_rbtree_init(ctx->rbtree, sentinel, ngx_http_uploadprogress_rbtree_insert_value);

return NGX_OK;
}
Expand Down