Welcome! Log In Create A New Profile

Advanced

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

Maxim Dounin
November 16, 2012 06:06AM
# HG changeset patch
# User Maxim Dounin <mdounin@mdounin.ru>
# Date 1352393278 -14400
# Node ID a3bad06d0ab3874b7479823f1c7240306792a110
# Parent d04392abdec6cb1c7e3d09522288838ce90851b4
Request body: always use calculated size of a request body in proxy.

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

diff --git a/src/http/modules/ngx_http_proxy_module.c b/src/http/modules/ngx_http_proxy_module.c
--- a/src/http/modules/ngx_http_proxy_module.c
+++ b/src/http/modules/ngx_http_proxy_module.c
@@ -83,7 +83,7 @@ typedef struct {
ngx_http_status_t status;
ngx_http_chunked_t chunked;
ngx_http_proxy_vars_t vars;
- size_t internal_body_length;
+ off_t internal_body_length;

ngx_uint_t head; /* unsigned head:1 */
} ngx_http_proxy_ctx_t;
@@ -555,6 +555,8 @@ static char ngx_http_proxy_version_11[]
static ngx_keyval_t ngx_http_proxy_headers[] = {
{ ngx_string("Host"), ngx_string("$proxy_host") },
{ ngx_string("Connection"), ngx_string("close") },
+ { ngx_string("Content-Length"), ngx_string("$proxy_internal_body_length") },
+ { ngx_string("Transfer-Encoding"), ngx_string("") },
{ ngx_string("Keep-Alive"), ngx_string("") },
{ ngx_string("Expect"), ngx_string("") },
{ ngx_string("Upgrade"), ngx_string("") },
@@ -580,6 +582,8 @@ static ngx_str_t ngx_http_proxy_hide_he
static ngx_keyval_t ngx_http_proxy_cache_headers[] = {
{ ngx_string("Host"), ngx_string("$proxy_host") },
{ ngx_string("Connection"), ngx_string("close") },
+ { ngx_string("Content-Length"), ngx_string("$proxy_internal_body_length") },
+ { ngx_string("Transfer-Encoding"), ngx_string("") },
{ ngx_string("Keep-Alive"), ngx_string("") },
{ ngx_string("Expect"), ngx_string("") },
{ ngx_string("Upgrade"), ngx_string("") },
@@ -1003,6 +1007,9 @@ ngx_http_proxy_create_request(ngx_http_r

ctx->internal_body_length = body_len;
len += body_len;
+
+ } else {
+ ctx->internal_body_length = r->headers_in.content_length_n;
}

le.ip = plcf->headers_set_len->elts;
@@ -2039,7 +2046,7 @@ ngx_http_proxy_internal_body_length_vari

ctx = ngx_http_get_module_ctx(r, ngx_http_proxy_module);

- if (ctx == NULL) {
+ if (ctx == NULL || ctx->internal_body_length < 0) {
v->not_found = 1;
return NGX_OK;
}
@@ -2048,13 +2055,13 @@ ngx_http_proxy_internal_body_length_vari
v->no_cacheable = 0;
v->not_found = 0;

- v->data = ngx_pnalloc(r->connection->pool, NGX_SIZE_T_LEN);
+ v->data = ngx_pnalloc(r->connection->pool, NGX_OFF_T_LEN);

if (v->data == NULL) {
return NGX_ERROR;
}

- v->len = ngx_sprintf(v->data, "%uz", ctx->internal_body_length) - v->data;
+ v->len = ngx_sprintf(v->data, "%O", ctx->internal_body_length) - v->data;

return NGX_OK;
}
@@ -2822,8 +2829,6 @@ ngx_http_proxy_merge_headers(ngx_conf_t
}

if (conf->headers_set_hash.buckets
- && ((conf->body_source.data == NULL)
- == (prev->body_source.data == NULL))
#if (NGX_HTTP_CACHE)
&& ((conf->upstream.cache == NULL) == (prev->upstream.cache == NULL))
#endif
@@ -2906,16 +2911,6 @@ ngx_http_proxy_merge_headers(ngx_conf_t
h++;
}

- if (conf->body_source.data) {
- s = ngx_array_push(&headers_merged);
- if (s == NULL) {
- return NGX_ERROR;
- }
-
- ngx_str_set(&s->key, "Content-Length");
- ngx_str_set(&s->value, "$proxy_internal_body_length");
- }
-

src = headers_merged.elts;
for (i = 0; i < headers_merged.nelts; i++) {

_______________________________________________
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 1082 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 562 November 16, 2012 06:06AM

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

Maxim Dounin 2186 November 16, 2012 06:06AM

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

Maxim Dounin 582 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 560 November 16, 2012 06:06AM

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

Maxim Dounin 526 November 16, 2012 06:06AM

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

Maxim Dounin 549 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 621 November 16, 2012 06:06AM

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

Maxim Dounin 658 November 16, 2012 06:08AM

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

Maxim Dounin 875 November 16, 2012 06:08AM



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

Online Users

Guests: 155
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