Welcome! Log In Create A New Profile

Advanced

[PATCH 12 of 13] Request body: recalculate size of a request body in scgi module

Maxim Dounin
November 16, 2012 06:08AM
# HG changeset patch
# User Maxim Dounin <mdounin@mdounin.ru>
# Date 1352393278 -14400
# Node ID 18c2ee91104005005fdc710fce2253400131c558
# Parent ec54ef6b4826b3fa6d0f310cb4d80291dcdc7d3f
Request body: recalculate size of a request body in scgi module.

This allows to handle requests with chunked body by scgi module, and
also simplifies handling of various request body modifications.

diff --git a/src/http/modules/ngx_http_scgi_module.c b/src/http/modules/ngx_http_scgi_module.c
--- a/src/http/modules/ngx_http_scgi_module.c
+++ b/src/http/modules/ngx_http_scgi_module.c
@@ -533,10 +533,11 @@ ngx_http_scgi_create_key(ngx_http_reques
static ngx_int_t
ngx_http_scgi_create_request(ngx_http_request_t *r)
{
+ off_t content_length_n;
u_char ch, *key, *val, *lowcase_key;
size_t len, key_len, val_len, allocated;
ngx_buf_t *b;
- ngx_str_t *content_length;
+ ngx_str_t content_length;
ngx_uint_t i, n, hash, skip_empty, header_params;
ngx_chain_t *cl, *body;
ngx_list_part_t *part;
@@ -545,12 +546,20 @@ ngx_http_scgi_create_request(ngx_http_re
ngx_http_script_engine_t e, le;
ngx_http_scgi_loc_conf_t *scf;
ngx_http_script_len_code_pt lcode;
- static ngx_str_t zero = ngx_string("0");
+ u_char buffer[NGX_OFF_T_LEN];

- content_length = r->headers_in.content_length ?
- &r->headers_in.content_length->value : &zero;
+ content_length_n = 0;
+ body = r->upstream->request_bufs;

- len = sizeof("CONTENT_LENGTH") + content_length->len + 1;
+ while (body) {
+ content_length_n += ngx_buf_size(body->buf);
+ body = body->next;
+ }
+
+ content_length.data = buffer;
+ content_length.len = ngx_sprintf(buffer, "%O", content_length_n) - buffer;
+
+ len = sizeof("CONTENT_LENGTH") + content_length.len + 1;

header_params = 0;
ignored = NULL;
@@ -672,11 +681,8 @@ ngx_http_scgi_create_request(ngx_http_re

cl->buf = b;

- b->last = ngx_snprintf(b->last,
- NGX_SIZE_T_LEN + 1 + sizeof("CONTENT_LENGTH")
- + NGX_OFF_T_LEN + 1,
- "%ui:CONTENT_LENGTH%Z%V%Z",
- len, content_length);
+ b->last = ngx_sprintf(b->last, "%ui:CONTENT_LENGTH%Z%V%Z",
+ len, &content_length);

if (scf->params_len) {
ngx_memzero(&e, sizeof(ngx_http_script_engine_t));

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[PATCH 00 of 13] chunked request body support

Maxim Dounin 1077 November 16, 2012 06:06AM

[PATCH 01 of 13] Dav: fixed segfault on PUT if body was already read (ticket #238)

Maxim Dounin 524 November 16, 2012 06:06AM

[PATCH 02 of 13] Core: added debug logging of writev() in ngx_write_chain_to_file()

Maxim Dounin 561 November 16, 2012 06:06AM

[PATCH 03 of 13] Request body: fixed "501 Not Implemented" error handling

Maxim Dounin 2181 November 16, 2012 06:06AM

[PATCH 04 of 13] Request body: $request_body variable generalization

Maxim Dounin 581 November 16, 2012 06:06AM

[PATCH 05 of 13] Request body: code duplication reduced, no functional changes

Maxim Dounin 558 November 16, 2012 06:06AM

[PATCH 06 of 13] Request body: fixed socket leak on errors

Maxim Dounin 558 November 16, 2012 06:06AM

[PATCH 07 of 13] Request body: properly handle events while discarding body

Maxim Dounin 525 November 16, 2012 06:06AM

[PATCH 08 of 13] Request body: chunked parsing moved to ngx_http_parse.c from proxy

Maxim Dounin 548 November 16, 2012 06:06AM

[PATCH 09 of 13] Request body: adjust b->pos when chunked parsing done

Maxim Dounin 535 November 16, 2012 06:06AM

[PATCH 10 of 13] Request body: always use calculated size of a request body in proxy

Maxim Dounin 515 November 16, 2012 06:06AM

[PATCH 11 of 13] Request body: $content_length variable to honor real body size

Maxim Dounin 620 November 16, 2012 06:06AM

[PATCH 12 of 13] Request body: recalculate size of a request body in scgi module

Maxim Dounin 656 November 16, 2012 06:08AM

[PATCH 13 of 13] Request body: chunked transfer encoding support

Maxim Dounin 873 November 16, 2012 06:08AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 306
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready