From 14f02ed0dde2ee19da75cd836daf76505d7f2e9c Mon Sep 17 00:00:00 2001 From: Igor Sysoev Date: Fri, 26 Mar 2004 16:13:01 +0000 Subject: [PATCH] nginx-0.0.3-2004-03-26-19:13:01 import --- src/http/ngx_http_request.h | 2 +- src/http/ngx_http_request_body.c | 27 +++++++++++++++++---------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/http/ngx_http_request.h b/src/http/ngx_http_request.h index ad1afd9b5..e86034ecc 100644 --- a/src/http/ngx_http_request.h +++ b/src/http/ngx_http_request.h @@ -228,7 +228,7 @@ struct ngx_http_request_s { ngx_temp_file_t *temp_file; ngx_chain_t *request_hunks; ngx_hunk_t *request_body_hunk; - size_t request_body_len; + size_t remaining_body_len; void (*request_body_handler) (void *data); void *data; diff --git a/src/http/ngx_http_request_body.c b/src/http/ngx_http_request_body.c index 99ac8aad3..f6be9cf50 100644 --- a/src/http/ngx_http_request_body.c +++ b/src/http/ngx_http_request_body.c @@ -19,6 +19,9 @@ ngx_int_t ngx_http_read_client_request_body(ngx_http_request_t *r, size = r->header_in->last - r->header_in->pos; if (size) { + + /* there is the pre-read part of the request body */ + ngx_test_null(h, ngx_calloc_hunk(r->pool), NGX_ERROR); h->type = NGX_HUNK_IN_MEMORY|NGX_HUNK_TEMP; @@ -28,19 +31,23 @@ ngx_int_t ngx_http_read_client_request_body(ngx_http_request_t *r, ngx_alloc_link_and_set_hunk(r->request_hunks, h, r->pool, NGX_ERROR); if (size >= r->headers_in.content_length_n) { - r->header_in->pos += r->headers_in.content_length_n; + /* the whole request body was pre-read */ + + r->header_in->pos += r->headers_in.content_length_n; return NGX_OK; } r->header_in->pos = r->header_in->last; } - r->request_body_len = r->headers_in.content_length_n - size; - if (r->request_body_len < request_buffer_size + (request_buffer_size >> 2)) + r->remaining_body_len = r->headers_in.content_length_n - size; + + if (r->remaining_body_len + < request_buffer_size + (request_buffer_size >> 2)) { - size = r->request_body_len; + size = r->remaining_body_len; } else { size = request_buffer_size; @@ -116,8 +123,8 @@ static ngx_int_t ngx_http_do_read_client_request_body(ngx_http_request_t *r) size = r->request_body_hunk->end - r->request_body_hunk->last; - if (size > r->request_body_len) { - size = r->request_body_len; + if (size > r->remaining_body_len) { + size = r->remaining_body_len; } n = ngx_recv(c, r->request_body_hunk->last, size); @@ -147,9 +154,9 @@ static ngx_int_t ngx_http_do_read_client_request_body(ngx_http_request_t *r) } r->request_body_hunk->last += n; - r->request_body_len -= n; + r->remaining_body_len -= n; - if (r->request_body_len == 0) { + if (r->remaining_body_len == 0) { break; } @@ -160,9 +167,9 @@ static ngx_int_t ngx_http_do_read_client_request_body(ngx_http_request_t *r) ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, "http client request body left " SIZE_T_FMT, - r->request_body_len); + r->remaining_body_len); - if (r->request_body_len) { + if (r->remaining_body_len) { return NGX_AGAIN; }