Welcome! Log In Create A New Profile

Advanced

[PATCH 05 of 15] Upstream: content_length_n API change

Maxim Dounin
September 04, 2011 07:46AM
# HG changeset patch
# User Maxim Dounin <mdounin@mdounin.ru>
# Date 1314889887 -14400
# Node ID 7383d1e59b73aff371fd7cdc2f0fd800bce0b84e
# Parent db8b34c0e7391efc6a68f43ebeace8407f22e19c
Upstream: content_length_n API change.

We no longer use r->headers_out.content_length_n as a primary source of
backend's response length. Instead we parse response length to
u->headers_in.content_length_n and copy to r->headers_out.content_length_n
when needed.

diff --git a/src/http/modules/ngx_http_memcached_module.c b/src/http/modules/ngx_http_memcached_module.c
--- a/src/http/modules/ngx_http_memcached_module.c
+++ b/src/http/modules/ngx_http_memcached_module.c
@@ -344,8 +344,8 @@ found:

while (*p && *p++ != CR) { /* void */ }

- r->headers_out.content_length_n = ngx_atoof(len, p - len - 1);
- if (r->headers_out.content_length_n == -1) {
+ u->headers_in.content_length_n = ngx_atoof(len, p - len - 1);
+ if (u->headers_in.content_length_n == -1) {
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
"memcached sent invalid length in response \"%V\" "
"for key \"%V\"",
diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c
--- a/src/http/ngx_http_upstream.c
+++ b/src/http/ngx_http_upstream.c
@@ -72,6 +72,8 @@ static void ngx_http_upstream_finalize_r

static ngx_int_t ngx_http_upstream_process_header_line(ngx_http_request_t *r,
ngx_table_elt_t *h, ngx_uint_t offset);
+static ngx_int_t ngx_http_upstream_process_content_length(ngx_http_request_t *r,
+ ngx_table_elt_t *h, ngx_uint_t offset);
static ngx_int_t ngx_http_upstream_process_set_cookie(ngx_http_request_t *r,
ngx_table_elt_t *h, ngx_uint_t offset);
static ngx_int_t
@@ -96,8 +98,6 @@ static ngx_int_t
ngx_table_elt_t *h, ngx_uint_t offset);
static ngx_int_t ngx_http_upstream_copy_content_type(ngx_http_request_t *r,
ngx_table_elt_t *h, ngx_uint_t offset);
-static ngx_int_t ngx_http_upstream_copy_content_length(ngx_http_request_t *r,
- ngx_table_elt_t *h, ngx_uint_t offset);
static ngx_int_t ngx_http_upstream_copy_last_modified(ngx_http_request_t *r,
ngx_table_elt_t *h, ngx_uint_t offset);
static ngx_int_t ngx_http_upstream_rewrite_location(ngx_http_request_t *r,
@@ -149,9 +149,9 @@ ngx_http_upstream_header_t ngx_http_ups
ngx_http_upstream_copy_content_type, 0, 1 },

{ ngx_string("Content-Length"),
- ngx_http_upstream_process_header_line,
+ ngx_http_upstream_process_content_length,
offsetof(ngx_http_upstream_headers_in_t, content_length),
- ngx_http_upstream_copy_content_length, 0, 0 },
+ ngx_http_upstream_ignore_header_line, 0, 0 },

{ ngx_string("Date"),
ngx_http_upstream_process_header_line,
@@ -396,6 +396,8 @@ ngx_http_upstream_create(ngx_http_reques
r->cache = NULL;
#endif

+ u->headers_in.content_length_n = -1;
+
return NGX_OK;
}

@@ -800,6 +802,7 @@ ngx_http_upstream_cache_send(ngx_http_re
u->buffer.pos += c->header_start;

ngx_memzero(&u->headers_in, sizeof(ngx_http_upstream_headers_in_t));
+ u->headers_in.content_length_n = -1;

if (ngx_list_init(&u->headers_in.headers, r->pool, 8,
sizeof(ngx_table_elt_t))
@@ -1295,6 +1298,7 @@ ngx_http_upstream_reinit(ngx_http_reques
}

ngx_memzero(&u->headers_in, sizeof(ngx_http_upstream_headers_in_t));
+ u->headers_in.content_length_n = -1;

if (ngx_list_init(&u->headers_in.headers, r->pool, 8,
sizeof(ngx_table_elt_t))
@@ -1936,10 +1940,10 @@ ngx_http_upstream_process_headers(ngx_ht
r->headers_out.status = u->headers_in.status_n;
r->headers_out.status_line = u->headers_in.status_line;

- u->headers_in.content_length_n = r->headers_out.content_length_n;
-
- if (r->headers_out.content_length_n != -1) {
- u->length = (size_t) r->headers_out.content_length_n;
+ r->headers_out.content_length_n = u->headers_in.content_length_n;
+
+ if (u->headers_in.content_length_n != -1) {
+ u->length = (size_t) u->headers_in.content_length_n;

} else {
u->length = NGX_MAX_SIZE_T_VALUE;
@@ -3078,6 +3082,21 @@ ngx_http_upstream_ignore_header_line(ngx


static ngx_int_t
+ngx_http_upstream_process_content_length(ngx_http_request_t *r,
+ ngx_table_elt_t *h, ngx_uint_t offset)
+{
+ ngx_http_upstream_t *u;
+
+ u = r->upstream;
+
+ u->headers_in.content_length = h;
+ u->headers_in.content_length_n = ngx_atoof(h->value.data, h->value.len);
+
+ return NGX_OK;
+}
+
+
+static ngx_int_t
ngx_http_upstream_process_set_cookie(ngx_http_request_t *r, ngx_table_elt_t *h,
ngx_uint_t offset)
{
@@ -3446,26 +3465,6 @@ ngx_http_upstream_copy_content_type(ngx_


static ngx_int_t
-ngx_http_upstream_copy_content_length(ngx_http_request_t *r, ngx_table_elt_t *h,
- ngx_uint_t offset)
-{
- ngx_table_elt_t *ho;
-
- ho = ngx_list_push(&r->headers_out.headers);
- if (ho == NULL) {
- return NGX_ERROR;
- }
-
- *ho = *h;
-
- r->headers_out.content_length = ho;
- r->headers_out.content_length_n = ngx_atoof(h->value.data, h->value.len);
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
ngx_http_upstream_copy_last_modified(ngx_http_request_t *r, ngx_table_elt_t *h,
ngx_uint_t offset)
{

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

[PATCH 00 of 15] upstream keepalive patch queue

Maxim Dounin 1950 September 04, 2011 07:46AM

[PATCH 01 of 15] Correct SSL shutdown handling

Maxim Dounin 863 September 04, 2011 07:46AM

[PATCH 02 of 15] Proper setting of read->eof in pipe code

Maxim Dounin 842 September 04, 2011 07:46AM

[PATCH 03 of 15] Workaround for cpu hog on errors with cached connections

Maxim Dounin 893 September 04, 2011 07:46AM

[PATCH 04 of 15] Upstream: separate pool for peer connections

Maxim Dounin 893 September 04, 2011 07:46AM

[PATCH 05 of 15] Upstream: content_length_n API change

Maxim Dounin 1089 September 04, 2011 07:46AM

[PATCH 06 of 15] Upstream: r->upstream->length type change to off_t

Maxim Dounin 786 September 04, 2011 07:46AM

[PATCH 07 of 15] Upstream: pipe length and input_filter_init in buffered mode

Maxim Dounin 899 September 04, 2011 07:48AM

[PATCH 08 of 15] Upstream: keepalive flag

Maxim Dounin 820 September 04, 2011 07:48AM

[PATCH 09 of 15] Keepalive support in memcached

Maxim Dounin 791 September 04, 2011 07:48AM

[PATCH 10 of 15] Keepalive support in fastcgi

Maxim Dounin 965 September 04, 2011 07:48AM

[PATCH 11 of 15] Upstream: process Transfer-Encoding header and detect chunked one

Maxim Dounin 914 September 04, 2011 07:48AM

[PATCH 12 of 15] Upstream: process Connection header and detect close token

Maxim Dounin 885 September 04, 2011 07:48AM

[PATCH 13 of 15] Protocol version parsing in ngx_http_parse_status_line()

Maxim Dounin 873 September 04, 2011 07:48AM

[PATCH 14 of 15] Proxy: basic HTTP/1.1 support (including keepalive)

Maxim Dounin 1015 September 04, 2011 07:48AM

[PATCH 15 of 15] Upstream keepalive module

Maxim Dounin 961 September 04, 2011 07:48AM

Re: [PATCH 00 of 15] upstream keepalive patch queue

Maxim Dounin 756 September 05, 2011 01:56PM

Re: [PATCH 00 of 15] upstream keepalive patch queue

splitice 1199 September 06, 2011 01:46AM



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

Online Users

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