Mercurial > hg > nginx
comparison src/http/ngx_http_upstream.c @ 4117:103b0d9afe07
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.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 15 Sep 2011 18:33:43 +0000 |
parents | 9baf12ea5ca1 |
children | dbddec65fdab |
comparison
equal
deleted
inserted
replaced
4116:9baf12ea5ca1 | 4117:103b0d9afe07 |
---|---|
70 static void ngx_http_upstream_finalize_request(ngx_http_request_t *r, | 70 static void ngx_http_upstream_finalize_request(ngx_http_request_t *r, |
71 ngx_http_upstream_t *u, ngx_int_t rc); | 71 ngx_http_upstream_t *u, ngx_int_t rc); |
72 | 72 |
73 static ngx_int_t ngx_http_upstream_process_header_line(ngx_http_request_t *r, | 73 static ngx_int_t ngx_http_upstream_process_header_line(ngx_http_request_t *r, |
74 ngx_table_elt_t *h, ngx_uint_t offset); | 74 ngx_table_elt_t *h, ngx_uint_t offset); |
75 static ngx_int_t ngx_http_upstream_process_content_length(ngx_http_request_t *r, | |
76 ngx_table_elt_t *h, ngx_uint_t offset); | |
75 static ngx_int_t ngx_http_upstream_process_set_cookie(ngx_http_request_t *r, | 77 static ngx_int_t ngx_http_upstream_process_set_cookie(ngx_http_request_t *r, |
76 ngx_table_elt_t *h, ngx_uint_t offset); | 78 ngx_table_elt_t *h, ngx_uint_t offset); |
77 static ngx_int_t | 79 static ngx_int_t |
78 ngx_http_upstream_process_cache_control(ngx_http_request_t *r, | 80 ngx_http_upstream_process_cache_control(ngx_http_request_t *r, |
79 ngx_table_elt_t *h, ngx_uint_t offset); | 81 ngx_table_elt_t *h, ngx_uint_t offset); |
94 static ngx_int_t | 96 static ngx_int_t |
95 ngx_http_upstream_copy_multi_header_lines(ngx_http_request_t *r, | 97 ngx_http_upstream_copy_multi_header_lines(ngx_http_request_t *r, |
96 ngx_table_elt_t *h, ngx_uint_t offset); | 98 ngx_table_elt_t *h, ngx_uint_t offset); |
97 static ngx_int_t ngx_http_upstream_copy_content_type(ngx_http_request_t *r, | 99 static ngx_int_t ngx_http_upstream_copy_content_type(ngx_http_request_t *r, |
98 ngx_table_elt_t *h, ngx_uint_t offset); | 100 ngx_table_elt_t *h, ngx_uint_t offset); |
99 static ngx_int_t ngx_http_upstream_copy_content_length(ngx_http_request_t *r, | |
100 ngx_table_elt_t *h, ngx_uint_t offset); | |
101 static ngx_int_t ngx_http_upstream_copy_last_modified(ngx_http_request_t *r, | 101 static ngx_int_t ngx_http_upstream_copy_last_modified(ngx_http_request_t *r, |
102 ngx_table_elt_t *h, ngx_uint_t offset); | 102 ngx_table_elt_t *h, ngx_uint_t offset); |
103 static ngx_int_t ngx_http_upstream_rewrite_location(ngx_http_request_t *r, | 103 static ngx_int_t ngx_http_upstream_rewrite_location(ngx_http_request_t *r, |
104 ngx_table_elt_t *h, ngx_uint_t offset); | 104 ngx_table_elt_t *h, ngx_uint_t offset); |
105 static ngx_int_t ngx_http_upstream_rewrite_refresh(ngx_http_request_t *r, | 105 static ngx_int_t ngx_http_upstream_rewrite_refresh(ngx_http_request_t *r, |
147 ngx_http_upstream_process_header_line, | 147 ngx_http_upstream_process_header_line, |
148 offsetof(ngx_http_upstream_headers_in_t, content_type), | 148 offsetof(ngx_http_upstream_headers_in_t, content_type), |
149 ngx_http_upstream_copy_content_type, 0, 1 }, | 149 ngx_http_upstream_copy_content_type, 0, 1 }, |
150 | 150 |
151 { ngx_string("Content-Length"), | 151 { ngx_string("Content-Length"), |
152 ngx_http_upstream_process_header_line, | 152 ngx_http_upstream_process_content_length, |
153 offsetof(ngx_http_upstream_headers_in_t, content_length), | 153 offsetof(ngx_http_upstream_headers_in_t, content_length), |
154 ngx_http_upstream_copy_content_length, 0, 0 }, | 154 ngx_http_upstream_ignore_header_line, 0, 0 }, |
155 | 155 |
156 { ngx_string("Date"), | 156 { ngx_string("Date"), |
157 ngx_http_upstream_process_header_line, | 157 ngx_http_upstream_process_header_line, |
158 offsetof(ngx_http_upstream_headers_in_t, date), | 158 offsetof(ngx_http_upstream_headers_in_t, date), |
159 ngx_http_upstream_copy_header_line, | 159 ngx_http_upstream_copy_header_line, |
394 | 394 |
395 #if (NGX_HTTP_CACHE) | 395 #if (NGX_HTTP_CACHE) |
396 r->cache = NULL; | 396 r->cache = NULL; |
397 #endif | 397 #endif |
398 | 398 |
399 u->headers_in.content_length_n = -1; | |
400 | |
399 return NGX_OK; | 401 return NGX_OK; |
400 } | 402 } |
401 | 403 |
402 | 404 |
403 void | 405 void |
798 | 800 |
799 u->buffer = *c->buf; | 801 u->buffer = *c->buf; |
800 u->buffer.pos += c->header_start; | 802 u->buffer.pos += c->header_start; |
801 | 803 |
802 ngx_memzero(&u->headers_in, sizeof(ngx_http_upstream_headers_in_t)); | 804 ngx_memzero(&u->headers_in, sizeof(ngx_http_upstream_headers_in_t)); |
805 u->headers_in.content_length_n = -1; | |
803 | 806 |
804 if (ngx_list_init(&u->headers_in.headers, r->pool, 8, | 807 if (ngx_list_init(&u->headers_in.headers, r->pool, 8, |
805 sizeof(ngx_table_elt_t)) | 808 sizeof(ngx_table_elt_t)) |
806 != NGX_OK) | 809 != NGX_OK) |
807 { | 810 { |
1293 if (u->reinit_request(r) != NGX_OK) { | 1296 if (u->reinit_request(r) != NGX_OK) { |
1294 return NGX_ERROR; | 1297 return NGX_ERROR; |
1295 } | 1298 } |
1296 | 1299 |
1297 ngx_memzero(&u->headers_in, sizeof(ngx_http_upstream_headers_in_t)); | 1300 ngx_memzero(&u->headers_in, sizeof(ngx_http_upstream_headers_in_t)); |
1301 u->headers_in.content_length_n = -1; | |
1298 | 1302 |
1299 if (ngx_list_init(&u->headers_in.headers, r->pool, 8, | 1303 if (ngx_list_init(&u->headers_in.headers, r->pool, 8, |
1300 sizeof(ngx_table_elt_t)) | 1304 sizeof(ngx_table_elt_t)) |
1301 != NGX_OK) | 1305 != NGX_OK) |
1302 { | 1306 { |
1934 } | 1938 } |
1935 | 1939 |
1936 r->headers_out.status = u->headers_in.status_n; | 1940 r->headers_out.status = u->headers_in.status_n; |
1937 r->headers_out.status_line = u->headers_in.status_line; | 1941 r->headers_out.status_line = u->headers_in.status_line; |
1938 | 1942 |
1939 u->headers_in.content_length_n = r->headers_out.content_length_n; | 1943 r->headers_out.content_length_n = u->headers_in.content_length_n; |
1940 | 1944 |
1941 if (r->headers_out.content_length_n != -1) { | 1945 if (u->headers_in.content_length_n != -1) { |
1942 u->length = (size_t) r->headers_out.content_length_n; | 1946 u->length = (size_t) u->headers_in.content_length_n; |
1943 | 1947 |
1944 } else { | 1948 } else { |
1945 u->length = NGX_MAX_SIZE_T_VALUE; | 1949 u->length = NGX_MAX_SIZE_T_VALUE; |
1946 } | 1950 } |
1947 | 1951 |
3076 return NGX_OK; | 3080 return NGX_OK; |
3077 } | 3081 } |
3078 | 3082 |
3079 | 3083 |
3080 static ngx_int_t | 3084 static ngx_int_t |
3085 ngx_http_upstream_process_content_length(ngx_http_request_t *r, | |
3086 ngx_table_elt_t *h, ngx_uint_t offset) | |
3087 { | |
3088 ngx_http_upstream_t *u; | |
3089 | |
3090 u = r->upstream; | |
3091 | |
3092 u->headers_in.content_length = h; | |
3093 u->headers_in.content_length_n = ngx_atoof(h->value.data, h->value.len); | |
3094 | |
3095 return NGX_OK; | |
3096 } | |
3097 | |
3098 | |
3099 static ngx_int_t | |
3081 ngx_http_upstream_process_set_cookie(ngx_http_request_t *r, ngx_table_elt_t *h, | 3100 ngx_http_upstream_process_set_cookie(ngx_http_request_t *r, ngx_table_elt_t *h, |
3082 ngx_uint_t offset) | 3101 ngx_uint_t offset) |
3083 { | 3102 { |
3084 #if (NGX_HTTP_CACHE) | 3103 #if (NGX_HTTP_CACHE) |
3085 ngx_http_upstream_t *u; | 3104 ngx_http_upstream_t *u; |
3438 r->headers_out.charset.len = last - p; | 3457 r->headers_out.charset.len = last - p; |
3439 r->headers_out.charset.data = p; | 3458 r->headers_out.charset.data = p; |
3440 | 3459 |
3441 return NGX_OK; | 3460 return NGX_OK; |
3442 } | 3461 } |
3443 | |
3444 return NGX_OK; | |
3445 } | |
3446 | |
3447 | |
3448 static ngx_int_t | |
3449 ngx_http_upstream_copy_content_length(ngx_http_request_t *r, ngx_table_elt_t *h, | |
3450 ngx_uint_t offset) | |
3451 { | |
3452 ngx_table_elt_t *ho; | |
3453 | |
3454 ho = ngx_list_push(&r->headers_out.headers); | |
3455 if (ho == NULL) { | |
3456 return NGX_ERROR; | |
3457 } | |
3458 | |
3459 *ho = *h; | |
3460 | |
3461 r->headers_out.content_length = ho; | |
3462 r->headers_out.content_length_n = ngx_atoof(h->value.data, h->value.len); | |
3463 | 3462 |
3464 return NGX_OK; | 3463 return NGX_OK; |
3465 } | 3464 } |
3466 | 3465 |
3467 | 3466 |