Skip to content

Commit 09ed086

Browse files
author
mdounin
committed
Perl: request body handling fixed.
As of 1.3.9, chunked request body may be available with r->headers_in.content_length_n <= 0. Additionally, request body may be in multiple buffers even if r->request_body_in_single_buf was requested.
1 parent af1d115 commit 09ed086

File tree

1 file changed

+36
-3
lines changed

1 file changed

+36
-3
lines changed

src/http/modules/perl/nginx.xs

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ has_request_body(r, next)
357357

358358
ngx_http_perl_set_request(r);
359359

360-
if (r->headers_in.content_length_n <= 0) {
360+
if (r->headers_in.content_length_n <= 0 && !r->headers_in.chunked) {
361361
XSRETURN_UNDEF;
362362
}
363363

@@ -386,7 +386,10 @@ request_body(r)
386386

387387
dXSTARG;
388388
ngx_http_request_t *r;
389+
u_char *p, *data;
389390
size_t len;
391+
ngx_buf_t *buf;
392+
ngx_chain_t *cl;
390393

391394
ngx_http_perl_set_request(r);
392395

@@ -397,13 +400,43 @@ request_body(r)
397400
XSRETURN_UNDEF;
398401
}
399402

400-
len = r->request_body->bufs->buf->last - r->request_body->bufs->buf->pos;
403+
cl = r->request_body->bufs;
404+
buf = cl->buf;
405+
406+
if (cl->next == NULL) {
407+
len = buf->last - buf->pos;
408+
data = buf->pos;
409+
goto done;
410+
}
411+
412+
len = buf->last - buf->pos;
413+
cl = cl->next;
414+
415+
for ( /* void */ ; cl; cl = cl->next) {
416+
buf = cl->buf;
417+
len += buf->last - buf->pos;
418+
}
419+
420+
p = ngx_pnalloc(r->pool, len);
421+
if (p == NULL) {
422+
return XSRETURN_UNDEF;
423+
}
424+
425+
data = p;
426+
cl = r->request_body->bufs;
427+
428+
for ( /* void */ ; cl; cl = cl->next) {
429+
buf = cl->buf;
430+
p = ngx_cpymem(p, buf->pos, buf->last - buf->pos);
431+
}
432+
433+
done:
401434

402435
if (len == 0) {
403436
XSRETURN_UNDEF;
404437
}
405438

406-
ngx_http_perl_set_targ(r->request_body->bufs->buf->pos, len);
439+
ngx_http_perl_set_targ(data, len);
407440

408441
ST(0) = TARG;
409442

0 commit comments

Comments
 (0)