summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_h1proto.c
diff options
context:
space:
mode:
authorValentin Bartenev <vbart@nginx.com>2018-02-07 18:17:41 +0300
committerValentin Bartenev <vbart@nginx.com>2018-02-07 18:17:41 +0300
commit31f72401d9356dc4413a8bac6ed059978dda7d9e (patch)
tree969fda442634090f28123ac3c8287dead380d5eb /src/nxt_h1proto.c
parent07303fb0d764a14d7f8a6632c153115520dd7048 (diff)
downloadunit-31f72401d9356dc4413a8bac6ed059978dda7d9e.tar.gz
unit-31f72401d9356dc4413a8bac6ed059978dda7d9e.tar.bz2
Fixed reading of the rest of body, again.
The last attempt in ee5f278e8c81 wasn't enough.
Diffstat (limited to '')
-rw-r--r--src/nxt_h1proto.c30
1 files changed, 12 insertions, 18 deletions
diff --git a/src/nxt_h1proto.c b/src/nxt_h1proto.c
index 56b8b3aa..e8d8e472 100644
--- a/src/nxt_h1proto.c
+++ b/src/nxt_h1proto.c
@@ -375,7 +375,7 @@ nxt_h1p_transfer_encoding(void *ctx, nxt_http_field_t *field, uintptr_t data)
static void
nxt_h1p_request_body_read(nxt_task_t *task, nxt_http_request_t *r)
{
- size_t size, rest_length;
+ size_t size, body_length;
nxt_buf_t *in, *b;
nxt_conn_t *c;
nxt_h1proto_t *h1p;
@@ -410,12 +410,12 @@ nxt_h1p_request_body_read(nxt_task_t *task, nxt_http_request_t *r)
goto error;
}
- rest_length = (size_t) r->content_length_n;
+ body_length = (size_t) r->content_length_n;
b = r->body;
if (b == NULL) {
- b = nxt_buf_mem_alloc(r->mem_pool, rest_length, 0);
+ b = nxt_buf_mem_alloc(r->mem_pool, body_length, 0);
if (nxt_slow_path(b == NULL)) {
status = NXT_HTTP_INTERNAL_SERVER_ERROR;
goto error;
@@ -429,23 +429,19 @@ nxt_h1p_request_body_read(nxt_task_t *task, nxt_http_request_t *r)
size = nxt_buf_mem_used_size(&in->mem);
if (size != 0) {
- if (size >= rest_length) {
- size = rest_length;
- rest_length = 0;
-
- } else {
- rest_length -= size;
+ if (size > body_length) {
+ size = body_length;
}
b->mem.free = nxt_cpymem(b->mem.free, in->mem.pos, size);
in->mem.pos += size;
}
- nxt_debug(task, "h1p body rest: %uz", rest_length);
+ size = nxt_buf_mem_free_size(&b->mem);
- r->rest_length = rest_length;
+ nxt_debug(task, "h1p body rest: %uz", size);
- if (rest_length != 0) {
+ if (size != 0) {
in->next = h1p->buffers;
h1p->buffers = in;
@@ -499,17 +495,15 @@ nxt_h1p_body_read(nxt_task_t *task, void *obj, void *data)
nxt_debug(task, "h1p body read");
- r = h1p->request;
- size = nxt_buf_mem_used_size(&c->read->mem);
+ size = nxt_buf_mem_free_size(&c->read->mem);
- r->rest_length -= size;
+ nxt_debug(task, "h1p body rest: %uz", size);
- nxt_debug(task, "h1p body rest: %O", r->rest_length);
-
- if (r->rest_length != 0) {
+ if (size != 0) {
nxt_conn_read(task->thread->engine, c);
} else {
+ r = h1p->request;
c->read = NULL;
nxt_work_queue_add(&task->thread->engine->fast_work_queue,
r->state->ready_handler, task, r, NULL);