[nginx] svn commit: r4928 - trunk/src/http/modules
mdounin at mdounin.ru
mdounin at mdounin.ru
Wed Nov 21 01:03:48 UTC 2012
Author: mdounin
Date: 2012-11-21 01:03:48 +0000 (Wed, 21 Nov 2012)
New Revision: 4928
URL: http://trac.nginx.org/nginx/changeset/4928/nginx
Log:
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.
Modified:
trunk/src/http/modules/ngx_http_proxy_module.c
Modified: trunk/src/http/modules/ngx_http_proxy_module.c
===================================================================
--- trunk/src/http/modules/ngx_http_proxy_module.c 2012-11-21 01:02:56 UTC (rev 4927)
+++ trunk/src/http/modules/ngx_http_proxy_module.c 2012-11-21 01:03:48 UTC (rev 4928)
@@ -83,7 +83,7 @@
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 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_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 @@
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 @@
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 @@
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 @@
}
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,17 +2911,7 @@
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++) {
More information about the nginx-devel
mailing list