diff options
author | Max Romanov <max.romanov@nginx.com> | 2017-09-07 16:39:31 -0700 |
---|---|---|
committer | Max Romanov <max.romanov@nginx.com> | 2017-09-07 16:39:31 -0700 |
commit | d87a4fb642ed4588483e65cd74a83b0cec7e8d29 (patch) | |
tree | 0758fc192846bdbe7edc12ddfcdc1d665ff70415 /src/nxt_router.c | |
parent | 789a101e99433ea371f7560758a5130a97d129a1 (diff) | |
download | unit-d87a4fb642ed4588483e65cd74a83b0cec7e8d29.tar.gz unit-d87a4fb642ed4588483e65cd74a83b0cec7e8d29.tar.bz2 |
Moving body data before headers for PHP POST.
PHP SAPI tries to read body for POST request before registering
header-specific variables. For other methods, read_post_body() called by SAPI
after variables registration.
This closes #10 issue on GitHub.
Diffstat (limited to '')
-rw-r--r-- | src/nxt_router.c | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/src/nxt_router.c b/src/nxt_router.c index fbc8d9c4..d62c536f 100644 --- a/src/nxt_router.c +++ b/src/nxt_router.c @@ -2862,6 +2862,7 @@ nxt_php_prepare_msg(nxt_task_t *task, nxt_app_request_t *r, { nxt_int_t rc; nxt_buf_t *b; + nxt_bool_t method_is_post; nxt_http_field_t *field; nxt_app_request_header_t *h; @@ -2916,6 +2917,20 @@ nxt_php_prepare_msg(nxt_task_t *task, nxt_app_request_t *r, NXT_WRITE(&h->content_length); RC(nxt_app_msg_write_size(task, wmsg, h->parsed_content_length)); + RC(nxt_app_msg_write_size(task, wmsg, r->body.preread_size)); + + method_is_post = h->method.length == 4 && + h->method.start[0] == 'P' && + h->method.start[1] == 'O' && + h->method.start[2] == 'S' && + h->method.start[3] == 'T'; + + if (method_is_post) { + for(b = r->body.buf; b != NULL; b = b->next) { + RC(nxt_app_msg_write_raw(task, wmsg, b->mem.pos, + nxt_buf_mem_used_size(&b->mem))); + } + } nxt_list_each(field, h->fields) { RC(nxt_app_msg_write_prefixed_upcase(task, wmsg, @@ -2927,11 +2942,11 @@ nxt_php_prepare_msg(nxt_task_t *task, nxt_app_request_t *r, /* end-of-headers mark */ NXT_WRITE(&eof); - RC(nxt_app_msg_write_size(task, wmsg, r->body.preread_size)); - - for(b = r->body.buf; b != NULL; b = b->next) { - RC(nxt_app_msg_write_raw(task, wmsg, b->mem.pos, - nxt_buf_mem_used_size(&b->mem))); + if (!method_is_post) { + for(b = r->body.buf; b != NULL; b = b->next) { + RC(nxt_app_msg_write_raw(task, wmsg, b->mem.pos, + nxt_buf_mem_used_size(&b->mem))); + } } #undef NXT_WRITE |