Mercurial > hg > nginx
annotate src/http/ngx_http_upstream.c @ 4118:dbddec65fdab
Upstream: r->upstream->length type change to off_t.
Previous use of size_t may cause wierd effects on 32bit platforms with certain
big responses transferred in unbuffered mode.
Nuke "if (size > u->length)" check as it's not usefull anyway (preread
body data isn't subject to this check) and now requires additional check
for u->length being positive.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 15 Sep 2011 18:43:19 +0000 |
parents | 103b0d9afe07 |
children | b66712cde67d |
rev | line source |
---|---|
479 | 1 |
2 /* | |
3 * Copyright (C) Igor Sysoev | |
4 */ | |
5 | |
6 | |
7 #include <ngx_config.h> | |
8 #include <ngx_core.h> | |
9 #include <ngx_http.h> | |
10 | |
11 | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
12 #if (NGX_HTTP_CACHE) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
13 static ngx_int_t ngx_http_upstream_cache(ngx_http_request_t *r, |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
14 ngx_http_upstream_t *u); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
15 static ngx_int_t ngx_http_upstream_cache_send(ngx_http_request_t *r, |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
16 ngx_http_upstream_t *u); |
2952 | 17 static ngx_int_t ngx_http_upstream_cache_status(ngx_http_request_t *r, |
18 ngx_http_variable_value_t *v, uintptr_t data); | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
19 #endif |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
20 |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
21 static void ngx_http_upstream_init_request(ngx_http_request_t *r); |
1658 | 22 static void ngx_http_upstream_resolve_handler(ngx_resolver_ctx_t *ctx); |
509 | 23 static void ngx_http_upstream_rd_check_broken_connection(ngx_http_request_t *r); |
24 static void ngx_http_upstream_wr_check_broken_connection(ngx_http_request_t *r); | |
25 static void ngx_http_upstream_check_broken_connection(ngx_http_request_t *r, | |
26 ngx_event_t *ev); | |
479 | 27 static void ngx_http_upstream_connect(ngx_http_request_t *r, |
487 | 28 ngx_http_upstream_t *u); |
509 | 29 static ngx_int_t ngx_http_upstream_reinit(ngx_http_request_t *r, |
487 | 30 ngx_http_upstream_t *u); |
479 | 31 static void ngx_http_upstream_send_request(ngx_http_request_t *r, |
487 | 32 ngx_http_upstream_t *u); |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
33 static void ngx_http_upstream_send_request_handler(ngx_http_request_t *r, |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
34 ngx_http_upstream_t *u); |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
35 static void ngx_http_upstream_process_header(ngx_http_request_t *r, |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
36 ngx_http_upstream_t *u); |
2268
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
37 static ngx_int_t ngx_http_upstream_test_next(ngx_http_request_t *r, |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
38 ngx_http_upstream_t *u); |
2267
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
39 static ngx_int_t ngx_http_upstream_intercept_errors(ngx_http_request_t *r, |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
40 ngx_http_upstream_t *u); |
1153
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
41 static ngx_int_t ngx_http_upstream_test_connect(ngx_connection_t *c); |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
42 static ngx_int_t ngx_http_upstream_process_headers(ngx_http_request_t *r, |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
43 ngx_http_upstream_t *u); |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
44 static void ngx_http_upstream_process_body_in_memory(ngx_http_request_t *r, |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
45 ngx_http_upstream_t *u); |
479 | 46 static void ngx_http_upstream_send_response(ngx_http_request_t *r, |
487 | 47 ngx_http_upstream_t *u); |
581 | 48 static void |
49 ngx_http_upstream_process_non_buffered_downstream(ngx_http_request_t *r); | |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
50 static void |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
51 ngx_http_upstream_process_non_buffered_upstream(ngx_http_request_t *r, |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
52 ngx_http_upstream_t *u); |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
53 static void |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
54 ngx_http_upstream_process_non_buffered_request(ngx_http_request_t *r, |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
55 ngx_uint_t do_write); |
581 | 56 static ngx_int_t ngx_http_upstream_non_buffered_filter_init(void *data); |
57 static ngx_int_t ngx_http_upstream_non_buffered_filter(void *data, | |
58 ssize_t bytes); | |
509 | 59 static void ngx_http_upstream_process_downstream(ngx_http_request_t *r); |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
60 static void ngx_http_upstream_process_upstream(ngx_http_request_t *r, |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
61 ngx_http_upstream_t *u); |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
62 static void ngx_http_upstream_process_request(ngx_http_request_t *r); |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
63 static void ngx_http_upstream_store(ngx_http_request_t *r, |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
64 ngx_http_upstream_t *u); |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
65 static void ngx_http_upstream_dummy_handler(ngx_http_request_t *r, |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
66 ngx_http_upstream_t *u); |
479 | 67 static void ngx_http_upstream_next(ngx_http_request_t *r, |
487 | 68 ngx_http_upstream_t *u, ngx_uint_t ft_type); |
569 | 69 static void ngx_http_upstream_cleanup(void *data); |
479 | 70 static void ngx_http_upstream_finalize_request(ngx_http_request_t *r, |
487 | 71 ngx_http_upstream_t *u, ngx_int_t rc); |
479 | 72 |
509 | 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); | |
4117
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
75 static ngx_int_t ngx_http_upstream_process_content_length(ngx_http_request_t *r, |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
76 ngx_table_elt_t *h, ngx_uint_t offset); |
3669
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
77 static ngx_int_t ngx_http_upstream_process_set_cookie(ngx_http_request_t *r, |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
78 ngx_table_elt_t *h, ngx_uint_t offset); |
509 | 79 static ngx_int_t |
2669
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
80 ngx_http_upstream_process_cache_control(ngx_http_request_t *r, |
509 | 81 ngx_table_elt_t *h, ngx_uint_t offset); |
82 static ngx_int_t ngx_http_upstream_ignore_header_line(ngx_http_request_t *r, | |
83 ngx_table_elt_t *h, ngx_uint_t offset); | |
2666 | 84 static ngx_int_t ngx_http_upstream_process_expires(ngx_http_request_t *r, |
85 ngx_table_elt_t *h, ngx_uint_t offset); | |
2663
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
86 static ngx_int_t ngx_http_upstream_process_accel_expires(ngx_http_request_t *r, |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
87 ngx_table_elt_t *h, ngx_uint_t offset); |
527 | 88 static ngx_int_t ngx_http_upstream_process_limit_rate(ngx_http_request_t *r, |
89 ngx_table_elt_t *h, ngx_uint_t offset); | |
649 | 90 static ngx_int_t ngx_http_upstream_process_buffering(ngx_http_request_t *r, |
509 | 91 ngx_table_elt_t *h, ngx_uint_t offset); |
657 | 92 static ngx_int_t ngx_http_upstream_process_charset(ngx_http_request_t *r, |
93 ngx_table_elt_t *h, ngx_uint_t offset); | |
649 | 94 static ngx_int_t ngx_http_upstream_copy_header_line(ngx_http_request_t *r, |
509 | 95 ngx_table_elt_t *h, ngx_uint_t offset); |
96 static ngx_int_t | |
97 ngx_http_upstream_copy_multi_header_lines(ngx_http_request_t *r, | |
98 ngx_table_elt_t *h, ngx_uint_t offset); | |
99 static ngx_int_t ngx_http_upstream_copy_content_type(ngx_http_request_t *r, | |
100 ngx_table_elt_t *h, ngx_uint_t offset); | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
101 static ngx_int_t ngx_http_upstream_copy_last_modified(ngx_http_request_t *r, |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
102 ngx_table_elt_t *h, ngx_uint_t offset); |
509 | 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); | |
105 static ngx_int_t ngx_http_upstream_rewrite_refresh(ngx_http_request_t *r, | |
106 ngx_table_elt_t *h, ngx_uint_t offset); | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
107 static ngx_int_t ngx_http_upstream_copy_allow_ranges(ngx_http_request_t *r, |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
108 ngx_table_elt_t *h, ngx_uint_t offset); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
109 |
509 | 110 #if (NGX_HTTP_GZIP) |
111 static ngx_int_t ngx_http_upstream_copy_content_encoding(ngx_http_request_t *r, | |
112 ngx_table_elt_t *h, ngx_uint_t offset); | |
113 #endif | |
114 | |
573 | 115 static ngx_int_t ngx_http_upstream_add_variables(ngx_conf_t *cf); |
1181 | 116 static ngx_int_t ngx_http_upstream_addr_variable(ngx_http_request_t *r, |
117 ngx_http_variable_value_t *v, uintptr_t data); | |
573 | 118 static ngx_int_t ngx_http_upstream_status_variable(ngx_http_request_t *r, |
119 ngx_http_variable_value_t *v, uintptr_t data); | |
120 static ngx_int_t ngx_http_upstream_response_time_variable(ngx_http_request_t *r, | |
121 ngx_http_variable_value_t *v, uintptr_t data); | |
2402 | 122 static ngx_int_t ngx_http_upstream_response_length_variable( |
123 ngx_http_request_t *r, ngx_http_variable_value_t *v, uintptr_t data); | |
573 | 124 |
651 | 125 static char *ngx_http_upstream(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy); |
126 static char *ngx_http_upstream_server(ngx_conf_t *cf, ngx_command_t *cmd, | |
127 void *conf); | |
128 | |
509 | 129 static void *ngx_http_upstream_create_main_conf(ngx_conf_t *cf); |
651 | 130 static char *ngx_http_upstream_init_main_conf(ngx_conf_t *cf, void *conf); |
509 | 131 |
577 | 132 #if (NGX_HTTP_SSL) |
591 | 133 static void ngx_http_upstream_ssl_init_connection(ngx_http_request_t *, |
134 ngx_http_upstream_t *u, ngx_connection_t *c); | |
577 | 135 static void ngx_http_upstream_ssl_handshake(ngx_connection_t *c); |
136 #endif | |
137 | |
509 | 138 |
139 ngx_http_upstream_header_t ngx_http_upstream_headers_in[] = { | |
140 | |
141 { ngx_string("Status"), | |
142 ngx_http_upstream_process_header_line, | |
143 offsetof(ngx_http_upstream_headers_in_t, status), | |
649 | 144 ngx_http_upstream_copy_header_line, 0, 0 }, |
509 | 145 |
146 { ngx_string("Content-Type"), | |
147 ngx_http_upstream_process_header_line, | |
148 offsetof(ngx_http_upstream_headers_in_t, content_type), | |
673 | 149 ngx_http_upstream_copy_content_type, 0, 1 }, |
509 | 150 |
151 { ngx_string("Content-Length"), | |
4117
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
152 ngx_http_upstream_process_content_length, |
509 | 153 offsetof(ngx_http_upstream_headers_in_t, content_length), |
4117
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
154 ngx_http_upstream_ignore_header_line, 0, 0 }, |
509 | 155 |
156 { ngx_string("Date"), | |
157 ngx_http_upstream_process_header_line, | |
158 offsetof(ngx_http_upstream_headers_in_t, date), | |
649 | 159 ngx_http_upstream_copy_header_line, |
160 offsetof(ngx_http_headers_out_t, date), 0 }, | |
509 | 161 |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
162 { ngx_string("Last-Modified"), |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
163 ngx_http_upstream_process_header_line, |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
164 offsetof(ngx_http_upstream_headers_in_t, last_modified), |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
165 ngx_http_upstream_copy_last_modified, 0, 0 }, |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
166 |
3037 | 167 { ngx_string("ETag"), |
168 ngx_http_upstream_process_header_line, | |
169 offsetof(ngx_http_upstream_headers_in_t, etag), | |
170 ngx_http_upstream_copy_header_line, | |
171 offsetof(ngx_http_headers_out_t, etag), 0 }, | |
172 | |
509 | 173 { ngx_string("Server"), |
174 ngx_http_upstream_process_header_line, | |
175 offsetof(ngx_http_upstream_headers_in_t, server), | |
649 | 176 ngx_http_upstream_copy_header_line, |
177 offsetof(ngx_http_headers_out_t, server), 0 }, | |
509 | 178 |
529 | 179 { ngx_string("WWW-Authenticate"), |
180 ngx_http_upstream_process_header_line, | |
181 offsetof(ngx_http_upstream_headers_in_t, www_authenticate), | |
182 ngx_http_upstream_copy_header_line, 0, 0 }, | |
183 | |
509 | 184 { ngx_string("Location"), |
2140
dce5ddef5af9
if upstream sent a location header without status use 302
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
185 ngx_http_upstream_process_header_line, |
dce5ddef5af9
if upstream sent a location header without status use 302
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
186 offsetof(ngx_http_upstream_headers_in_t, location), |
515 | 187 ngx_http_upstream_rewrite_location, 0, 0 }, |
509 | 188 |
189 { ngx_string("Refresh"), | |
190 ngx_http_upstream_ignore_header_line, 0, | |
515 | 191 ngx_http_upstream_rewrite_refresh, 0, 0 }, |
192 | |
193 { ngx_string("Set-Cookie"), | |
3669
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
194 ngx_http_upstream_process_set_cookie, 0, |
531 | 195 ngx_http_upstream_copy_header_line, 0, 1 }, |
196 | |
197 { ngx_string("Content-Disposition"), | |
198 ngx_http_upstream_ignore_header_line, 0, | |
199 ngx_http_upstream_copy_header_line, 0, 1 }, | |
509 | 200 |
201 { ngx_string("Cache-Control"), | |
2669
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
202 ngx_http_upstream_process_cache_control, 0, |
509 | 203 ngx_http_upstream_copy_multi_header_lines, |
515 | 204 offsetof(ngx_http_headers_out_t, cache_control), 1 }, |
509 | 205 |
573 | 206 { ngx_string("Expires"), |
2666 | 207 ngx_http_upstream_process_expires, 0, |
573 | 208 ngx_http_upstream_copy_header_line, |
209 offsetof(ngx_http_headers_out_t, expires), 1 }, | |
210 | |
577 | 211 { ngx_string("Accept-Ranges"), |
212 ngx_http_upstream_process_header_line, | |
213 offsetof(ngx_http_upstream_headers_in_t, accept_ranges), | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
214 ngx_http_upstream_copy_allow_ranges, |
577 | 215 offsetof(ngx_http_headers_out_t, accept_ranges), 1 }, |
216 | |
509 | 217 { ngx_string("Connection"), |
218 ngx_http_upstream_ignore_header_line, 0, | |
515 | 219 ngx_http_upstream_ignore_header_line, 0, 0 }, |
509 | 220 |
641 | 221 { ngx_string("Keep-Alive"), |
222 ngx_http_upstream_ignore_header_line, 0, | |
223 ngx_http_upstream_ignore_header_line, 0, 0 }, | |
224 | |
509 | 225 { ngx_string("X-Powered-By"), |
226 ngx_http_upstream_ignore_header_line, 0, | |
649 | 227 ngx_http_upstream_copy_header_line, 0, 0 }, |
509 | 228 |
229 { ngx_string("X-Accel-Expires"), | |
2664 | 230 ngx_http_upstream_process_accel_expires, 0, |
649 | 231 ngx_http_upstream_copy_header_line, 0, 0 }, |
515 | 232 |
233 { ngx_string("X-Accel-Redirect"), | |
234 ngx_http_upstream_process_header_line, | |
235 offsetof(ngx_http_upstream_headers_in_t, x_accel_redirect), | |
3003
b630e7d095b3
allow to proxy_pass_header/fastcgi_pass_header "X-Accel-Redirect",
Igor Sysoev <igor@sysoev.ru>
parents:
2971
diff
changeset
|
236 ngx_http_upstream_copy_header_line, 0, 0 }, |
509 | 237 |
527 | 238 { ngx_string("X-Accel-Limit-Rate"), |
239 ngx_http_upstream_process_limit_rate, 0, | |
3003
b630e7d095b3
allow to proxy_pass_header/fastcgi_pass_header "X-Accel-Redirect",
Igor Sysoev <igor@sysoev.ru>
parents:
2971
diff
changeset
|
240 ngx_http_upstream_copy_header_line, 0, 0 }, |
527 | 241 |
649 | 242 { ngx_string("X-Accel-Buffering"), |
243 ngx_http_upstream_process_buffering, 0, | |
3003
b630e7d095b3
allow to proxy_pass_header/fastcgi_pass_header "X-Accel-Redirect",
Igor Sysoev <igor@sysoev.ru>
parents:
2971
diff
changeset
|
244 ngx_http_upstream_copy_header_line, 0, 0 }, |
649 | 245 |
657 | 246 { ngx_string("X-Accel-Charset"), |
247 ngx_http_upstream_process_charset, 0, | |
3003
b630e7d095b3
allow to proxy_pass_header/fastcgi_pass_header "X-Accel-Redirect",
Igor Sysoev <igor@sysoev.ru>
parents:
2971
diff
changeset
|
248 ngx_http_upstream_copy_header_line, 0, 0 }, |
657 | 249 |
509 | 250 #if (NGX_HTTP_GZIP) |
251 { ngx_string("Content-Encoding"), | |
252 ngx_http_upstream_process_header_line, | |
253 offsetof(ngx_http_upstream_headers_in_t, content_encoding), | |
515 | 254 ngx_http_upstream_copy_content_encoding, 0, 0 }, |
509 | 255 #endif |
256 | |
515 | 257 { ngx_null_string, NULL, 0, NULL, 0, 0 } |
509 | 258 }; |
479 | 259 |
260 | |
651 | 261 static ngx_command_t ngx_http_upstream_commands[] = { |
262 | |
263 { ngx_string("upstream"), | |
264 NGX_HTTP_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_TAKE1, | |
265 ngx_http_upstream, | |
266 0, | |
267 0, | |
268 NULL }, | |
269 | |
270 { ngx_string("server"), | |
884 | 271 NGX_HTTP_UPS_CONF|NGX_CONF_1MORE, |
651 | 272 ngx_http_upstream_server, |
273 NGX_HTTP_SRV_CONF_OFFSET, | |
274 0, | |
275 NULL }, | |
276 | |
277 ngx_null_command | |
278 }; | |
279 | |
280 | |
281 static ngx_http_module_t ngx_http_upstream_module_ctx = { | |
573 | 282 ngx_http_upstream_add_variables, /* preconfiguration */ |
509 | 283 NULL, /* postconfiguration */ |
284 | |
285 ngx_http_upstream_create_main_conf, /* create main configuration */ | |
651 | 286 ngx_http_upstream_init_main_conf, /* init main configuration */ |
479 | 287 |
288 NULL, /* create server configuration */ | |
289 NULL, /* merge server configuration */ | |
290 | |
291 NULL, /* create location configuration */ | |
292 NULL /* merge location configuration */ | |
293 }; | |
577 | 294 |
479 | 295 |
296 ngx_module_t ngx_http_upstream_module = { | |
509 | 297 NGX_MODULE_V1, |
479 | 298 &ngx_http_upstream_module_ctx, /* module context */ |
651 | 299 ngx_http_upstream_commands, /* module directives */ |
479 | 300 NGX_HTTP_MODULE, /* module type */ |
541 | 301 NULL, /* init master */ |
479 | 302 NULL, /* init module */ |
541 | 303 NULL, /* init process */ |
304 NULL, /* init thread */ | |
305 NULL, /* exit thread */ | |
306 NULL, /* exit process */ | |
307 NULL, /* exit master */ | |
308 NGX_MODULE_V1_PADDING | |
479 | 309 }; |
310 | |
311 | |
573 | 312 static ngx_http_variable_t ngx_http_upstream_vars[] = { |
313 | |
1181 | 314 { ngx_string("upstream_addr"), NULL, |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
315 ngx_http_upstream_addr_variable, 0, |
3898
bd1222fb0192
allow to use $upstream_... variables in SSI
Igor Sysoev <igor@sysoev.ru>
parents:
3879
diff
changeset
|
316 NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
1181 | 317 |
637 | 318 { ngx_string("upstream_status"), NULL, |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
319 ngx_http_upstream_status_variable, 0, |
3898
bd1222fb0192
allow to use $upstream_... variables in SSI
Igor Sysoev <igor@sysoev.ru>
parents:
3879
diff
changeset
|
320 NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
573 | 321 |
637 | 322 { ngx_string("upstream_response_time"), NULL, |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
323 ngx_http_upstream_response_time_variable, 0, |
3898
bd1222fb0192
allow to use $upstream_... variables in SSI
Igor Sysoev <igor@sysoev.ru>
parents:
3879
diff
changeset
|
324 NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
573 | 325 |
2402 | 326 { ngx_string("upstream_response_length"), NULL, |
327 ngx_http_upstream_response_length_variable, 0, | |
3898
bd1222fb0192
allow to use $upstream_... variables in SSI
Igor Sysoev <igor@sysoev.ru>
parents:
3879
diff
changeset
|
328 NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
2402 | 329 |
2957
b4f39842523b
fix building --without-http-cache, broken in r2953
Igor Sysoev <igor@sysoev.ru>
parents:
2953
diff
changeset
|
330 #if (NGX_HTTP_CACHE) |
b4f39842523b
fix building --without-http-cache, broken in r2953
Igor Sysoev <igor@sysoev.ru>
parents:
2953
diff
changeset
|
331 |
2952 | 332 { ngx_string("upstream_cache_status"), NULL, |
333 ngx_http_upstream_cache_status, 0, | |
3898
bd1222fb0192
allow to use $upstream_... variables in SSI
Igor Sysoev <igor@sysoev.ru>
parents:
3879
diff
changeset
|
334 NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
2952 | 335 |
2957
b4f39842523b
fix building --without-http-cache, broken in r2953
Igor Sysoev <igor@sysoev.ru>
parents:
2953
diff
changeset
|
336 #endif |
b4f39842523b
fix building --without-http-cache, broken in r2953
Igor Sysoev <igor@sysoev.ru>
parents:
2953
diff
changeset
|
337 |
637 | 338 { ngx_null_string, NULL, NULL, 0, 0, 0 } |
573 | 339 }; |
340 | |
341 | |
2268
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
342 static ngx_http_upstream_next_t ngx_http_upstream_next_errors[] = { |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
343 { 500, NGX_HTTP_UPSTREAM_FT_HTTP_500 }, |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
344 { 502, NGX_HTTP_UPSTREAM_FT_HTTP_502 }, |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
345 { 503, NGX_HTTP_UPSTREAM_FT_HTTP_503 }, |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
346 { 504, NGX_HTTP_UPSTREAM_FT_HTTP_504 }, |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
347 { 404, NGX_HTTP_UPSTREAM_FT_HTTP_404 }, |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
348 { 0, 0 } |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
349 }; |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
350 |
2875
6e1941b321b7
proxy_cache_methods and fastcgi_cache_methods
Igor Sysoev <igor@sysoev.ru>
parents:
2874
diff
changeset
|
351 |
6e1941b321b7
proxy_cache_methods and fastcgi_cache_methods
Igor Sysoev <igor@sysoev.ru>
parents:
2874
diff
changeset
|
352 ngx_conf_bitmask_t ngx_http_upstream_cache_method_mask[] = { |
6e1941b321b7
proxy_cache_methods and fastcgi_cache_methods
Igor Sysoev <igor@sysoev.ru>
parents:
2874
diff
changeset
|
353 { ngx_string("GET"), NGX_HTTP_GET}, |
6e1941b321b7
proxy_cache_methods and fastcgi_cache_methods
Igor Sysoev <igor@sysoev.ru>
parents:
2874
diff
changeset
|
354 { ngx_string("HEAD"), NGX_HTTP_HEAD }, |
6e1941b321b7
proxy_cache_methods and fastcgi_cache_methods
Igor Sysoev <igor@sysoev.ru>
parents:
2874
diff
changeset
|
355 { ngx_string("POST"), NGX_HTTP_POST }, |
6e1941b321b7
proxy_cache_methods and fastcgi_cache_methods
Igor Sysoev <igor@sysoev.ru>
parents:
2874
diff
changeset
|
356 { ngx_null_string, 0 } |
6e1941b321b7
proxy_cache_methods and fastcgi_cache_methods
Igor Sysoev <igor@sysoev.ru>
parents:
2874
diff
changeset
|
357 }; |
6e1941b321b7
proxy_cache_methods and fastcgi_cache_methods
Igor Sysoev <igor@sysoev.ru>
parents:
2874
diff
changeset
|
358 |
6e1941b321b7
proxy_cache_methods and fastcgi_cache_methods
Igor Sysoev <igor@sysoev.ru>
parents:
2874
diff
changeset
|
359 |
3667
12bd9e26fadb
use shared ngx_http_upstream_ignore_headers_masks[]
Igor Sysoev <igor@sysoev.ru>
parents:
3527
diff
changeset
|
360 ngx_conf_bitmask_t ngx_http_upstream_ignore_headers_masks[] = { |
12bd9e26fadb
use shared ngx_http_upstream_ignore_headers_masks[]
Igor Sysoev <igor@sysoev.ru>
parents:
3527
diff
changeset
|
361 { ngx_string("X-Accel-Redirect"), NGX_HTTP_UPSTREAM_IGN_XA_REDIRECT }, |
12bd9e26fadb
use shared ngx_http_upstream_ignore_headers_masks[]
Igor Sysoev <igor@sysoev.ru>
parents:
3527
diff
changeset
|
362 { ngx_string("X-Accel-Expires"), NGX_HTTP_UPSTREAM_IGN_XA_EXPIRES }, |
12bd9e26fadb
use shared ngx_http_upstream_ignore_headers_masks[]
Igor Sysoev <igor@sysoev.ru>
parents:
3527
diff
changeset
|
363 { ngx_string("Expires"), NGX_HTTP_UPSTREAM_IGN_EXPIRES }, |
12bd9e26fadb
use shared ngx_http_upstream_ignore_headers_masks[]
Igor Sysoev <igor@sysoev.ru>
parents:
3527
diff
changeset
|
364 { ngx_string("Cache-Control"), NGX_HTTP_UPSTREAM_IGN_CACHE_CONTROL }, |
3669
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
365 { ngx_string("Set-Cookie"), NGX_HTTP_UPSTREAM_IGN_SET_COOKIE }, |
3667
12bd9e26fadb
use shared ngx_http_upstream_ignore_headers_masks[]
Igor Sysoev <igor@sysoev.ru>
parents:
3527
diff
changeset
|
366 { ngx_null_string, 0 } |
12bd9e26fadb
use shared ngx_http_upstream_ignore_headers_masks[]
Igor Sysoev <igor@sysoev.ru>
parents:
3527
diff
changeset
|
367 }; |
12bd9e26fadb
use shared ngx_http_upstream_ignore_headers_masks[]
Igor Sysoev <igor@sysoev.ru>
parents:
3527
diff
changeset
|
368 |
12bd9e26fadb
use shared ngx_http_upstream_ignore_headers_masks[]
Igor Sysoev <igor@sysoev.ru>
parents:
3527
diff
changeset
|
369 |
3006
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
370 ngx_int_t |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
371 ngx_http_upstream_create(ngx_http_request_t *r) |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
372 { |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
373 ngx_http_upstream_t *u; |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
374 |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
375 u = r->upstream; |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
376 |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
377 if (u && u->cleanup) { |
3112
5ddc9458e4bb
increase request counter before an upstream cleanup because the cleanup
Igor Sysoev <igor@sysoev.ru>
parents:
3083
diff
changeset
|
378 r->main->count++; |
3006
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
379 ngx_http_upstream_cleanup(r); |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
380 } |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
381 |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
382 u = ngx_pcalloc(r->pool, sizeof(ngx_http_upstream_t)); |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
383 if (u == NULL) { |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
384 return NGX_ERROR; |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
385 } |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
386 |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
387 r->upstream = u; |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
388 |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
389 u->peer.log = r->connection->log; |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
390 u->peer.log_error = NGX_ERROR_ERR; |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
391 #if (NGX_THREADS) |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
392 u->peer.lock = &r->connection->lock; |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
393 #endif |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
394 |
3056
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
395 #if (NGX_HTTP_CACHE) |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
396 r->cache = NULL; |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
397 #endif |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
398 |
4117
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
399 u->headers_in.content_length_n = -1; |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
400 |
3006
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
401 return NGX_OK; |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
402 } |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
403 |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
404 |
487 | 405 void |
406 ngx_http_upstream_init(ngx_http_request_t *r) | |
479 | 407 { |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
408 ngx_connection_t *c; |
479 | 409 |
410 c = r->connection; | |
411 | |
412 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
413 "http init upstream, client timer: %d", c->read->timer_set); | |
414 | |
415 if (c->read->timer_set) { | |
416 ngx_del_timer(c->read); | |
417 } | |
418 | |
419 if (ngx_event_flags & NGX_USE_CLEAR_EVENT) { | |
420 | |
421 if (!c->write->active) { | |
531 | 422 if (ngx_add_event(c->write, NGX_WRITE_EVENT, NGX_CLEAR_EVENT) |
423 == NGX_ERROR) | |
479 | 424 { |
425 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | |
426 return; | |
427 } | |
428 } | |
429 } | |
430 | |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
431 ngx_http_upstream_init_request(r); |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
432 } |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
433 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
434 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
435 static void |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
436 ngx_http_upstream_init_request(ngx_http_request_t *r) |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
437 { |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
438 ngx_str_t *host; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
439 ngx_uint_t i; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
440 ngx_resolver_ctx_t *ctx, temp; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
441 ngx_http_cleanup_t *cln; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
442 ngx_http_upstream_t *u; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
443 ngx_http_core_loc_conf_t *clcf; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
444 ngx_http_upstream_srv_conf_t *uscf, **uscfp; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
445 ngx_http_upstream_main_conf_t *umcf; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
446 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
447 if (r->aio) { |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
448 return; |
537 | 449 } |
509 | 450 |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
451 u = r->upstream; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
452 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
453 #if (NGX_HTTP_CACHE) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
454 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
455 if (u->conf->cache) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
456 ngx_int_t rc; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
457 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
458 rc = ngx_http_upstream_cache(r, u); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
459 |
3055
92b6cfaa3c27
fix sending a cached file using AIO
Igor Sysoev <igor@sysoev.ru>
parents:
3053
diff
changeset
|
460 if (rc == NGX_BUSY) { |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
461 r->write_event_handler = ngx_http_upstream_init_request; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
462 return; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
463 } |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
464 |
3055
92b6cfaa3c27
fix sending a cached file using AIO
Igor Sysoev <igor@sysoev.ru>
parents:
3053
diff
changeset
|
465 r->write_event_handler = ngx_http_request_empty_handler; |
92b6cfaa3c27
fix sending a cached file using AIO
Igor Sysoev <igor@sysoev.ru>
parents:
3053
diff
changeset
|
466 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
467 if (rc == NGX_DONE) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
468 return; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
469 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
470 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
471 if (rc != NGX_DECLINED) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
472 ngx_http_finalize_request(r, rc); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
473 return; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
474 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
475 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
476 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
477 #endif |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
478 |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
479 u->store = (u->conf->store || u->conf->store_lengths); |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
480 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
481 if (!u->store && !r->post_action && !u->conf->ignore_client_abort) { |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
482 r->read_event_handler = ngx_http_upstream_rd_check_broken_connection; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
483 r->write_event_handler = ngx_http_upstream_wr_check_broken_connection; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
484 } |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
485 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
486 if (r->request_body) { |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
487 u->request_bufs = r->request_body->bufs; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
488 } |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
489 |
537 | 490 if (u->create_request(r) != NGX_OK) { |
479 | 491 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); |
492 return; | |
493 } | |
494 | |
3271
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3198
diff
changeset
|
495 u->peer.local = u->conf->local; |
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3198
diff
changeset
|
496 |
509 | 497 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
479 | 498 |
3053 | 499 u->output.alignment = clcf->directio_alignment; |
479 | 500 u->output.pool = r->pool; |
501 u->output.bufs.num = 1; | |
509 | 502 u->output.bufs.size = clcf->client_body_buffer_size; |
479 | 503 u->output.output_filter = ngx_chain_writer; |
504 u->output.filter_ctx = &u->writer; | |
505 | |
506 u->writer.pool = r->pool; | |
507 | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
508 if (r->upstream_states == NULL) { |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
509 |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
510 r->upstream_states = ngx_array_create(r->pool, 1, |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
511 sizeof(ngx_http_upstream_state_t)); |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
512 if (r->upstream_states == NULL) { |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
513 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
514 return; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
515 } |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
516 |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
517 } else { |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
518 |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
519 u->state = ngx_array_push(r->upstream_states); |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
520 if (u->state == NULL) { |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
521 ngx_http_upstream_finalize_request(r, u, |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
522 NGX_HTTP_INTERNAL_SERVER_ERROR); |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
523 return; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
524 } |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
525 |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
526 ngx_memzero(u->state, sizeof(ngx_http_upstream_state_t)); |
479 | 527 } |
528 | |
593 | 529 cln = ngx_http_cleanup_add(r, 0); |
569 | 530 if (cln == NULL) { |
531 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | |
532 return; | |
533 } | |
534 | |
535 cln->handler = ngx_http_upstream_cleanup; | |
536 cln->data = r; | |
537 u->cleanup = &cln->handler; | |
538 | |
1658 | 539 if (u->resolved == NULL) { |
540 | |
541 uscf = u->conf->upstream; | |
542 | |
543 } else { | |
544 | |
2422
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2413
diff
changeset
|
545 if (u->resolved->sockaddr) { |
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2413
diff
changeset
|
546 |
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2413
diff
changeset
|
547 if (ngx_http_upstream_create_round_robin_peer(r, u->resolved) |
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2413
diff
changeset
|
548 != NGX_OK) |
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2413
diff
changeset
|
549 { |
3169
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
550 ngx_http_upstream_finalize_request(r, u, |
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
551 NGX_HTTP_INTERNAL_SERVER_ERROR); |
2422
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2413
diff
changeset
|
552 return; |
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2413
diff
changeset
|
553 } |
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2413
diff
changeset
|
554 |
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2413
diff
changeset
|
555 ngx_http_upstream_connect(r, u); |
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2413
diff
changeset
|
556 |
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2413
diff
changeset
|
557 return; |
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2413
diff
changeset
|
558 } |
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2413
diff
changeset
|
559 |
1705 | 560 host = &u->resolved->host; |
1658 | 561 |
562 umcf = ngx_http_get_module_main_conf(r, ngx_http_upstream_module); | |
563 | |
564 uscfp = umcf->upstreams.elts; | |
565 | |
566 for (i = 0; i < umcf->upstreams.nelts; i++) { | |
567 | |
568 uscf = uscfp[i]; | |
569 | |
570 if (uscf->host.len == host->len | |
2285 | 571 && ((uscf->port == 0 && u->resolved->no_port) |
1912 | 572 || uscf->port == u->resolved->port) |
1658 | 573 && ngx_memcmp(uscf->host.data, host->data, host->len) == 0) |
574 { | |
575 goto found; | |
576 } | |
577 } | |
578 | |
3879
502a6b0acf3f
fix case when a host in fastcgi_pass, scgi_pass, and uwsgi_pass
Igor Sysoev <igor@sysoev.ru>
parents:
3713
diff
changeset
|
579 if (u->resolved->port == 0) { |
502a6b0acf3f
fix case when a host in fastcgi_pass, scgi_pass, and uwsgi_pass
Igor Sysoev <igor@sysoev.ru>
parents:
3713
diff
changeset
|
580 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
502a6b0acf3f
fix case when a host in fastcgi_pass, scgi_pass, and uwsgi_pass
Igor Sysoev <igor@sysoev.ru>
parents:
3713
diff
changeset
|
581 "no port in upstream \"%V\"", host); |
502a6b0acf3f
fix case when a host in fastcgi_pass, scgi_pass, and uwsgi_pass
Igor Sysoev <igor@sysoev.ru>
parents:
3713
diff
changeset
|
582 ngx_http_upstream_finalize_request(r, u, |
502a6b0acf3f
fix case when a host in fastcgi_pass, scgi_pass, and uwsgi_pass
Igor Sysoev <igor@sysoev.ru>
parents:
3713
diff
changeset
|
583 NGX_HTTP_INTERNAL_SERVER_ERROR); |
502a6b0acf3f
fix case when a host in fastcgi_pass, scgi_pass, and uwsgi_pass
Igor Sysoev <igor@sysoev.ru>
parents:
3713
diff
changeset
|
584 return; |
502a6b0acf3f
fix case when a host in fastcgi_pass, scgi_pass, and uwsgi_pass
Igor Sysoev <igor@sysoev.ru>
parents:
3713
diff
changeset
|
585 } |
502a6b0acf3f
fix case when a host in fastcgi_pass, scgi_pass, and uwsgi_pass
Igor Sysoev <igor@sysoev.ru>
parents:
3713
diff
changeset
|
586 |
1658 | 587 temp.name = *host; |
588 | |
589 ctx = ngx_resolve_start(clcf->resolver, &temp); | |
590 if (ctx == NULL) { | |
3169
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
591 ngx_http_upstream_finalize_request(r, u, |
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
592 NGX_HTTP_INTERNAL_SERVER_ERROR); |
1658 | 593 return; |
594 } | |
595 | |
1683
1e0b028055ec
allow to use IP addresses without defined resolver
Igor Sysoev <igor@sysoev.ru>
parents:
1658
diff
changeset
|
596 if (ctx == NGX_NO_RESOLVER) { |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
597 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
1683
1e0b028055ec
allow to use IP addresses without defined resolver
Igor Sysoev <igor@sysoev.ru>
parents:
1658
diff
changeset
|
598 "no resolver defined to resolve %V", host); |
1e0b028055ec
allow to use IP addresses without defined resolver
Igor Sysoev <igor@sysoev.ru>
parents:
1658
diff
changeset
|
599 |
3169
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
600 ngx_http_upstream_finalize_request(r, u, NGX_HTTP_BAD_GATEWAY); |
1683
1e0b028055ec
allow to use IP addresses without defined resolver
Igor Sysoev <igor@sysoev.ru>
parents:
1658
diff
changeset
|
601 return; |
1e0b028055ec
allow to use IP addresses without defined resolver
Igor Sysoev <igor@sysoev.ru>
parents:
1658
diff
changeset
|
602 } |
1e0b028055ec
allow to use IP addresses without defined resolver
Igor Sysoev <igor@sysoev.ru>
parents:
1658
diff
changeset
|
603 |
1658 | 604 ctx->name = *host; |
605 ctx->type = NGX_RESOLVE_A; | |
606 ctx->handler = ngx_http_upstream_resolve_handler; | |
607 ctx->data = r; | |
608 ctx->timeout = clcf->resolver_timeout; | |
609 | |
1959
4f16186f5603
quick resolving handles u->resolved->ctx by itself
Igor Sysoev <igor@sysoev.ru>
parents:
1958
diff
changeset
|
610 u->resolved->ctx = ctx; |
4f16186f5603
quick resolving handles u->resolved->ctx by itself
Igor Sysoev <igor@sysoev.ru>
parents:
1958
diff
changeset
|
611 |
1658 | 612 if (ngx_resolve_name(ctx) != NGX_OK) { |
1959
4f16186f5603
quick resolving handles u->resolved->ctx by itself
Igor Sysoev <igor@sysoev.ru>
parents:
1958
diff
changeset
|
613 u->resolved->ctx = NULL; |
3169
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
614 ngx_http_upstream_finalize_request(r, u, |
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
615 NGX_HTTP_INTERNAL_SERVER_ERROR); |
1658 | 616 return; |
617 } | |
618 | |
619 return; | |
620 } | |
621 | |
622 found: | |
623 | |
624 if (uscf->peer.init(r, uscf) != NGX_OK) { | |
3169
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
625 ngx_http_upstream_finalize_request(r, u, |
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
626 NGX_HTTP_INTERNAL_SERVER_ERROR); |
1658 | 627 return; |
628 } | |
629 | |
479 | 630 ngx_http_upstream_connect(r, u); |
631 } | |
632 | |
633 | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
634 #if (NGX_HTTP_CACHE) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
635 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
636 static ngx_int_t |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
637 ngx_http_upstream_cache(ngx_http_request_t *r, ngx_http_upstream_t *u) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
638 { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
639 ngx_int_t rc; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
640 ngx_http_cache_t *c; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
641 |
3056
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
642 c = r->cache; |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
643 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
644 if (c == NULL) { |
3056
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
645 |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
646 if (!(r->method & u->conf->cache_methods)) { |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
647 return NGX_DECLINED; |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
648 } |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
649 |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
650 if (r->method & NGX_HTTP_HEAD) { |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
651 u->method = ngx_http_core_get_method; |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
652 } |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
653 |
3698
d11227f0107f
rename ngx_http_file_cache_create() to ngx_http_file_cache_new()
Igor Sysoev <igor@sysoev.ru>
parents:
3697
diff
changeset
|
654 if (ngx_http_file_cache_new(r) != NGX_OK) { |
3056
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
655 return NGX_ERROR; |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
656 } |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
657 |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
658 if (u->create_key(r) != NGX_OK) { |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
659 return NGX_ERROR; |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
660 } |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
661 |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
662 /* TODO: add keys */ |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
663 |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
664 ngx_http_file_cache_create_key(r); |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
665 |
3976
215fe9223419
update r3945 with more descriptive error message
Igor Sysoev <igor@sysoev.ru>
parents:
3963
diff
changeset
|
666 if (r->cache->header_start + 256 >= u->conf->buffer_size) { |
3944
f1f194ceab16
fix segfault if cache key is larger than upstream buffer size
Igor Sysoev <igor@sysoev.ru>
parents:
3940
diff
changeset
|
667 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
3976
215fe9223419
update r3945 with more descriptive error message
Igor Sysoev <igor@sysoev.ru>
parents:
3963
diff
changeset
|
668 "%V_buffer_size %uz is not enough for cache key, " |
215fe9223419
update r3945 with more descriptive error message
Igor Sysoev <igor@sysoev.ru>
parents:
3963
diff
changeset
|
669 "it should increased at least to %uz", |
215fe9223419
update r3945 with more descriptive error message
Igor Sysoev <igor@sysoev.ru>
parents:
3963
diff
changeset
|
670 &u->conf->module, u->conf->buffer_size, |
215fe9223419
update r3945 with more descriptive error message
Igor Sysoev <igor@sysoev.ru>
parents:
3963
diff
changeset
|
671 ngx_align(r->cache->header_start + 256, 1024)); |
3944
f1f194ceab16
fix segfault if cache key is larger than upstream buffer size
Igor Sysoev <igor@sysoev.ru>
parents:
3940
diff
changeset
|
672 |
f1f194ceab16
fix segfault if cache key is larger than upstream buffer size
Igor Sysoev <igor@sysoev.ru>
parents:
3940
diff
changeset
|
673 r->cache = NULL; |
f1f194ceab16
fix segfault if cache key is larger than upstream buffer size
Igor Sysoev <igor@sysoev.ru>
parents:
3940
diff
changeset
|
674 return NGX_DECLINED; |
f1f194ceab16
fix segfault if cache key is larger than upstream buffer size
Igor Sysoev <igor@sysoev.ru>
parents:
3940
diff
changeset
|
675 } |
f1f194ceab16
fix segfault if cache key is larger than upstream buffer size
Igor Sysoev <igor@sysoev.ru>
parents:
3940
diff
changeset
|
676 |
3917
2a70484a6580
fix a broken cached response if bypass/no_cache directive values are different,
Igor Sysoev <igor@sysoev.ru>
parents:
3898
diff
changeset
|
677 switch (ngx_http_test_predicates(r, u->conf->cache_bypass)) { |
2a70484a6580
fix a broken cached response if bypass/no_cache directive values are different,
Igor Sysoev <igor@sysoev.ru>
parents:
3898
diff
changeset
|
678 |
2a70484a6580
fix a broken cached response if bypass/no_cache directive values are different,
Igor Sysoev <igor@sysoev.ru>
parents:
3898
diff
changeset
|
679 case NGX_ERROR: |
2a70484a6580
fix a broken cached response if bypass/no_cache directive values are different,
Igor Sysoev <igor@sysoev.ru>
parents:
3898
diff
changeset
|
680 return NGX_ERROR; |
2a70484a6580
fix a broken cached response if bypass/no_cache directive values are different,
Igor Sysoev <igor@sysoev.ru>
parents:
3898
diff
changeset
|
681 |
2a70484a6580
fix a broken cached response if bypass/no_cache directive values are different,
Igor Sysoev <igor@sysoev.ru>
parents:
3898
diff
changeset
|
682 case NGX_DECLINED: |
2a70484a6580
fix a broken cached response if bypass/no_cache directive values are different,
Igor Sysoev <igor@sysoev.ru>
parents:
3898
diff
changeset
|
683 u->cache_status = NGX_HTTP_CACHE_BYPASS; |
2a70484a6580
fix a broken cached response if bypass/no_cache directive values are different,
Igor Sysoev <igor@sysoev.ru>
parents:
3898
diff
changeset
|
684 return NGX_DECLINED; |
2a70484a6580
fix a broken cached response if bypass/no_cache directive values are different,
Igor Sysoev <igor@sysoev.ru>
parents:
3898
diff
changeset
|
685 |
2a70484a6580
fix a broken cached response if bypass/no_cache directive values are different,
Igor Sysoev <igor@sysoev.ru>
parents:
3898
diff
changeset
|
686 default: /* NGX_OK */ |
2a70484a6580
fix a broken cached response if bypass/no_cache directive values are different,
Igor Sysoev <igor@sysoev.ru>
parents:
3898
diff
changeset
|
687 break; |
2a70484a6580
fix a broken cached response if bypass/no_cache directive values are different,
Igor Sysoev <igor@sysoev.ru>
parents:
3898
diff
changeset
|
688 } |
2a70484a6580
fix a broken cached response if bypass/no_cache directive values are different,
Igor Sysoev <igor@sysoev.ru>
parents:
3898
diff
changeset
|
689 |
3056
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
690 u->cacheable = 1; |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
691 |
3697 | 692 c = r->cache; |
693 | |
3056
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
694 c->min_uses = u->conf->cache_min_uses; |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
695 c->body_start = u->conf->buffer_size; |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
696 c->file_cache = u->conf->cache->data; |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
697 |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
698 u->cache_status = NGX_HTTP_CACHE_MISS; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
699 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
700 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
701 rc = ngx_http_file_cache_open(r); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
702 |
2926
80a314b63c56
delete useless r->cache->uses
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
703 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
80a314b63c56
delete useless r->cache->uses
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
704 "http upstream cache: %i", rc); |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
705 |
2952 | 706 switch (rc) { |
707 | |
708 case NGX_HTTP_CACHE_UPDATING: | |
709 | |
2927
55ceaef03d34
proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents:
2926
diff
changeset
|
710 if (u->conf->cache_use_stale & NGX_HTTP_UPSTREAM_FT_UPDATING) { |
2952 | 711 u->cache_status = rc; |
2927
55ceaef03d34
proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents:
2926
diff
changeset
|
712 rc = NGX_OK; |
55ceaef03d34
proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents:
2926
diff
changeset
|
713 |
55ceaef03d34
proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents:
2926
diff
changeset
|
714 } else { |
55ceaef03d34
proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents:
2926
diff
changeset
|
715 rc = NGX_HTTP_CACHE_STALE; |
55ceaef03d34
proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents:
2926
diff
changeset
|
716 } |
2952 | 717 |
718 break; | |
719 | |
720 case NGX_OK: | |
721 u->cache_status = NGX_HTTP_CACHE_HIT; | |
2927
55ceaef03d34
proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents:
2926
diff
changeset
|
722 } |
55ceaef03d34
proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents:
2926
diff
changeset
|
723 |
2952 | 724 switch (rc) { |
725 | |
726 case NGX_OK: | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
727 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
728 rc = ngx_http_upstream_cache_send(r, u); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
729 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
730 if (rc != NGX_HTTP_UPSTREAM_INVALID_HEADER) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
731 return rc; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
732 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
733 |
2952 | 734 break; |
735 | |
736 case NGX_HTTP_CACHE_STALE: | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
737 |
2665
4d627567c324
fix r2664: ..._cache_valid did not work for stale responses
Igor Sysoev <igor@sysoev.ru>
parents:
2664
diff
changeset
|
738 c->valid_sec = 0; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
739 u->buffer.start = NULL; |
2952 | 740 u->cache_status = NGX_HTTP_CACHE_EXPIRED; |
741 | |
742 break; | |
743 | |
744 case NGX_DECLINED: | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
745 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
746 if ((size_t) (u->buffer.end - u->buffer.start) < u->conf->buffer_size) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
747 u->buffer.start = NULL; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
748 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
749 } else { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
750 u->buffer.pos = u->buffer.start + c->header_start; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
751 u->buffer.last = u->buffer.pos; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
752 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
753 |
2952 | 754 break; |
755 | |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
756 case NGX_HTTP_CACHE_SCARCE: |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
757 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
758 u->cacheable = 0; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
759 |
2952 | 760 break; |
761 | |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
762 case NGX_AGAIN: |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
763 |
3055
92b6cfaa3c27
fix sending a cached file using AIO
Igor Sysoev <igor@sysoev.ru>
parents:
3053
diff
changeset
|
764 return NGX_BUSY; |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
765 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
766 case NGX_ERROR: |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
767 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
768 return NGX_ERROR; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
769 |
2952 | 770 default: |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
771 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
772 /* cached NGX_HTTP_BAD_GATEWAY, NGX_HTTP_GATEWAY_TIME_OUT, etc. */ |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
773 |
2952 | 774 u->cache_status = NGX_HTTP_CACHE_HIT; |
775 | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
776 return rc; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
777 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
778 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
779 r->cached = 0; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
780 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
781 return NGX_DECLINED; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
782 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
783 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
784 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
785 static ngx_int_t |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
786 ngx_http_upstream_cache_send(ngx_http_request_t *r, ngx_http_upstream_t *u) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
787 { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
788 ngx_int_t rc; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
789 ngx_http_cache_t *c; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
790 |
2952 | 791 r->cached = 1; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
792 c = r->cache; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
793 |
3369
479468a7d982
fix handling cached HTTP/0.9 response
Igor Sysoev <igor@sysoev.ru>
parents:
3272
diff
changeset
|
794 if (c->header_start == c->body_start) { |
479468a7d982
fix handling cached HTTP/0.9 response
Igor Sysoev <igor@sysoev.ru>
parents:
3272
diff
changeset
|
795 r->http_version = NGX_HTTP_VERSION_9; |
479468a7d982
fix handling cached HTTP/0.9 response
Igor Sysoev <igor@sysoev.ru>
parents:
3272
diff
changeset
|
796 return ngx_http_cache_send(r); |
479468a7d982
fix handling cached HTTP/0.9 response
Igor Sysoev <igor@sysoev.ru>
parents:
3272
diff
changeset
|
797 } |
479468a7d982
fix handling cached HTTP/0.9 response
Igor Sysoev <igor@sysoev.ru>
parents:
3272
diff
changeset
|
798 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
799 /* TODO: cache stack */ |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
800 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
801 u->buffer = *c->buf; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
802 u->buffer.pos += c->header_start; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
803 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
804 ngx_memzero(&u->headers_in, sizeof(ngx_http_upstream_headers_in_t)); |
4117
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
805 u->headers_in.content_length_n = -1; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
806 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
807 if (ngx_list_init(&u->headers_in.headers, r->pool, 8, |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
808 sizeof(ngx_table_elt_t)) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
809 != NGX_OK) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
810 { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
811 return NGX_ERROR; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
812 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
813 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
814 rc = u->process_header(r); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
815 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
816 if (rc == NGX_OK) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
817 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
818 if (ngx_http_upstream_process_headers(r, u) != NGX_OK) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
819 return NGX_DONE; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
820 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
821 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
822 return ngx_http_cache_send(r); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
823 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
824 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
825 if (rc == NGX_ERROR) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
826 return NGX_ERROR; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
827 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
828 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
829 /* rc == NGX_HTTP_UPSTREAM_INVALID_HEADER */ |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
830 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
831 /* TODO: delete file */ |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
832 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
833 return rc; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
834 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
835 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
836 #endif |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
837 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
838 |
487 | 839 static void |
1658 | 840 ngx_http_upstream_resolve_handler(ngx_resolver_ctx_t *ctx) |
841 { | |
842 ngx_http_request_t *r; | |
3169
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
843 ngx_http_upstream_t *u; |
1658 | 844 ngx_http_upstream_resolved_t *ur; |
845 | |
846 r = ctx->data; | |
847 | |
3169
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
848 u = r->upstream; |
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
849 ur = u->resolved; |
1658 | 850 |
851 if (ctx->state) { | |
852 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
853 "%V could not be resolved (%i: %s)", | |
854 &ctx->name, ctx->state, | |
855 ngx_resolver_strerror(ctx->state)); | |
856 | |
3169
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
857 ngx_http_upstream_finalize_request(r, u, NGX_HTTP_BAD_GATEWAY); |
1658 | 858 return; |
859 } | |
860 | |
861 ur->naddrs = ctx->naddrs; | |
862 ur->addrs = ctx->addrs; | |
863 | |
864 #if (NGX_DEBUG) | |
865 { | |
866 in_addr_t addr; | |
867 ngx_uint_t i; | |
868 | |
869 for (i = 0; i < ctx->naddrs; i++) { | |
870 addr = ntohl(ur->addrs[i]); | |
871 | |
872 ngx_log_debug4(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
873 "name was resolved to %ud.%ud.%ud.%ud", | |
874 (addr >> 24) & 0xff, (addr >> 16) & 0xff, | |
875 (addr >> 8) & 0xff, addr & 0xff); | |
876 } | |
877 } | |
878 #endif | |
879 | |
880 if (ngx_http_upstream_create_round_robin_peer(r, ur) != NGX_OK) { | |
3169
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
881 ngx_http_upstream_finalize_request(r, u, |
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
882 NGX_HTTP_INTERNAL_SERVER_ERROR); |
1658 | 883 return; |
884 } | |
885 | |
886 ngx_resolve_name_done(ctx); | |
3169
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
887 ur->ctx = NULL; |
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
888 |
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
889 ngx_http_upstream_connect(r, u); |
1658 | 890 } |
891 | |
892 | |
893 static void | |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
894 ngx_http_upstream_handler(ngx_event_t *ev) |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
895 { |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
896 ngx_connection_t *c; |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
897 ngx_http_request_t *r; |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
898 ngx_http_log_ctx_t *ctx; |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
899 ngx_http_upstream_t *u; |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
900 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
901 c = ev->data; |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
902 r = c->data; |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
903 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
904 u = r->upstream; |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
905 c = r->connection; |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
906 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
907 ctx = c->log->data; |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
908 ctx->current_request = r; |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
909 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
910 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
911 "http upstream request: \"%V?%V\"", &r->uri, &r->args); |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
912 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
913 if (ev->write) { |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
914 u->write_event_handler(r, u); |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
915 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
916 } else { |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
917 u->read_event_handler(r, u); |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
918 } |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
919 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
920 ngx_http_run_posted_requests(c); |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
921 } |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
922 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
923 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
924 static void |
509 | 925 ngx_http_upstream_rd_check_broken_connection(ngx_http_request_t *r) |
926 { | |
927 ngx_http_upstream_check_broken_connection(r, r->connection->read); | |
928 } | |
929 | |
930 | |
931 static void | |
932 ngx_http_upstream_wr_check_broken_connection(ngx_http_request_t *r) | |
933 { | |
934 ngx_http_upstream_check_broken_connection(r, r->connection->write); | |
935 } | |
936 | |
937 | |
938 static void | |
939 ngx_http_upstream_check_broken_connection(ngx_http_request_t *r, | |
940 ngx_event_t *ev) | |
479 | 941 { |
942 int n; | |
943 char buf[1]; | |
577 | 944 ngx_err_t err; |
2807
6ad4bba6313e
delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents:
2805
diff
changeset
|
945 ngx_int_t event; |
479 | 946 ngx_connection_t *c; |
947 ngx_http_upstream_t *u; | |
948 | |
527 | 949 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, ev->log, 0, |
950 "http upstream check client, write event:%d, \"%V\"", | |
951 ev->write, &r->uri); | |
479 | 952 |
509 | 953 c = r->connection; |
483 | 954 u = r->upstream; |
955 | |
583 | 956 if (c->error) { |
2807
6ad4bba6313e
delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents:
2805
diff
changeset
|
957 if ((ngx_event_flags & NGX_USE_LEVEL_EVENT) && ev->active) { |
6ad4bba6313e
delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents:
2805
diff
changeset
|
958 |
6ad4bba6313e
delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents:
2805
diff
changeset
|
959 event = ev->write ? NGX_WRITE_EVENT : NGX_READ_EVENT; |
6ad4bba6313e
delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents:
2805
diff
changeset
|
960 |
6ad4bba6313e
delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents:
2805
diff
changeset
|
961 if (ngx_del_event(ev, event, 0) != NGX_OK) { |
6ad4bba6313e
delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents:
2805
diff
changeset
|
962 ngx_http_upstream_finalize_request(r, u, |
6ad4bba6313e
delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents:
2805
diff
changeset
|
963 NGX_HTTP_INTERNAL_SERVER_ERROR); |
6ad4bba6313e
delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents:
2805
diff
changeset
|
964 return; |
6ad4bba6313e
delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents:
2805
diff
changeset
|
965 } |
6ad4bba6313e
delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents:
2805
diff
changeset
|
966 } |
6ad4bba6313e
delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents:
2805
diff
changeset
|
967 |
2757
9cc973b46af1
get a full response if the response is cacheable or storable even
Igor Sysoev <igor@sysoev.ru>
parents:
2708
diff
changeset
|
968 if (!u->cacheable) { |
9cc973b46af1
get a full response if the response is cacheable or storable even
Igor Sysoev <igor@sysoev.ru>
parents:
2708
diff
changeset
|
969 ngx_http_upstream_finalize_request(r, u, |
9cc973b46af1
get a full response if the response is cacheable or storable even
Igor Sysoev <igor@sysoev.ru>
parents:
2708
diff
changeset
|
970 NGX_HTTP_CLIENT_CLOSED_REQUEST); |
9cc973b46af1
get a full response if the response is cacheable or storable even
Igor Sysoev <igor@sysoev.ru>
parents:
2708
diff
changeset
|
971 } |
2807
6ad4bba6313e
delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents:
2805
diff
changeset
|
972 |
527 | 973 return; |
974 } | |
975 | |
479 | 976 #if (NGX_HAVE_KQUEUE) |
977 | |
978 if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) { | |
979 | |
980 if (!ev->pending_eof) { | |
981 return; | |
982 } | |
983 | |
984 ev->eof = 1; | |
583 | 985 c->error = 1; |
479 | 986 |
987 if (ev->kq_errno) { | |
988 ev->error = 1; | |
989 } | |
990 | |
2757
9cc973b46af1
get a full response if the response is cacheable or storable even
Igor Sysoev <igor@sysoev.ru>
parents:
2708
diff
changeset
|
991 if (!u->cacheable && u->peer.connection) { |
479 | 992 ngx_log_error(NGX_LOG_INFO, ev->log, ev->kq_errno, |
527 | 993 "kevent() reported that client closed prematurely " |
994 "connection, so upstream connection is closed too"); | |
479 | 995 ngx_http_upstream_finalize_request(r, u, |
996 NGX_HTTP_CLIENT_CLOSED_REQUEST); | |
997 return; | |
998 } | |
999 | |
1000 ngx_log_error(NGX_LOG_INFO, ev->log, ev->kq_errno, | |
1001 "kevent() reported that client closed " | |
1002 "prematurely connection"); | |
1003 | |
1004 if (u->peer.connection == NULL) { | |
1005 ngx_http_upstream_finalize_request(r, u, | |
1006 NGX_HTTP_CLIENT_CLOSED_REQUEST); | |
1007 } | |
1008 | |
1009 return; | |
1010 } | |
1011 | |
1012 #endif | |
1013 | |
1014 n = recv(c->fd, buf, 1, MSG_PEEK); | |
1015 | |
1016 err = ngx_socket_errno; | |
1017 | |
1109 | 1018 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ev->log, err, |
1019 "http upstream recv(): %d", n); | |
1020 | |
479 | 1021 if (ev->write && (n >= 0 || err == NGX_EAGAIN)) { |
1022 return; | |
1023 } | |
1024 | |
1025 if ((ngx_event_flags & NGX_USE_LEVEL_EVENT) && ev->active) { | |
2807
6ad4bba6313e
delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents:
2805
diff
changeset
|
1026 |
6ad4bba6313e
delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents:
2805
diff
changeset
|
1027 event = ev->write ? NGX_WRITE_EVENT : NGX_READ_EVENT; |
6ad4bba6313e
delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents:
2805
diff
changeset
|
1028 |
6ad4bba6313e
delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents:
2805
diff
changeset
|
1029 if (ngx_del_event(ev, event, 0) != NGX_OK) { |
479 | 1030 ngx_http_upstream_finalize_request(r, u, |
1031 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
1032 return; | |
1033 } | |
1034 } | |
1035 | |
1036 if (n > 0) { | |
1037 return; | |
1038 } | |
1039 | |
1040 if (n == -1) { | |
1041 if (err == NGX_EAGAIN) { | |
1042 return; | |
1043 } | |
1044 | |
1045 ev->error = 1; | |
1046 | |
483 | 1047 } else { /* n == 0 */ |
479 | 1048 err = 0; |
1049 } | |
1050 | |
529 | 1051 ev->eof = 1; |
583 | 1052 c->error = 1; |
529 | 1053 |
2757
9cc973b46af1
get a full response if the response is cacheable or storable even
Igor Sysoev <igor@sysoev.ru>
parents:
2708
diff
changeset
|
1054 if (!u->cacheable && u->peer.connection) { |
479 | 1055 ngx_log_error(NGX_LOG_INFO, ev->log, err, |
1056 "client closed prematurely connection, " | |
1057 "so upstream connection is closed too"); | |
1058 ngx_http_upstream_finalize_request(r, u, | |
1059 NGX_HTTP_CLIENT_CLOSED_REQUEST); | |
1060 return; | |
1061 } | |
1062 | |
1063 ngx_log_error(NGX_LOG_INFO, ev->log, err, | |
1064 "client closed prematurely connection"); | |
1065 | |
1066 if (u->peer.connection == NULL) { | |
1067 ngx_http_upstream_finalize_request(r, u, | |
1068 NGX_HTTP_CLIENT_CLOSED_REQUEST); | |
1069 } | |
1070 } | |
1071 | |
1072 | |
487 | 1073 static void |
1074 ngx_http_upstream_connect(ngx_http_request_t *r, ngx_http_upstream_t *u) | |
479 | 1075 { |
591 | 1076 ngx_int_t rc; |
665 | 1077 ngx_time_t *tp; |
591 | 1078 ngx_connection_t *c; |
479 | 1079 |
483 | 1080 r->connection->log->action = "connecting to upstream"; |
479 | 1081 |
1082 r->connection->single_connection = 0; | |
1083 | |
889
a9a7e4b1a72b
the previous fix does not actually fix overflow
Igor Sysoev <igor@sysoev.ru>
parents:
888
diff
changeset
|
1084 if (u->state && u->state->response_sec) { |
665 | 1085 tp = ngx_timeofday(); |
889
a9a7e4b1a72b
the previous fix does not actually fix overflow
Igor Sysoev <igor@sysoev.ru>
parents:
888
diff
changeset
|
1086 u->state->response_sec = tp->sec - u->state->response_sec; |
a9a7e4b1a72b
the previous fix does not actually fix overflow
Igor Sysoev <igor@sysoev.ru>
parents:
888
diff
changeset
|
1087 u->state->response_msec = tp->msec - u->state->response_msec; |
665 | 1088 } |
1089 | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
1090 u->state = ngx_array_push(r->upstream_states); |
665 | 1091 if (u->state == NULL) { |
1092 ngx_http_upstream_finalize_request(r, u, | |
1093 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
1094 return; | |
1095 } | |
1096 | |
1097 ngx_memzero(u->state, sizeof(ngx_http_upstream_state_t)); | |
1098 | |
1099 tp = ngx_timeofday(); | |
889
a9a7e4b1a72b
the previous fix does not actually fix overflow
Igor Sysoev <igor@sysoev.ru>
parents:
888
diff
changeset
|
1100 u->state->response_sec = tp->sec; |
a9a7e4b1a72b
the previous fix does not actually fix overflow
Igor Sysoev <igor@sysoev.ru>
parents:
888
diff
changeset
|
1101 u->state->response_msec = tp->msec; |
665 | 1102 |
479 | 1103 rc = ngx_event_connect_peer(&u->peer); |
1104 | |
1105 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
1106 "http upstream connect: %i", rc); | |
1107 | |
1108 if (rc == NGX_ERROR) { | |
1109 ngx_http_upstream_finalize_request(r, u, | |
1110 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
1111 return; | |
1112 } | |
1113 | |
1707
f3188f6eae1f
$upstream_addr did not contain last address, the bug was introduced in r1659
Igor Sysoev <igor@sysoev.ru>
parents:
1706
diff
changeset
|
1114 u->state->peer = u->peer.name; |
f3188f6eae1f
$upstream_addr did not contain last address, the bug was introduced in r1659
Igor Sysoev <igor@sysoev.ru>
parents:
1706
diff
changeset
|
1115 |
543 | 1116 if (rc == NGX_BUSY) { |
1117 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "no live upstreams"); | |
1378 | 1118 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_NOLIVE); |
1119 return; | |
543 | 1120 } |
1121 | |
1378 | 1122 if (rc == NGX_DECLINED) { |
479 | 1123 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR); |
1124 return; | |
1125 } | |
1126 | |
577 | 1127 /* rc == NGX_OK || rc == NGX_AGAIN */ |
1128 | |
479 | 1129 c = u->peer.connection; |
1130 | |
1131 c->data = r; | |
591 | 1132 |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1133 c->write->handler = ngx_http_upstream_handler; |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1134 c->read->handler = ngx_http_upstream_handler; |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1135 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1136 u->write_event_handler = ngx_http_upstream_send_request_handler; |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1137 u->read_event_handler = ngx_http_upstream_process_header; |
479 | 1138 |
1397
6c25a49e548a
upstream sendfile bit was overridden by r->connection->sendfile
Igor Sysoev <igor@sysoev.ru>
parents:
1378
diff
changeset
|
1139 c->sendfile &= r->connection->sendfile; |
1958 | 1140 u->output.sendfile = c->sendfile; |
479 | 1141 |
4116
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1142 if (c->pool == NULL) { |
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1143 |
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1144 /* we need separate pool here to be able to cache SSL connections */ |
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1145 |
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1146 c->pool = ngx_create_pool(128, r->connection->log); |
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1147 if (c->pool == NULL) { |
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1148 ngx_http_upstream_finalize_request(r, u, |
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1149 NGX_HTTP_INTERNAL_SERVER_ERROR); |
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1150 return; |
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1151 } |
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1152 } |
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1153 |
2847 | 1154 c->log = r->connection->log; |
4116
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1155 c->pool->log = c->log; |
2847 | 1156 c->read->log = c->log; |
1157 c->write->log = c->log; | |
479 | 1158 |
1159 /* init or reinit the ngx_output_chain() and ngx_chain_writer() contexts */ | |
1160 | |
1161 u->writer.out = NULL; | |
1162 u->writer.last = &u->writer.out; | |
1163 u->writer.connection = c; | |
1164 u->writer.limit = 0; | |
1165 | |
1166 if (u->request_sent) { | |
509 | 1167 if (ngx_http_upstream_reinit(r, u) != NGX_OK) { |
1168 ngx_http_upstream_finalize_request(r, u, | |
1169 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
1170 return; | |
1171 } | |
479 | 1172 } |
1173 | |
1064
7c84c877f2d7
fix segfault when client_body_in_file_only is on, the body is not passed
Igor Sysoev <igor@sysoev.ru>
parents:
1063
diff
changeset
|
1174 if (r->request_body |
7c84c877f2d7
fix segfault when client_body_in_file_only is on, the body is not passed
Igor Sysoev <igor@sysoev.ru>
parents:
1063
diff
changeset
|
1175 && r->request_body->buf |
7c84c877f2d7
fix segfault when client_body_in_file_only is on, the body is not passed
Igor Sysoev <igor@sysoev.ru>
parents:
1063
diff
changeset
|
1176 && r->request_body->temp_file |
7c84c877f2d7
fix segfault when client_body_in_file_only is on, the body is not passed
Igor Sysoev <igor@sysoev.ru>
parents:
1063
diff
changeset
|
1177 && r == r->main) |
7c84c877f2d7
fix segfault when client_body_in_file_only is on, the body is not passed
Igor Sysoev <igor@sysoev.ru>
parents:
1063
diff
changeset
|
1178 { |
573 | 1179 /* |
1180 * the r->request_body->buf can be reused for one request only, | |
1181 * the subrequests should allocate their own temporay bufs | |
1182 */ | |
1183 | |
1184 u->output.free = ngx_alloc_chain_link(r->pool); | |
1185 if (u->output.free == NULL) { | |
1186 ngx_http_upstream_finalize_request(r, u, | |
1187 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
1188 return; | |
479 | 1189 } |
573 | 1190 |
1191 u->output.free->buf = r->request_body->buf; | |
1192 u->output.free->next = NULL; | |
1193 u->output.allocated = 1; | |
1194 | |
1195 r->request_body->buf->pos = r->request_body->buf->start; | |
1196 r->request_body->buf->last = r->request_body->buf->start; | |
1197 r->request_body->buf->tag = u->output.tag; | |
479 | 1198 } |
1199 | |
1200 u->request_sent = 0; | |
1201 | |
1202 if (rc == NGX_AGAIN) { | |
1203 ngx_add_timer(c->write, u->conf->connect_timeout); | |
1204 return; | |
1205 } | |
1206 | |
577 | 1207 #if (NGX_HTTP_SSL) |
1208 | |
1658 | 1209 if (u->ssl && c->ssl == NULL) { |
591 | 1210 ngx_http_upstream_ssl_init_connection(r, u, c); |
577 | 1211 return; |
1212 } | |
1213 | |
1214 #endif | |
1215 | |
479 | 1216 ngx_http_upstream_send_request(r, u); |
1217 } | |
1218 | |
1219 | |
577 | 1220 #if (NGX_HTTP_SSL) |
1221 | |
1222 static void | |
591 | 1223 ngx_http_upstream_ssl_init_connection(ngx_http_request_t *r, |
1224 ngx_http_upstream_t *u, ngx_connection_t *c) | |
1225 { | |
884 | 1226 ngx_int_t rc; |
591 | 1227 |
1228 if (ngx_ssl_create_connection(u->conf->ssl, c, | |
1229 NGX_SSL_BUFFER|NGX_SSL_CLIENT) | |
2536
a6d6d762c554
small optimization: " == NGX_ERROR" > " != NGX_OK"
Igor Sysoev <igor@sysoev.ru>
parents:
2463
diff
changeset
|
1230 != NGX_OK) |
591 | 1231 { |
1232 ngx_http_upstream_finalize_request(r, u, | |
1233 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
1234 return; | |
1235 } | |
1236 | |
1237 c->sendfile = 0; | |
619 | 1238 u->output.sendfile = 0; |
591 | 1239 |
2184 | 1240 if (u->conf->ssl_session_reuse) { |
1241 if (u->peer.set_session(&u->peer, u->peer.data) != NGX_OK) { | |
1242 ngx_http_upstream_finalize_request(r, u, | |
1243 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
1244 return; | |
1245 } | |
591 | 1246 } |
1247 | |
641 | 1248 r->connection->log->action = "SSL handshaking to upstream"; |
1249 | |
591 | 1250 rc = ngx_ssl_handshake(c); |
1251 | |
1252 if (rc == NGX_AGAIN) { | |
1253 c->ssl->handler = ngx_http_upstream_ssl_handshake; | |
1254 return; | |
1255 } | |
1256 | |
1257 ngx_http_upstream_ssl_handshake(c); | |
1258 } | |
1259 | |
1260 | |
1261 static void | |
577 | 1262 ngx_http_upstream_ssl_handshake(ngx_connection_t *c) |
1263 { | |
1264 ngx_http_request_t *r; | |
1265 ngx_http_upstream_t *u; | |
1266 | |
1267 r = c->data; | |
1268 u = r->upstream; | |
1269 | |
1270 if (c->ssl->handshaked) { | |
1271 | |
2184 | 1272 if (u->conf->ssl_session_reuse) { |
1273 u->peer.save_session(&u->peer, u->peer.data); | |
1274 } | |
884 | 1275 |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1276 c->write->handler = ngx_http_upstream_handler; |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1277 c->read->handler = ngx_http_upstream_handler; |
577 | 1278 |
1279 ngx_http_upstream_send_request(r, u); | |
1280 | |
1281 return; | |
1282 } | |
1283 | |
1284 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR); | |
1285 | |
1286 } | |
1287 | |
1288 #endif | |
1289 | |
1290 | |
509 | 1291 static ngx_int_t |
487 | 1292 ngx_http_upstream_reinit(ngx_http_request_t *r, ngx_http_upstream_t *u) |
479 | 1293 { |
1294 ngx_chain_t *cl; | |
1295 | |
509 | 1296 if (u->reinit_request(r) != NGX_OK) { |
1297 return NGX_ERROR; | |
1298 } | |
1299 | |
1705 | 1300 ngx_memzero(&u->headers_in, sizeof(ngx_http_upstream_headers_in_t)); |
4117
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
1301 u->headers_in.content_length_n = -1; |
1705 | 1302 |
1303 if (ngx_list_init(&u->headers_in.headers, r->pool, 8, | |
591 | 1304 sizeof(ngx_table_elt_t)) |
1305 != NGX_OK) | |
509 | 1306 { |
1307 return NGX_ERROR; | |
479 | 1308 } |
1309 | |
1310 /* reinit the request chain */ | |
577 | 1311 |
509 | 1312 for (cl = u->request_bufs; cl; cl = cl->next) { |
479 | 1313 cl->buf->pos = cl->buf->start; |
1314 cl->buf->file_pos = 0; | |
1315 } | |
1316 | |
509 | 1317 /* reinit the subrequest's ngx_output_chain() context */ |
1318 | |
573 | 1319 if (r->request_body && r->request_body->temp_file |
597 | 1320 && r != r->main && u->output.buf) |
573 | 1321 { |
1322 u->output.free = ngx_alloc_chain_link(r->pool); | |
1323 if (u->output.free == NULL) { | |
1324 return NGX_ERROR; | |
509 | 1325 } |
573 | 1326 |
1327 u->output.free->buf = u->output.buf; | |
1328 u->output.free->next = NULL; | |
1329 | |
1330 u->output.buf->pos = u->output.buf->start; | |
1331 u->output.buf->last = u->output.buf->start; | |
509 | 1332 } |
479 | 1333 |
1334 u->output.buf = NULL; | |
1335 u->output.in = NULL; | |
1336 u->output.busy = NULL; | |
577 | 1337 |
581 | 1338 /* reinit u->buffer */ |
577 | 1339 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1340 u->buffer.pos = u->buffer.start; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1341 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1342 #if (NGX_HTTP_CACHE) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1343 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1344 if (r->cache) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1345 u->buffer.pos += r->cache->header_start; |
479 | 1346 } |
509 | 1347 |
479 | 1348 #endif |
1349 | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1350 u->buffer.last = u->buffer.pos; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1351 |
509 | 1352 return NGX_OK; |
479 | 1353 } |
1354 | |
1355 | |
487 | 1356 static void |
1357 ngx_http_upstream_send_request(ngx_http_request_t *r, ngx_http_upstream_t *u) | |
479 | 1358 { |
1153
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
1359 ngx_int_t rc; |
483 | 1360 ngx_connection_t *c; |
577 | 1361 |
479 | 1362 c = u->peer.connection; |
1363 | |
1364 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
1365 "http upstream send request"); | |
1366 | |
1153
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
1367 if (!u->request_sent && ngx_http_upstream_test_connect(c) != NGX_OK) { |
1166 | 1368 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR); |
1153
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
1369 return; |
479 | 1370 } |
1371 | |
483 | 1372 c->log->action = "sending request to upstream"; |
479 | 1373 |
509 | 1374 rc = ngx_output_chain(&u->output, u->request_sent ? NULL : u->request_bufs); |
479 | 1375 |
1376 u->request_sent = 1; | |
1377 | |
1378 if (rc == NGX_ERROR) { | |
1379 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR); | |
1380 return; | |
1381 } | |
1382 | |
1383 if (c->write->timer_set) { | |
1384 ngx_del_timer(c->write); | |
1385 } | |
1386 | |
1387 if (rc == NGX_AGAIN) { | |
1388 ngx_add_timer(c->write, u->conf->send_timeout); | |
1389 | |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1390 if (ngx_handle_write_event(c->write, u->conf->send_lowat) != NGX_OK) { |
479 | 1391 ngx_http_upstream_finalize_request(r, u, |
1392 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
1393 return; | |
1394 } | |
1395 | |
1396 return; | |
1397 } | |
1398 | |
1399 /* rc == NGX_OK */ | |
1400 | |
1401 if (c->tcp_nopush == NGX_TCP_NOPUSH_SET) { | |
1402 if (ngx_tcp_push(c->fd) == NGX_ERROR) { | |
1403 ngx_log_error(NGX_LOG_CRIT, c->log, ngx_socket_errno, | |
1404 ngx_tcp_push_n " failed"); | |
1405 ngx_http_upstream_finalize_request(r, u, | |
1406 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
577 | 1407 return; |
479 | 1408 } |
1409 | |
1410 c->tcp_nopush = NGX_TCP_NOPUSH_UNSET; | |
1411 } | |
577 | 1412 |
479 | 1413 ngx_add_timer(c->read, u->conf->read_timeout); |
1414 | |
1415 #if 1 | |
1416 if (c->read->ready) { | |
577 | 1417 |
479 | 1418 /* post aio operation */ |
1419 | |
1420 /* | |
1421 * TODO comment | |
1422 * although we can post aio operation just in the end | |
1423 * of ngx_http_upstream_connect() CHECK IT !!! | |
1424 * it's better to do here because we postpone header buffer allocation | |
1425 */ | |
1426 | |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1427 ngx_http_upstream_process_header(r, u); |
479 | 1428 return; |
1429 } | |
1430 #endif | |
1431 | |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1432 u->write_event_handler = ngx_http_upstream_dummy_handler; |
479 | 1433 |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1434 if (ngx_handle_write_event(c->write, 0) != NGX_OK) { |
479 | 1435 ngx_http_upstream_finalize_request(r, u, |
1436 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
1437 return; | |
1438 } | |
1439 } | |
1440 | |
1441 | |
487 | 1442 static void |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1443 ngx_http_upstream_send_request_handler(ngx_http_request_t *r, |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1444 ngx_http_upstream_t *u) |
479 | 1445 { |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1446 ngx_connection_t *c; |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1447 |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1448 c = u->peer.connection; |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1449 |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1450 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
479 | 1451 "http upstream send request handler"); |
1452 | |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1453 if (c->write->timedout) { |
479 | 1454 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_TIMEOUT); |
1455 return; | |
1456 } | |
1457 | |
591 | 1458 #if (NGX_HTTP_SSL) |
1459 | |
1658 | 1460 if (u->ssl && c->ssl == NULL) { |
591 | 1461 ngx_http_upstream_ssl_init_connection(r, u, c); |
1462 return; | |
1463 } | |
1464 | |
1465 #endif | |
1466 | |
651 | 1467 if (u->header_sent) { |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1468 u->write_event_handler = ngx_http_upstream_dummy_handler; |
651 | 1469 |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1470 (void) ngx_handle_write_event(c->write, 0); |
651 | 1471 |
1472 return; | |
1473 } | |
1474 | |
479 | 1475 ngx_http_upstream_send_request(r, u); |
1476 } | |
1477 | |
1478 | |
487 | 1479 static void |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1480 ngx_http_upstream_process_header(ngx_http_request_t *r, ngx_http_upstream_t *u) |
479 | 1481 { |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1482 ssize_t n; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1483 ngx_int_t rc; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1484 ngx_connection_t *c; |
479 | 1485 |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1486 c = u->peer.connection; |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1487 |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1488 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, |
483 | 1489 "http upstream process header"); |
479 | 1490 |
483 | 1491 c->log->action = "reading response header from upstream"; |
479 | 1492 |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1493 if (c->read->timedout) { |
479 | 1494 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_TIMEOUT); |
1495 return; | |
1496 } | |
577 | 1497 |
1153
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
1498 if (!u->request_sent && ngx_http_upstream_test_connect(c) != NGX_OK) { |
1166 | 1499 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR); |
1153
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
1500 return; |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
1501 } |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
1502 |
581 | 1503 if (u->buffer.start == NULL) { |
1504 u->buffer.start = ngx_palloc(r->pool, u->conf->buffer_size); | |
1505 if (u->buffer.start == NULL) { | |
479 | 1506 ngx_http_upstream_finalize_request(r, u, |
1507 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
1508 return; | |
1509 } | |
1510 | |
581 | 1511 u->buffer.pos = u->buffer.start; |
1512 u->buffer.last = u->buffer.start; | |
1513 u->buffer.end = u->buffer.start + u->conf->buffer_size; | |
1514 u->buffer.temporary = 1; | |
1515 | |
1516 u->buffer.tag = u->output.tag; | |
479 | 1517 |
1705 | 1518 if (ngx_list_init(&u->headers_in.headers, r->pool, 8, |
581 | 1519 sizeof(ngx_table_elt_t)) |
1520 != NGX_OK) | |
509 | 1521 { |
1522 ngx_http_upstream_finalize_request(r, u, | |
1523 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
1524 return; | |
1525 } | |
1526 | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1527 #if (NGX_HTTP_CACHE) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1528 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1529 if (r->cache) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1530 u->buffer.pos += r->cache->header_start; |
581 | 1531 u->buffer.last = u->buffer.pos; |
479 | 1532 } |
1533 #endif | |
1534 } | |
1535 | |
2360
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1536 for ( ;; ) { |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1537 |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1538 n = c->recv(c, u->buffer.last, u->buffer.end - u->buffer.last); |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1539 |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1540 if (n == NGX_AGAIN) { |
479 | 1541 #if 0 |
2360
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1542 ngx_add_timer(rev, u->read_timeout); |
479 | 1543 #endif |
1544 | |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1545 if (ngx_handle_read_event(c->read, 0) != NGX_OK) { |
2360
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1546 ngx_http_upstream_finalize_request(r, u, |
479 | 1547 NGX_HTTP_INTERNAL_SERVER_ERROR); |
2360
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1548 return; |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1549 } |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1550 |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1551 return; |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1552 } |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1553 |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1554 if (n == 0) { |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1555 ngx_log_error(NGX_LOG_ERR, c->log, 0, |
2360
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1556 "upstream prematurely closed connection"); |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1557 } |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1558 |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1559 if (n == NGX_ERROR || n == 0) { |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1560 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR); |
479 | 1561 return; |
1562 } | |
1563 | |
2360
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1564 u->buffer.last += n; |
479 | 1565 |
1566 #if 0 | |
2360
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1567 u->valid_header_in = 0; |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1568 |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1569 u->peer.cached = 0; |
479 | 1570 #endif |
1571 | |
2360
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1572 rc = u->process_header(r); |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1573 |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1574 if (rc == NGX_AGAIN) { |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1575 |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1576 if (u->buffer.pos == u->buffer.end) { |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1577 ngx_log_error(NGX_LOG_ERR, c->log, 0, |
2360
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1578 "upstream sent too big header"); |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1579 |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1580 ngx_http_upstream_next(r, u, |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1581 NGX_HTTP_UPSTREAM_FT_INVALID_HEADER); |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1582 return; |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1583 } |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1584 |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1585 continue; |
479 | 1586 } |
1587 | |
2360
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1588 break; |
479 | 1589 } |
1590 | |
1591 if (rc == NGX_HTTP_UPSTREAM_INVALID_HEADER) { | |
1592 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_INVALID_HEADER); | |
1593 return; | |
1594 } | |
1595 | |
1699
976db8c6fb64
return NGX_ERROR instead of NGX_HTTP_INTERNAL_SERVER_ERROR in u->parse_header()
Igor Sysoev <igor@sysoev.ru>
parents:
1693
diff
changeset
|
1596 if (rc == NGX_ERROR) { |
479 | 1597 ngx_http_upstream_finalize_request(r, u, |
1598 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
1599 return; | |
1600 } | |
1601 | |
1602 /* rc == NGX_OK */ | |
1603 | |
3401
9e7926763f87
allow to handle 301/302 in error_page
Igor Sysoev <igor@sysoev.ru>
parents:
3399
diff
changeset
|
1604 if (u->headers_in.status_n > NGX_HTTP_SPECIAL_RESPONSE) { |
2268
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
1605 |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
1606 if (r->subrequest_in_memory) { |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
1607 u->buffer.last = u->buffer.pos; |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
1608 } |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
1609 |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
1610 if (ngx_http_upstream_test_next(r, u) == NGX_OK) { |
509 | 1611 return; |
1612 } | |
1613 | |
2267
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
1614 if (ngx_http_upstream_intercept_errors(r, u) == NGX_OK) { |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
1615 return; |
487 | 1616 } |
1617 } | |
1618 | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1619 if (ngx_http_upstream_process_headers(r, u) != NGX_OK) { |
515 | 1620 return; |
1621 } | |
1622 | |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1623 if (!r->subrequest_in_memory) { |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1624 ngx_http_upstream_send_response(r, u); |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1625 return; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1626 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1627 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1628 /* subrequest content in memory */ |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1629 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1630 if (u->input_filter == NULL) { |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1631 u->input_filter_init = ngx_http_upstream_non_buffered_filter_init; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1632 u->input_filter = ngx_http_upstream_non_buffered_filter; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1633 u->input_filter_ctx = r; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1634 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1635 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1636 if (u->input_filter_init(u->input_filter_ctx) == NGX_ERROR) { |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1637 ngx_http_upstream_finalize_request(r, u, |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1638 NGX_HTTP_INTERNAL_SERVER_ERROR); |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1639 return; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1640 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1641 |
2308
3f98400e31e9
memcached response was stored in variable with END
Igor Sysoev <igor@sysoev.ru>
parents:
2285
diff
changeset
|
1642 n = u->buffer.last - u->buffer.pos; |
3f98400e31e9
memcached response was stored in variable with END
Igor Sysoev <igor@sysoev.ru>
parents:
2285
diff
changeset
|
1643 |
3f98400e31e9
memcached response was stored in variable with END
Igor Sysoev <igor@sysoev.ru>
parents:
2285
diff
changeset
|
1644 if (n) { |
3f98400e31e9
memcached response was stored in variable with END
Igor Sysoev <igor@sysoev.ru>
parents:
2285
diff
changeset
|
1645 u->buffer.last -= n; |
3f98400e31e9
memcached response was stored in variable with END
Igor Sysoev <igor@sysoev.ru>
parents:
2285
diff
changeset
|
1646 |
2402 | 1647 u->state->response_length += n; |
1648 | |
2308
3f98400e31e9
memcached response was stored in variable with END
Igor Sysoev <igor@sysoev.ru>
parents:
2285
diff
changeset
|
1649 if (u->input_filter(u->input_filter_ctx, n) == NGX_ERROR) { |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1650 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1651 return; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1652 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1653 |
2308
3f98400e31e9
memcached response was stored in variable with END
Igor Sysoev <igor@sysoev.ru>
parents:
2285
diff
changeset
|
1654 if (u->length == 0) { |
3f98400e31e9
memcached response was stored in variable with END
Igor Sysoev <igor@sysoev.ru>
parents:
2285
diff
changeset
|
1655 ngx_http_upstream_finalize_request(r, u, 0); |
3f98400e31e9
memcached response was stored in variable with END
Igor Sysoev <igor@sysoev.ru>
parents:
2285
diff
changeset
|
1656 return; |
3f98400e31e9
memcached response was stored in variable with END
Igor Sysoev <igor@sysoev.ru>
parents:
2285
diff
changeset
|
1657 } |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1658 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1659 |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1660 u->read_event_handler = ngx_http_upstream_process_body_in_memory; |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1661 |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1662 ngx_http_upstream_process_body_in_memory(r, u); |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1663 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1664 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1665 |
1153
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
1666 static ngx_int_t |
2268
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
1667 ngx_http_upstream_test_next(ngx_http_request_t *r, ngx_http_upstream_t *u) |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
1668 { |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
1669 ngx_uint_t status; |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
1670 ngx_http_upstream_next_t *un; |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
1671 |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
1672 status = u->headers_in.status_n; |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
1673 |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
1674 for (un = ngx_http_upstream_next_errors; un->status; un++) { |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
1675 |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
1676 if (status != un->status) { |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
1677 continue; |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
1678 } |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
1679 |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
1680 if (u->peer.tries > 1 && (u->conf->next_upstream & un->mask)) { |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
1681 ngx_http_upstream_next(r, u, un->mask); |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
1682 return NGX_OK; |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
1683 } |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
1684 |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
1685 #if (NGX_HTTP_CACHE) |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
1686 |
2952 | 1687 if (u->cache_status == NGX_HTTP_CACHE_EXPIRED |
1688 && (u->conf->cache_use_stale & un->mask)) | |
1689 { | |
2824
d106509491b5
fix building --without-http-cache
Igor Sysoev <igor@sysoev.ru>
parents:
2807
diff
changeset
|
1690 ngx_int_t rc; |
2805
60551422e150
reinit proxy/fastcgi header parser before ngx_http_upstream_cache_send()
Igor Sysoev <igor@sysoev.ru>
parents:
2804
diff
changeset
|
1691 |
60551422e150
reinit proxy/fastcgi header parser before ngx_http_upstream_cache_send()
Igor Sysoev <igor@sysoev.ru>
parents:
2804
diff
changeset
|
1692 rc = u->reinit_request(r); |
60551422e150
reinit proxy/fastcgi header parser before ngx_http_upstream_cache_send()
Igor Sysoev <igor@sysoev.ru>
parents:
2804
diff
changeset
|
1693 |
60551422e150
reinit proxy/fastcgi header parser before ngx_http_upstream_cache_send()
Igor Sysoev <igor@sysoev.ru>
parents:
2804
diff
changeset
|
1694 if (rc == NGX_OK) { |
2952 | 1695 u->cache_status = NGX_HTTP_CACHE_STALE; |
2805
60551422e150
reinit proxy/fastcgi header parser before ngx_http_upstream_cache_send()
Igor Sysoev <igor@sysoev.ru>
parents:
2804
diff
changeset
|
1696 rc = ngx_http_upstream_cache_send(r, u); |
60551422e150
reinit proxy/fastcgi header parser before ngx_http_upstream_cache_send()
Igor Sysoev <igor@sysoev.ru>
parents:
2804
diff
changeset
|
1697 } |
60551422e150
reinit proxy/fastcgi header parser before ngx_http_upstream_cache_send()
Igor Sysoev <igor@sysoev.ru>
parents:
2804
diff
changeset
|
1698 |
60551422e150
reinit proxy/fastcgi header parser before ngx_http_upstream_cache_send()
Igor Sysoev <igor@sysoev.ru>
parents:
2804
diff
changeset
|
1699 ngx_http_upstream_finalize_request(r, u, rc); |
2268
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
1700 return NGX_OK; |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
1701 } |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
1702 |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
1703 #endif |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
1704 } |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
1705 |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
1706 return NGX_DECLINED; |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
1707 } |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
1708 |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
1709 |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
1710 static ngx_int_t |
2267
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
1711 ngx_http_upstream_intercept_errors(ngx_http_request_t *r, |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
1712 ngx_http_upstream_t *u) |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
1713 { |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
1714 ngx_int_t status; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
1715 ngx_uint_t i; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
1716 ngx_table_elt_t *h; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
1717 ngx_http_err_page_t *err_page; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
1718 ngx_http_core_loc_conf_t *clcf; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
1719 |
2441
0c117a89f399
in miss case memcached module returned END instead of default 404 page body
Igor Sysoev <igor@sysoev.ru>
parents:
2422
diff
changeset
|
1720 status = u->headers_in.status_n; |
0c117a89f399
in miss case memcached module returned END instead of default 404 page body
Igor Sysoev <igor@sysoev.ru>
parents:
2422
diff
changeset
|
1721 |
0c117a89f399
in miss case memcached module returned END instead of default 404 page body
Igor Sysoev <igor@sysoev.ru>
parents:
2422
diff
changeset
|
1722 if (status == NGX_HTTP_NOT_FOUND && u->conf->intercept_404) { |
0c117a89f399
in miss case memcached module returned END instead of default 404 page body
Igor Sysoev <igor@sysoev.ru>
parents:
2422
diff
changeset
|
1723 ngx_http_upstream_finalize_request(r, u, NGX_HTTP_NOT_FOUND); |
0c117a89f399
in miss case memcached module returned END instead of default 404 page body
Igor Sysoev <igor@sysoev.ru>
parents:
2422
diff
changeset
|
1724 return NGX_OK; |
0c117a89f399
in miss case memcached module returned END instead of default 404 page body
Igor Sysoev <igor@sysoev.ru>
parents:
2422
diff
changeset
|
1725 } |
0c117a89f399
in miss case memcached module returned END instead of default 404 page body
Igor Sysoev <igor@sysoev.ru>
parents:
2422
diff
changeset
|
1726 |
2267
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
1727 if (!u->conf->intercept_errors) { |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
1728 return NGX_DECLINED; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
1729 } |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
1730 |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
1731 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
1732 |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
1733 if (clcf->error_pages == NULL) { |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
1734 return NGX_DECLINED; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
1735 } |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
1736 |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
1737 err_page = clcf->error_pages->elts; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
1738 for (i = 0; i < clcf->error_pages->nelts; i++) { |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
1739 |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
1740 if (err_page[i].status == status) { |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
1741 |
2953
aa12525236da
fix segfault if there is error_page 401, proxy_intercept_errors is on
Igor Sysoev <igor@sysoev.ru>
parents:
2952
diff
changeset
|
1742 if (status == NGX_HTTP_UNAUTHORIZED |
aa12525236da
fix segfault if there is error_page 401, proxy_intercept_errors is on
Igor Sysoev <igor@sysoev.ru>
parents:
2952
diff
changeset
|
1743 && u->headers_in.www_authenticate) |
aa12525236da
fix segfault if there is error_page 401, proxy_intercept_errors is on
Igor Sysoev <igor@sysoev.ru>
parents:
2952
diff
changeset
|
1744 { |
2267
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
1745 h = ngx_list_push(&r->headers_out.headers); |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
1746 |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
1747 if (h == NULL) { |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
1748 ngx_http_upstream_finalize_request(r, u, |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
1749 NGX_HTTP_INTERNAL_SERVER_ERROR); |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
1750 return NGX_OK; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
1751 } |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
1752 |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
1753 *h = *u->headers_in.www_authenticate; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
1754 |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
1755 r->headers_out.www_authenticate = h; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
1756 } |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
1757 |
3706
ea908f6ae499
an intercepted error code was not cached
Igor Sysoev <igor@sysoev.ru>
parents:
3705
diff
changeset
|
1758 #if (NGX_HTTP_CACHE) |
ea908f6ae499
an intercepted error code was not cached
Igor Sysoev <igor@sysoev.ru>
parents:
3705
diff
changeset
|
1759 |
3709
64777690c697
fix r3707: cache node should be freed be a response is not cached
Igor Sysoev <igor@sysoev.ru>
parents:
3708
diff
changeset
|
1760 if (r->cache) { |
3706
ea908f6ae499
an intercepted error code was not cached
Igor Sysoev <igor@sysoev.ru>
parents:
3705
diff
changeset
|
1761 time_t valid; |
ea908f6ae499
an intercepted error code was not cached
Igor Sysoev <igor@sysoev.ru>
parents:
3705
diff
changeset
|
1762 |
ea908f6ae499
an intercepted error code was not cached
Igor Sysoev <igor@sysoev.ru>
parents:
3705
diff
changeset
|
1763 valid = ngx_http_file_cache_valid(u->conf->cache_valid, status); |
ea908f6ae499
an intercepted error code was not cached
Igor Sysoev <igor@sysoev.ru>
parents:
3705
diff
changeset
|
1764 |
ea908f6ae499
an intercepted error code was not cached
Igor Sysoev <igor@sysoev.ru>
parents:
3705
diff
changeset
|
1765 if (valid) { |
ea908f6ae499
an intercepted error code was not cached
Igor Sysoev <igor@sysoev.ru>
parents:
3705
diff
changeset
|
1766 r->cache->valid_sec = ngx_time() + valid; |
ea908f6ae499
an intercepted error code was not cached
Igor Sysoev <igor@sysoev.ru>
parents:
3705
diff
changeset
|
1767 r->cache->error = status; |
ea908f6ae499
an intercepted error code was not cached
Igor Sysoev <igor@sysoev.ru>
parents:
3705
diff
changeset
|
1768 } |
ea908f6ae499
an intercepted error code was not cached
Igor Sysoev <igor@sysoev.ru>
parents:
3705
diff
changeset
|
1769 |
3711
ce6ba077c270
several changes in cache cleanup handling:
Igor Sysoev <igor@sysoev.ru>
parents:
3709
diff
changeset
|
1770 ngx_http_file_cache_free(r->cache, u->pipe->temp_file); |
3706
ea908f6ae499
an intercepted error code was not cached
Igor Sysoev <igor@sysoev.ru>
parents:
3705
diff
changeset
|
1771 } |
ea908f6ae499
an intercepted error code was not cached
Igor Sysoev <igor@sysoev.ru>
parents:
3705
diff
changeset
|
1772 #endif |
2267
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
1773 ngx_http_upstream_finalize_request(r, u, status); |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
1774 |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
1775 return NGX_OK; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
1776 } |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
1777 } |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
1778 |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
1779 return NGX_DECLINED; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
1780 } |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
1781 |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
1782 |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
1783 static ngx_int_t |
1153
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
1784 ngx_http_upstream_test_connect(ngx_connection_t *c) |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
1785 { |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
1786 int err; |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
1787 socklen_t len; |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
1788 |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
1789 #if (NGX_HAVE_KQUEUE) |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
1790 |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
1791 if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) { |
1166 | 1792 if (c->write->pending_eof) { |
1469
0a269c464eaf
connection error should be logged with "connecting to upstream" action,
Igor Sysoev <igor@sysoev.ru>
parents:
1468
diff
changeset
|
1793 c->log->action = "connecting to upstream"; |
1166 | 1794 (void) ngx_connection_error(c, c->write->kq_errno, |
1795 "kevent() reported that connect() failed"); | |
1796 return NGX_ERROR; | |
1797 } | |
1153
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
1798 |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
1799 } else |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
1800 #endif |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
1801 { |
1166 | 1802 err = 0; |
1803 len = sizeof(int); | |
1804 | |
1805 /* | |
1806 * BSDs and Linux return 0 and set a pending error in err | |
1807 * Solaris returns -1 and sets errno | |
1808 */ | |
1809 | |
1810 if (getsockopt(c->fd, SOL_SOCKET, SO_ERROR, (void *) &err, &len) | |
1811 == -1) | |
1812 { | |
1813 err = ngx_errno; | |
1814 } | |
1815 | |
1816 if (err) { | |
1469
0a269c464eaf
connection error should be logged with "connecting to upstream" action,
Igor Sysoev <igor@sysoev.ru>
parents:
1468
diff
changeset
|
1817 c->log->action = "connecting to upstream"; |
1166 | 1818 (void) ngx_connection_error(c, err, "connect() failed"); |
1819 return NGX_ERROR; | |
1820 } | |
1153
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
1821 } |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
1822 |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
1823 return NGX_OK; |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
1824 } |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
1825 |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
1826 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1827 static ngx_int_t |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1828 ngx_http_upstream_process_headers(ngx_http_request_t *r, ngx_http_upstream_t *u) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1829 { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1830 ngx_str_t *uri, args; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1831 ngx_uint_t i, flags; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1832 ngx_list_part_t *part; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1833 ngx_table_elt_t *h; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1834 ngx_http_upstream_header_t *hh; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1835 ngx_http_upstream_main_conf_t *umcf; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1836 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1837 umcf = ngx_http_get_module_main_conf(r, ngx_http_upstream_module); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1838 |
2786
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
1839 if (u->headers_in.x_accel_redirect |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
1840 && !(u->conf->ignore_headers & NGX_HTTP_UPSTREAM_IGN_XA_REDIRECT)) |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
1841 { |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1842 ngx_http_upstream_finalize_request(r, u, NGX_DECLINED); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1843 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1844 part = &u->headers_in.headers.part; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1845 h = part->elts; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1846 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1847 for (i = 0; /* void */; i++) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1848 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1849 if (i >= part->nelts) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1850 if (part->next == NULL) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1851 break; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1852 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1853 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1854 part = part->next; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1855 h = part->elts; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1856 i = 0; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1857 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1858 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1859 hh = ngx_hash_find(&umcf->headers_in_hash, h[i].hash, |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1860 h[i].lowcase_key, h[i].key.len); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1861 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1862 if (hh && hh->redirect) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1863 if (hh->copy_handler(r, &h[i], hh->conf) != NGX_OK) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1864 ngx_http_finalize_request(r, |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1865 NGX_HTTP_INTERNAL_SERVER_ERROR); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1866 return NGX_DONE; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1867 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1868 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1869 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1870 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1871 uri = &u->headers_in.x_accel_redirect->value; |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1872 ngx_str_null(&args); |
3161 | 1873 flags = NGX_HTTP_LOG_UNSAFE; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1874 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1875 if (ngx_http_parse_unsafe_uri(r, uri, &args, &flags) != NGX_OK) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1876 ngx_http_finalize_request(r, NGX_HTTP_NOT_FOUND); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1877 return NGX_DONE; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1878 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1879 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1880 if (r->method != NGX_HTTP_HEAD) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1881 r->method = NGX_HTTP_GET; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1882 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1883 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1884 r->valid_unparsed_uri = 0; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1885 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1886 ngx_http_internal_redirect(r, uri, &args); |
3120
40b8b398dbbc
fix request counter for X-Accel-Redirect, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3112
diff
changeset
|
1887 ngx_http_finalize_request(r, NGX_DONE); |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1888 return NGX_DONE; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1889 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1890 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1891 part = &u->headers_in.headers.part; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1892 h = part->elts; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1893 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1894 for (i = 0; /* void */; i++) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1895 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1896 if (i >= part->nelts) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1897 if (part->next == NULL) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1898 break; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1899 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1900 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1901 part = part->next; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1902 h = part->elts; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1903 i = 0; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1904 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1905 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1906 if (ngx_hash_find(&u->conf->hide_headers_hash, h[i].hash, |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1907 h[i].lowcase_key, h[i].key.len)) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1908 { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1909 continue; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1910 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1911 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1912 hh = ngx_hash_find(&umcf->headers_in_hash, h[i].hash, |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1913 h[i].lowcase_key, h[i].key.len); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1914 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1915 if (hh) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1916 if (hh->copy_handler(r, &h[i], hh->conf) != NGX_OK) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1917 ngx_http_upstream_finalize_request(r, u, |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1918 NGX_HTTP_INTERNAL_SERVER_ERROR); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1919 return NGX_DONE; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1920 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1921 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1922 continue; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1923 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1924 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1925 if (ngx_http_upstream_copy_header_line(r, &h[i], 0) != NGX_OK) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1926 ngx_http_upstream_finalize_request(r, u, |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1927 NGX_HTTP_INTERNAL_SERVER_ERROR); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1928 return NGX_DONE; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1929 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1930 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1931 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1932 if (r->headers_out.server && r->headers_out.server->value.data == NULL) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1933 r->headers_out.server->hash = 0; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1934 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1935 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1936 if (r->headers_out.date && r->headers_out.date->value.data == NULL) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1937 r->headers_out.date->hash = 0; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1938 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1939 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1940 r->headers_out.status = u->headers_in.status_n; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1941 r->headers_out.status_line = u->headers_in.status_line; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1942 |
4117
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
1943 r->headers_out.content_length_n = u->headers_in.content_length_n; |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
1944 |
4118
dbddec65fdab
Upstream: r->upstream->length type change to off_t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4117
diff
changeset
|
1945 u->length = u->headers_in.content_length_n; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1946 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1947 return NGX_OK; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1948 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1949 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1950 |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1951 static void |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1952 ngx_http_upstream_process_body_in_memory(ngx_http_request_t *r, |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1953 ngx_http_upstream_t *u) |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1954 { |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1955 size_t size; |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1956 ssize_t n; |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1957 ngx_buf_t *b; |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1958 ngx_event_t *rev; |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1959 ngx_connection_t *c; |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1960 |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1961 c = u->peer.connection; |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1962 rev = c->read; |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1963 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1964 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1965 "http upstream process body on memory"); |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1966 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1967 if (rev->timedout) { |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1968 ngx_connection_error(c, NGX_ETIMEDOUT, "upstream timed out"); |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1969 ngx_http_upstream_finalize_request(r, u, NGX_ETIMEDOUT); |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1970 return; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1971 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1972 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1973 b = &u->buffer; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1974 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1975 for ( ;; ) { |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1976 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1977 size = b->end - b->last; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1978 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1979 if (size == 0) { |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1980 ngx_log_error(NGX_LOG_ALERT, c->log, 0, |
3708 | 1981 "upstream buffer is too small to read response"); |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1982 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1983 return; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1984 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1985 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1986 n = c->recv(c, b->last, size); |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1987 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1988 if (n == NGX_AGAIN) { |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1989 break; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1990 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1991 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1992 if (n == 0 || n == NGX_ERROR) { |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1993 ngx_http_upstream_finalize_request(r, u, n); |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1994 return; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1995 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1996 |
2402 | 1997 u->state->response_length += n; |
1998 | |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1999 if (u->input_filter(u->input_filter_ctx, n) == NGX_ERROR) { |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2000 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2001 return; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2002 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2003 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2004 if (!rev->ready) { |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2005 break; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2006 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2007 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2008 |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2009 if (ngx_handle_read_event(rev, 0) != NGX_OK) { |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2010 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2011 return; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2012 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2013 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2014 if (rev->active) { |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2015 ngx_add_timer(rev, u->conf->read_timeout); |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2016 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2017 } else if (rev->timer_set) { |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2018 ngx_del_timer(rev); |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2019 } |
681 | 2020 } |
2021 | |
2022 | |
2023 static void | |
2024 ngx_http_upstream_send_response(ngx_http_request_t *r, ngx_http_upstream_t *u) | |
2025 { | |
2026 int tcp_nodelay; | |
2402 | 2027 ssize_t n; |
681 | 2028 ngx_int_t rc; |
2029 ngx_event_pipe_t *p; | |
2030 ngx_connection_t *c; | |
2031 ngx_http_core_loc_conf_t *clcf; | |
2032 | |
509 | 2033 rc = ngx_http_send_header(r); |
479 | 2034 |
2701 | 2035 if (rc == NGX_ERROR || rc > NGX_OK || r->post_action) { |
485 | 2036 ngx_http_upstream_finalize_request(r, u, rc); |
479 | 2037 return; |
2038 } | |
2039 | |
2704
ac1e2e199c9f
shutdown client connection for cacheable header only responses
Igor Sysoev <igor@sysoev.ru>
parents:
2703
diff
changeset
|
2040 c = r->connection; |
ac1e2e199c9f
shutdown client connection for cacheable header only responses
Igor Sysoev <igor@sysoev.ru>
parents:
2703
diff
changeset
|
2041 |
2701 | 2042 if (r->header_only) { |
2704
ac1e2e199c9f
shutdown client connection for cacheable header only responses
Igor Sysoev <igor@sysoev.ru>
parents:
2703
diff
changeset
|
2043 |
2701 | 2044 if (u->cacheable || u->store) { |
2704
ac1e2e199c9f
shutdown client connection for cacheable header only responses
Igor Sysoev <igor@sysoev.ru>
parents:
2703
diff
changeset
|
2045 |
ac1e2e199c9f
shutdown client connection for cacheable header only responses
Igor Sysoev <igor@sysoev.ru>
parents:
2703
diff
changeset
|
2046 if (ngx_shutdown_socket(c->fd, NGX_WRITE_SHUTDOWN) == -1) { |
ac1e2e199c9f
shutdown client connection for cacheable header only responses
Igor Sysoev <igor@sysoev.ru>
parents:
2703
diff
changeset
|
2047 ngx_connection_error(c, ngx_socket_errno, |
ac1e2e199c9f
shutdown client connection for cacheable header only responses
Igor Sysoev <igor@sysoev.ru>
parents:
2703
diff
changeset
|
2048 ngx_shutdown_socket_n " failed"); |
ac1e2e199c9f
shutdown client connection for cacheable header only responses
Igor Sysoev <igor@sysoev.ru>
parents:
2703
diff
changeset
|
2049 } |
ac1e2e199c9f
shutdown client connection for cacheable header only responses
Igor Sysoev <igor@sysoev.ru>
parents:
2703
diff
changeset
|
2050 |
2701 | 2051 r->read_event_handler = ngx_http_request_empty_handler; |
2052 r->write_event_handler = ngx_http_request_empty_handler; | |
2704
ac1e2e199c9f
shutdown client connection for cacheable header only responses
Igor Sysoev <igor@sysoev.ru>
parents:
2703
diff
changeset
|
2053 c->error = 1; |
2701 | 2054 |
2055 } else { | |
2056 ngx_http_upstream_finalize_request(r, u, rc); | |
2057 return; | |
2058 } | |
2059 } | |
2060 | |
479 | 2061 u->header_sent = 1; |
2062 | |
573 | 2063 if (r->request_body && r->request_body->temp_file) { |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2064 ngx_pool_run_cleanup_file(r->pool, r->request_body->temp_file->file.fd); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2065 r->request_body->temp_file->file.fd = NGX_INVALID_FILE; |
563 | 2066 } |
2067 | |
581 | 2068 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
2069 | |
649 | 2070 if (!u->buffering) { |
581 | 2071 |
2072 if (u->input_filter == NULL) { | |
2073 u->input_filter_init = ngx_http_upstream_non_buffered_filter_init; | |
2074 u->input_filter = ngx_http_upstream_non_buffered_filter; | |
2075 u->input_filter_ctx = r; | |
2076 } | |
2077 | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2078 u->read_event_handler = ngx_http_upstream_process_non_buffered_upstream; |
581 | 2079 r->write_event_handler = |
2080 ngx_http_upstream_process_non_buffered_downstream; | |
2081 | |
2082 r->limit_rate = 0; | |
2083 | |
2084 if (u->input_filter_init(u->input_filter_ctx) == NGX_ERROR) { | |
2085 ngx_http_upstream_finalize_request(r, u, 0); | |
2086 return; | |
2087 } | |
2088 | |
583 | 2089 if (clcf->tcp_nodelay && c->tcp_nodelay == NGX_TCP_NODELAY_UNSET) { |
2090 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "tcp_nodelay"); | |
2091 | |
2092 tcp_nodelay = 1; | |
2093 | |
2094 if (setsockopt(c->fd, IPPROTO_TCP, TCP_NODELAY, | |
2095 (const void *) &tcp_nodelay, sizeof(int)) == -1) | |
2096 { | |
2097 ngx_connection_error(c, ngx_socket_errno, | |
2098 "setsockopt(TCP_NODELAY) failed"); | |
2099 ngx_http_upstream_finalize_request(r, u, 0); | |
2100 return; | |
2101 } | |
2102 | |
2103 c->tcp_nodelay = NGX_TCP_NODELAY_SET; | |
2104 } | |
2105 | |
2402 | 2106 n = u->buffer.last - u->buffer.pos; |
2107 | |
2108 if (n) { | |
581 | 2109 u->buffer.last = u->buffer.pos; |
2110 | |
2402 | 2111 u->state->response_length += n; |
2112 | |
2113 if (u->input_filter(u->input_filter_ctx, n) == NGX_ERROR) { | |
581 | 2114 ngx_http_upstream_finalize_request(r, u, 0); |
2115 return; | |
2116 } | |
2117 | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2118 ngx_http_upstream_process_non_buffered_downstream(r); |
581 | 2119 |
2120 } else { | |
2121 u->buffer.pos = u->buffer.start; | |
2122 u->buffer.last = u->buffer.start; | |
2123 | |
2124 if (ngx_http_send_special(r, NGX_HTTP_FLUSH) == NGX_ERROR) { | |
2125 ngx_http_upstream_finalize_request(r, u, 0); | |
2126 return; | |
2127 } | |
1468
491e5059ea19
read EOF of header only responses in non-buffered proxying
Igor Sysoev <igor@sysoev.ru>
parents:
1397
diff
changeset
|
2128 |
491e5059ea19
read EOF of header only responses in non-buffered proxying
Igor Sysoev <igor@sysoev.ru>
parents:
1397
diff
changeset
|
2129 if (u->peer.connection->read->ready) { |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2130 ngx_http_upstream_process_non_buffered_upstream(r, u); |
1468
491e5059ea19
read EOF of header only responses in non-buffered proxying
Igor Sysoev <igor@sysoev.ru>
parents:
1397
diff
changeset
|
2131 } |
581 | 2132 } |
2133 | |
2134 return; | |
2135 } | |
2136 | |
479 | 2137 /* TODO: preallocate event_pipe bufs, look "Content-Length" */ |
2138 | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2139 #if (NGX_HTTP_CACHE) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2140 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2141 if (r->cache && r->cache->file.fd != NGX_INVALID_FILE) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2142 ngx_pool_run_cleanup_file(r->pool, r->cache->file.fd); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2143 r->cache->file.fd = NGX_INVALID_FILE; |
479 | 2144 } |
2145 | |
3699
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2146 switch (ngx_http_test_predicates(r, u->conf->no_cache)) { |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2147 |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2148 case NGX_ERROR: |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2149 ngx_http_upstream_finalize_request(r, u, 0); |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2150 return; |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2151 |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2152 case NGX_DECLINED: |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2153 u->cacheable = 0; |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2154 break; |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2155 |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2156 default: /* NGX_OK */ |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2157 |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2158 if (u->cache_status == NGX_HTTP_CACHE_BYPASS) { |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2159 |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2160 r->cache->min_uses = u->conf->cache_min_uses; |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2161 r->cache->body_start = u->conf->buffer_size; |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2162 r->cache->file_cache = u->conf->cache->data; |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2163 |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2164 if (ngx_http_file_cache_create(r) != NGX_OK) { |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2165 ngx_http_upstream_finalize_request(r, u, 0); |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2166 return; |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2167 } |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2168 |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2169 u->cacheable = 1; |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2170 } |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2171 |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2172 break; |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2173 } |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2174 |
1565 | 2175 if (u->cacheable) { |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2176 time_t now, valid; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2177 |
2663
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
2178 now = ngx_time(); |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
2179 |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
2180 valid = r->cache->valid_sec; |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
2181 |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
2182 if (valid == 0) { |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
2183 valid = ngx_http_file_cache_valid(u->conf->cache_valid, |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
2184 u->headers_in.status_n); |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
2185 if (valid) { |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
2186 r->cache->valid_sec = now + valid; |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
2187 } |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
2188 } |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
2189 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2190 if (valid) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2191 r->cache->last_modified = r->headers_out.last_modified_time; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2192 r->cache->date = now; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2193 r->cache->body_start = (u_short) (u->buffer.pos - u->buffer.start); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2194 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2195 ngx_http_file_cache_set_header(r, u->buffer.start); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2196 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2197 } else { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2198 u->cacheable = 0; |
2703
3b6afa999c2f
support 304 for cacheable responses
Igor Sysoev <igor@sysoev.ru>
parents:
2701
diff
changeset
|
2199 r->headers_out.last_modified_time = -1; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2200 } |
479 | 2201 } |
2202 | |
2690 | 2203 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, |
2204 "http cacheable: %d", u->cacheable); | |
2205 | |
3083
ffe8bfb38184
clean cache updating state if a response has uncacheable code or
Igor Sysoev <igor@sysoev.ru>
parents:
3056
diff
changeset
|
2206 if (u->cacheable == 0 && r->cache) { |
3711
ce6ba077c270
several changes in cache cleanup handling:
Igor Sysoev <igor@sysoev.ru>
parents:
3709
diff
changeset
|
2207 ngx_http_file_cache_free(r->cache, u->pipe->temp_file); |
3083
ffe8bfb38184
clean cache updating state if a response has uncacheable code or
Igor Sysoev <igor@sysoev.ru>
parents:
3056
diff
changeset
|
2208 } |
ffe8bfb38184
clean cache updating state if a response has uncacheable code or
Igor Sysoev <igor@sysoev.ru>
parents:
3056
diff
changeset
|
2209 |
479 | 2210 #endif |
2211 | |
581 | 2212 p = u->pipe; |
479 | 2213 |
2214 p->output_filter = (ngx_event_pipe_output_filter_pt) ngx_http_output_filter; | |
2215 p->output_ctx = r; | |
2216 p->tag = u->output.tag; | |
577 | 2217 p->bufs = u->conf->bufs; |
479 | 2218 p->busy_size = u->conf->busy_buffers_size; |
2219 p->upstream = u->peer.connection; | |
583 | 2220 p->downstream = c; |
479 | 2221 p->pool = r->pool; |
583 | 2222 p->log = c->log; |
577 | 2223 |
1565 | 2224 p->cacheable = u->cacheable || u->store; |
479 | 2225 |
501 | 2226 p->temp_file = ngx_pcalloc(r->pool, sizeof(ngx_temp_file_t)); |
2227 if (p->temp_file == NULL) { | |
479 | 2228 ngx_http_upstream_finalize_request(r, u, 0); |
2229 return; | |
2230 } | |
2231 | |
2232 p->temp_file->file.fd = NGX_INVALID_FILE; | |
583 | 2233 p->temp_file->file.log = c->log; |
479 | 2234 p->temp_file->path = u->conf->temp_path; |
2235 p->temp_file->pool = r->pool; | |
577 | 2236 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2237 if (p->cacheable) { |
479 | 2238 p->temp_file->persistent = 1; |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
2239 |
479 | 2240 } else { |
667 | 2241 p->temp_file->log_level = NGX_LOG_WARN; |
479 | 2242 p->temp_file->warn = "an upstream response is buffered " |
2243 "to a temporary file"; | |
2244 } | |
2245 | |
2246 p->max_temp_file_size = u->conf->max_temp_file_size; | |
2247 p->temp_file_write_size = u->conf->temp_file_write_size; | |
2248 | |
501 | 2249 p->preread_bufs = ngx_alloc_chain_link(r->pool); |
2250 if (p->preread_bufs == NULL) { | |
479 | 2251 ngx_http_upstream_finalize_request(r, u, 0); |
2252 return; | |
2253 } | |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
2254 |
581 | 2255 p->preread_bufs->buf = &u->buffer; |
479 | 2256 p->preread_bufs->next = NULL; |
581 | 2257 u->buffer.recycled = 1; |
2258 | |
2259 p->preread_size = u->buffer.last - u->buffer.pos; | |
479 | 2260 |
1565 | 2261 if (u->cacheable) { |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
2262 |
479 | 2263 p->buf_to_file = ngx_calloc_buf(r->pool); |
2264 if (p->buf_to_file == NULL) { | |
2265 ngx_http_upstream_finalize_request(r, u, 0); | |
2266 return; | |
2267 } | |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
2268 |
581 | 2269 p->buf_to_file->pos = u->buffer.start; |
2270 p->buf_to_file->last = u->buffer.pos; | |
479 | 2271 p->buf_to_file->temporary = 1; |
2272 } | |
2273 | |
2274 if (ngx_event_flags & NGX_USE_AIO_EVENT) { | |
2275 /* the posted aio operation may currupt a shadow buffer */ | |
2276 p->single_buf = 1; | |
2277 } | |
2278 | |
2279 /* TODO: p->free_bufs = 0 if use ngx_create_chain_of_bufs() */ | |
2280 p->free_bufs = 1; | |
2281 | |
2282 /* | |
581 | 2283 * event_pipe would do u->buffer.last += p->preread_size |
479 | 2284 * as though these bytes were read |
2285 */ | |
581 | 2286 u->buffer.last = u->buffer.pos; |
479 | 2287 |
2288 if (u->conf->cyclic_temp_file) { | |
2289 | |
2290 /* | |
2291 * we need to disable the use of sendfile() if we use cyclic temp file | |
2292 * because the writing a new data may interfere with sendfile() | |
2293 * that uses the same kernel file pages (at least on FreeBSD) | |
2294 */ | |
2295 | |
2296 p->cyclic_temp_file = 1; | |
583 | 2297 c->sendfile = 0; |
479 | 2298 |
2299 } else { | |
2300 p->cyclic_temp_file = 0; | |
2301 } | |
2302 | |
2303 p->read_timeout = u->conf->read_timeout; | |
2304 p->send_timeout = clcf->send_timeout; | |
2305 p->send_lowat = clcf->send_lowat; | |
2306 | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2307 u->read_event_handler = ngx_http_upstream_process_upstream; |
509 | 2308 r->write_event_handler = ngx_http_upstream_process_downstream; |
479 | 2309 |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2310 ngx_http_upstream_process_upstream(r, u); |
479 | 2311 } |
2312 | |
2313 | |
487 | 2314 static void |
581 | 2315 ngx_http_upstream_process_non_buffered_downstream(ngx_http_request_t *r) |
2316 { | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2317 ngx_event_t *wev; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2318 ngx_connection_t *c; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2319 ngx_http_upstream_t *u; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2320 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2321 c = r->connection; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2322 u = r->upstream; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2323 wev = c->write; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2324 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2325 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2326 "http upstream process non buffered downstream"); |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2327 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2328 c->log->action = "sending to client"; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2329 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2330 if (wev->timedout) { |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2331 c->timedout = 1; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2332 ngx_connection_error(c, NGX_ETIMEDOUT, "client timed out"); |
3963
10fbb8f02a45
finalizing with rc == 0 in unbuffered proxy mode caused nginx to wait
Igor Sysoev <igor@sysoev.ru>
parents:
3944
diff
changeset
|
2333 ngx_http_upstream_finalize_request(r, u, NGX_HTTP_REQUEST_TIME_OUT); |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2334 return; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2335 } |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2336 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2337 ngx_http_upstream_process_non_buffered_request(r, 1); |
581 | 2338 } |
2339 | |
2340 | |
2341 static void | |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2342 ngx_http_upstream_process_non_buffered_upstream(ngx_http_request_t *r, |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2343 ngx_http_upstream_t *u) |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2344 { |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2345 ngx_connection_t *c; |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2346 |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2347 c = u->peer.connection; |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2348 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2349 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2350 "http upstream process non buffered upstream"); |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2351 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2352 c->log->action = "reading upstream"; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2353 |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2354 if (c->read->timedout) { |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2355 ngx_connection_error(c, NGX_ETIMEDOUT, "upstream timed out"); |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2356 ngx_http_upstream_finalize_request(r, u, 0); |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2357 return; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2358 } |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2359 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2360 ngx_http_upstream_process_non_buffered_request(r, 0); |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2361 } |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2362 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2363 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2364 static void |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2365 ngx_http_upstream_process_non_buffered_request(ngx_http_request_t *r, |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2366 ngx_uint_t do_write) |
581 | 2367 { |
2368 size_t size; | |
2369 ssize_t n; | |
2370 ngx_buf_t *b; | |
583 | 2371 ngx_int_t rc; |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2372 ngx_connection_t *downstream, *upstream; |
581 | 2373 ngx_http_upstream_t *u; |
2374 ngx_http_core_loc_conf_t *clcf; | |
2375 | |
756
d904b5cb3bba
fix building introduced by previous commit
Igor Sysoev <igor@sysoev.ru>
parents:
755
diff
changeset
|
2376 u = r->upstream; |
884 | 2377 downstream = r->connection; |
2378 upstream = u->peer.connection; | |
581 | 2379 |
2380 b = &u->buffer; | |
2381 | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2382 do_write = do_write || u->length == 0; |
581 | 2383 |
2384 for ( ;; ) { | |
2385 | |
2386 if (do_write) { | |
2387 | |
2388 if (u->out_bufs || u->busy_bufs) { | |
583 | 2389 rc = ngx_http_output_filter(r, u->out_bufs); |
2390 | |
2391 if (rc == NGX_ERROR) { | |
581 | 2392 ngx_http_upstream_finalize_request(r, u, 0); |
2393 return; | |
2394 } | |
2395 | |
4114
5db098f97e0e
API change: ngx_chain_update_chains() now requires pool.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3976
diff
changeset
|
2396 ngx_chain_update_chains(r->pool, &u->free_bufs, &u->busy_bufs, |
581 | 2397 &u->out_bufs, u->output.tag); |
2398 } | |
2399 | |
2400 if (u->busy_bufs == NULL) { | |
2401 | |
2402 if (u->length == 0 | |
884 | 2403 || upstream->read->eof |
2404 || upstream->read->error) | |
581 | 2405 { |
2406 ngx_http_upstream_finalize_request(r, u, 0); | |
2407 return; | |
2408 } | |
2409 | |
2410 b->pos = b->start; | |
2411 b->last = b->start; | |
2412 } | |
2413 } | |
2414 | |
2415 size = b->end - b->last; | |
2416 | |
884 | 2417 if (size && upstream->read->ready) { |
2418 | |
2419 n = upstream->recv(upstream, b->last, size); | |
581 | 2420 |
2421 if (n == NGX_AGAIN) { | |
2422 break; | |
2423 } | |
2424 | |
2425 if (n > 0) { | |
2402 | 2426 u->state->response_length += n; |
2427 | |
581 | 2428 if (u->input_filter(u->input_filter_ctx, n) == NGX_ERROR) { |
2429 ngx_http_upstream_finalize_request(r, u, 0); | |
2430 return; | |
2431 } | |
2432 } | |
2433 | |
2434 do_write = 1; | |
2435 | |
2436 continue; | |
2437 } | |
2438 | |
2439 break; | |
2440 } | |
2441 | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2442 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2443 |
884 | 2444 if (downstream->data == r) { |
2445 if (ngx_handle_write_event(downstream->write, clcf->send_lowat) | |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
2446 != NGX_OK) |
583 | 2447 { |
2448 ngx_http_upstream_finalize_request(r, u, 0); | |
2449 return; | |
2450 } | |
581 | 2451 } |
2452 | |
1063
e2a6ecc5a3ae
a non-active client connection must not closed after send timeout
Igor Sysoev <igor@sysoev.ru>
parents:
1031
diff
changeset
|
2453 if (downstream->write->active && !downstream->write->ready) { |
884 | 2454 ngx_add_timer(downstream->write, clcf->send_timeout); |
2455 | |
2456 } else if (downstream->write->timer_set) { | |
2457 ngx_del_timer(downstream->write); | |
581 | 2458 } |
2459 | |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
2460 if (ngx_handle_read_event(upstream->read, 0) != NGX_OK) { |
581 | 2461 ngx_http_upstream_finalize_request(r, u, 0); |
2462 return; | |
2463 } | |
2464 | |
1063
e2a6ecc5a3ae
a non-active client connection must not closed after send timeout
Igor Sysoev <igor@sysoev.ru>
parents:
1031
diff
changeset
|
2465 if (upstream->read->active && !upstream->read->ready) { |
884 | 2466 ngx_add_timer(upstream->read, u->conf->read_timeout); |
2467 | |
2468 } else if (upstream->read->timer_set) { | |
2469 ngx_del_timer(upstream->read); | |
581 | 2470 } |
2471 } | |
2472 | |
2473 | |
2474 static ngx_int_t | |
2475 ngx_http_upstream_non_buffered_filter_init(void *data) | |
2476 { | |
2477 return NGX_OK; | |
2478 } | |
2479 | |
2480 | |
2481 static ngx_int_t | |
2482 ngx_http_upstream_non_buffered_filter(void *data, ssize_t bytes) | |
2483 { | |
2484 ngx_http_request_t *r = data; | |
2485 | |
2486 ngx_buf_t *b; | |
2487 ngx_chain_t *cl, **ll; | |
2488 ngx_http_upstream_t *u; | |
2489 | |
2490 u = r->upstream; | |
2491 | |
2492 for (cl = u->out_bufs, ll = &u->out_bufs; cl; cl = cl->next) { | |
2493 ll = &cl->next; | |
2494 } | |
2495 | |
2496 cl = ngx_chain_get_free_buf(r->pool, &u->free_bufs); | |
2497 if (cl == NULL) { | |
2498 return NGX_ERROR; | |
2499 } | |
2500 | |
2501 *ll = cl; | |
2502 | |
2503 cl->buf->flush = 1; | |
2504 cl->buf->memory = 1; | |
2505 | |
2506 b = &u->buffer; | |
2507 | |
2508 cl->buf->pos = b->last; | |
2509 b->last += bytes; | |
2510 cl->buf->last = b->last; | |
1908
f2953601ed3c
fix memory leak in long-lived non buffered connections
Igor Sysoev <igor@sysoev.ru>
parents:
1902
diff
changeset
|
2511 cl->buf->tag = u->output.tag; |
581 | 2512 |
4118
dbddec65fdab
Upstream: r->upstream->length type change to off_t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4117
diff
changeset
|
2513 if (u->length == -1) { |
581 | 2514 return NGX_OK; |
2515 } | |
2516 | |
2517 u->length -= bytes; | |
2518 | |
2519 return NGX_OK; | |
2520 } | |
2521 | |
2522 | |
2523 static void | |
509 | 2524 ngx_http_upstream_process_downstream(ngx_http_request_t *r) |
2525 { | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2526 ngx_event_t *wev; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2527 ngx_connection_t *c; |
509 | 2528 ngx_event_pipe_t *p; |
479 | 2529 ngx_http_upstream_t *u; |
2530 | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2531 c = r->connection; |
479 | 2532 u = r->upstream; |
581 | 2533 p = u->pipe; |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2534 wev = c->write; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2535 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2536 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2537 "http upstream process downstream"); |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2538 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2539 c->log->action = "sending to client"; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2540 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2541 if (wev->timedout) { |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2542 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2543 if (wev->delayed) { |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2544 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2545 wev->timedout = 0; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2546 wev->delayed = 0; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2547 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2548 if (!wev->ready) { |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2549 ngx_add_timer(wev, p->send_timeout); |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2550 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2551 if (ngx_handle_write_event(wev, p->send_lowat) != NGX_OK) { |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2552 ngx_http_upstream_finalize_request(r, u, 0); |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2553 } |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2554 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2555 return; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2556 } |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2557 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2558 if (ngx_event_pipe(p, wev->write) == NGX_ABORT) { |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2559 ngx_http_upstream_finalize_request(r, u, 0); |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2560 return; |
527 | 2561 } |
479 | 2562 |
2563 } else { | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2564 p->downstream_error = 1; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2565 c->timedout = 1; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2566 ngx_connection_error(c, NGX_ETIMEDOUT, "client timed out"); |
479 | 2567 } |
2568 | |
2569 } else { | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2570 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2571 if (wev->delayed) { |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2572 |
527 | 2573 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, |
2574 "http downstream delayed"); | |
2575 | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2576 if (ngx_handle_write_event(wev, p->send_lowat) != NGX_OK) { |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
2577 ngx_http_upstream_finalize_request(r, u, 0); |
527 | 2578 } |
2579 | |
2580 return; | |
2581 } | |
2582 | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2583 if (ngx_event_pipe(p, 1) == NGX_ABORT) { |
479 | 2584 ngx_http_upstream_finalize_request(r, u, 0); |
2585 return; | |
2586 } | |
2587 } | |
577 | 2588 |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2589 ngx_http_upstream_process_request(r); |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2590 } |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2591 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2592 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2593 static void |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2594 ngx_http_upstream_process_upstream(ngx_http_request_t *r, |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2595 ngx_http_upstream_t *u) |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2596 { |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2597 ngx_connection_t *c; |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2598 |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2599 c = u->peer.connection; |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2600 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2601 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2602 "http upstream process upstream"); |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2603 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2604 c->log->action = "reading upstream"; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2605 |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2606 if (c->read->timedout) { |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2607 u->pipe->upstream_error = 1; |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2608 ngx_connection_error(c, NGX_ETIMEDOUT, "upstream timed out"); |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2609 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2610 } else { |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2611 if (ngx_event_pipe(u->pipe, 0) == NGX_ABORT) { |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2612 ngx_http_upstream_finalize_request(r, u, 0); |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2613 return; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2614 } |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2615 } |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2616 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2617 ngx_http_upstream_process_request(r); |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2618 } |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2619 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2620 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2621 static void |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2622 ngx_http_upstream_process_request(ngx_http_request_t *r) |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2623 { |
2445
3c6af1fb7586
proxy/fastcgi_store did not delete incomplete files
Igor Sysoev <igor@sysoev.ru>
parents:
2441
diff
changeset
|
2624 ngx_uint_t del; |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2625 ngx_temp_file_t *tf; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2626 ngx_event_pipe_t *p; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2627 ngx_http_upstream_t *u; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2628 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2629 u = r->upstream; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2630 p = u->pipe; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2631 |
479 | 2632 if (u->peer.connection) { |
2633 | |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
2634 if (u->store) { |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
2635 |
2445
3c6af1fb7586
proxy/fastcgi_store did not delete incomplete files
Igor Sysoev <igor@sysoev.ru>
parents:
2441
diff
changeset
|
2636 del = p->upstream_error; |
3c6af1fb7586
proxy/fastcgi_store did not delete incomplete files
Igor Sysoev <igor@sysoev.ru>
parents:
2441
diff
changeset
|
2637 |
1885
e5897822515f
test response length in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1777
diff
changeset
|
2638 tf = u->pipe->temp_file; |
e5897822515f
test response length in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1777
diff
changeset
|
2639 |
2463 | 2640 if (p->upstream_eof || p->upstream_done) { |
2445
3c6af1fb7586
proxy/fastcgi_store did not delete incomplete files
Igor Sysoev <igor@sysoev.ru>
parents:
2441
diff
changeset
|
2641 |
3c6af1fb7586
proxy/fastcgi_store did not delete incomplete files
Igor Sysoev <igor@sysoev.ru>
parents:
2441
diff
changeset
|
2642 if (u->headers_in.status_n == NGX_HTTP_OK |
3c6af1fb7586
proxy/fastcgi_store did not delete incomplete files
Igor Sysoev <igor@sysoev.ru>
parents:
2441
diff
changeset
|
2643 && (u->headers_in.content_length_n == -1 |
3c6af1fb7586
proxy/fastcgi_store did not delete incomplete files
Igor Sysoev <igor@sysoev.ru>
parents:
2441
diff
changeset
|
2644 || (u->headers_in.content_length_n == tf->offset))) |
3c6af1fb7586
proxy/fastcgi_store did not delete incomplete files
Igor Sysoev <igor@sysoev.ru>
parents:
2441
diff
changeset
|
2645 { |
3c6af1fb7586
proxy/fastcgi_store did not delete incomplete files
Igor Sysoev <igor@sysoev.ru>
parents:
2441
diff
changeset
|
2646 ngx_http_upstream_store(r, u); |
3c6af1fb7586
proxy/fastcgi_store did not delete incomplete files
Igor Sysoev <igor@sysoev.ru>
parents:
2441
diff
changeset
|
2647 |
3c6af1fb7586
proxy/fastcgi_store did not delete incomplete files
Igor Sysoev <igor@sysoev.ru>
parents:
2441
diff
changeset
|
2648 } else { |
3c6af1fb7586
proxy/fastcgi_store did not delete incomplete files
Igor Sysoev <igor@sysoev.ru>
parents:
2441
diff
changeset
|
2649 del = 1; |
3c6af1fb7586
proxy/fastcgi_store did not delete incomplete files
Igor Sysoev <igor@sysoev.ru>
parents:
2441
diff
changeset
|
2650 } |
3c6af1fb7586
proxy/fastcgi_store did not delete incomplete files
Igor Sysoev <igor@sysoev.ru>
parents:
2441
diff
changeset
|
2651 } |
3c6af1fb7586
proxy/fastcgi_store did not delete incomplete files
Igor Sysoev <igor@sysoev.ru>
parents:
2441
diff
changeset
|
2652 |
3c6af1fb7586
proxy/fastcgi_store did not delete incomplete files
Igor Sysoev <igor@sysoev.ru>
parents:
2441
diff
changeset
|
2653 if (del && tf->file.fd != NGX_INVALID_FILE) { |
3c6af1fb7586
proxy/fastcgi_store did not delete incomplete files
Igor Sysoev <igor@sysoev.ru>
parents:
2441
diff
changeset
|
2654 |
1885
e5897822515f
test response length in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1777
diff
changeset
|
2655 if (ngx_delete_file(tf->file.name.data) == NGX_FILE_ERROR) { |
e5897822515f
test response length in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1777
diff
changeset
|
2656 |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
2657 ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno, |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
2658 ngx_delete_file_n " \"%s\" failed", |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
2659 u->pipe->temp_file->file.name.data); |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
2660 } |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
2661 } |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
2662 } |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
2663 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2664 #if (NGX_HTTP_CACHE) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2665 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2666 if (u->cacheable) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2667 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2668 if (p->upstream_done) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2669 ngx_http_file_cache_update(r, u->pipe->temp_file); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2670 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2671 } else if (p->upstream_eof) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2672 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2673 /* TODO: check length & update cache */ |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2674 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2675 ngx_http_file_cache_update(r, u->pipe->temp_file); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2676 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2677 } else if (p->upstream_error) { |
3711
ce6ba077c270
several changes in cache cleanup handling:
Igor Sysoev <igor@sysoev.ru>
parents:
3709
diff
changeset
|
2678 ngx_http_file_cache_free(r->cache, u->pipe->temp_file); |
479 | 2679 } |
2680 } | |
2681 | |
2682 #endif | |
2683 | |
2684 if (p->upstream_done || p->upstream_eof || p->upstream_error) { | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2685 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
483 | 2686 "http upstream exit: %p", p->out); |
479 | 2687 #if 0 |
2688 ngx_http_busy_unlock(u->conf->busy_lock, &u->busy_lock); | |
2689 #endif | |
2690 ngx_http_upstream_finalize_request(r, u, 0); | |
2691 return; | |
2692 } | |
2693 } | |
2694 | |
2695 if (p->downstream_error) { | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2696 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
483 | 2697 "http upstream downstream error"); |
479 | 2698 |
2757
9cc973b46af1
get a full response if the response is cacheable or storable even
Igor Sysoev <igor@sysoev.ru>
parents:
2708
diff
changeset
|
2699 if (!u->cacheable && !u->store && u->peer.connection) { |
479 | 2700 ngx_http_upstream_finalize_request(r, u, 0); |
2701 } | |
2702 } | |
2703 } | |
2704 | |
2705 | |
487 | 2706 static void |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
2707 ngx_http_upstream_store(ngx_http_request_t *r, ngx_http_upstream_t *u) |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
2708 { |
1947
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
2709 size_t root; |
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
2710 time_t lm; |
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
2711 ngx_str_t path; |
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
2712 ngx_temp_file_t *tf; |
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
2713 ngx_ext_rename_file_t ext; |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
2714 |
1777 | 2715 tf = u->pipe->temp_file; |
2716 | |
2717 if (tf->file.fd == NGX_INVALID_FILE) { | |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
2718 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
2719 /* create file for empty 200 response */ |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
2720 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
2721 tf = ngx_pcalloc(r->pool, sizeof(ngx_temp_file_t)); |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
2722 if (tf == NULL) { |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
2723 return; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
2724 } |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
2725 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
2726 tf->file.fd = NGX_INVALID_FILE; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
2727 tf->file.log = r->connection->log; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
2728 tf->path = u->conf->temp_path; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
2729 tf->pool = r->pool; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
2730 tf->persistent = 1; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
2731 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
2732 if (ngx_create_temp_file(&tf->file, tf->path, tf->pool, |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
2733 tf->persistent, tf->clean, tf->access) |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
2734 != NGX_OK) |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
2735 { |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
2736 return; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
2737 } |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
2738 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
2739 u->pipe->temp_file = tf; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
2740 } |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
2741 |
1947
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
2742 ext.access = u->conf->store_access; |
2394
dbe746851b31
use ngx_ext_rename_file() for single file MOVE
Igor Sysoev <igor@sysoev.ru>
parents:
2386
diff
changeset
|
2743 ext.path_access = u->conf->store_access; |
1947
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
2744 ext.time = -1; |
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
2745 ext.create_path = 1; |
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
2746 ext.delete_file = 1; |
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
2747 ext.log = r->connection->log; |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
2748 |
1705 | 2749 if (u->headers_in.last_modified) { |
2750 | |
1947
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
2751 lm = ngx_http_parse_time(u->headers_in.last_modified->value.data, |
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
2752 u->headers_in.last_modified->value.len); |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
2753 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
2754 if (lm != NGX_ERROR) { |
1947
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
2755 ext.time = lm; |
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
2756 ext.fd = tf->file.fd; |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
2757 } |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
2758 } |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
2759 |
1295
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2760 if (u->conf->store_lengths == NULL) { |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2761 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2762 ngx_http_map_uri_to_path(r, &path, &root, 0); |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2763 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2764 } else { |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2765 if (ngx_http_script_run(r, &path, u->conf->store_lengths->elts, 0, |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2766 u->conf->store_values->elts) |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2767 == NULL) |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2768 { |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2769 return; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2770 } |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2771 } |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
2772 |
3032
524ba56ba9f7
fix copy destination name length, introduced in r3025
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
2773 path.len--; |
524ba56ba9f7
fix copy destination name length, introduced in r3025
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
2774 |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
2775 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
1947
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
2776 "upstream stores \"%s\" to \"%s\"", |
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
2777 tf->file.name.data, path.data); |
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
2778 |
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
2779 (void) ngx_ext_rename_file(&tf->file.name, &path, &ext); |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
2780 } |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
2781 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
2782 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
2783 static void |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2784 ngx_http_upstream_dummy_handler(ngx_http_request_t *r, ngx_http_upstream_t *u) |
479 | 2785 { |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2786 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
479 | 2787 "http upstream dummy handler"); |
2788 } | |
2789 | |
2790 | |
487 | 2791 static void |
2792 ngx_http_upstream_next(ngx_http_request_t *r, ngx_http_upstream_t *u, | |
2793 ngx_uint_t ft_type) | |
479 | 2794 { |
884 | 2795 ngx_uint_t status, state; |
479 | 2796 |
2797 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
884 | 2798 "http next upstream, %xi", ft_type); |
479 | 2799 |
2800 #if 0 | |
2801 ngx_http_busy_unlock(u->conf->busy_lock, &u->busy_lock); | |
2802 #endif | |
2803 | |
525 | 2804 if (ft_type == NGX_HTTP_UPSTREAM_FT_HTTP_404) { |
884 | 2805 state = NGX_PEER_NEXT; |
525 | 2806 } else { |
884 | 2807 state = NGX_PEER_FAILED; |
479 | 2808 } |
525 | 2809 |
1378 | 2810 if (ft_type != NGX_HTTP_UPSTREAM_FT_NOLIVE) { |
2811 u->peer.free(&u->peer, u->peer.data, state); | |
2812 } | |
525 | 2813 |
479 | 2814 if (ft_type == NGX_HTTP_UPSTREAM_FT_TIMEOUT) { |
2815 ngx_log_error(NGX_LOG_ERR, r->connection->log, NGX_ETIMEDOUT, | |
2816 "upstream timed out"); | |
2817 } | |
577 | 2818 |
479 | 2819 if (u->peer.cached && ft_type == NGX_HTTP_UPSTREAM_FT_ERROR) { |
2820 status = 0; | |
2821 | |
4115
70a45a504905
Workaround for cpu hog on errors with cached connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4114
diff
changeset
|
2822 /* TODO: inform balancer instead */ |
70a45a504905
Workaround for cpu hog on errors with cached connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4114
diff
changeset
|
2823 |
70a45a504905
Workaround for cpu hog on errors with cached connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4114
diff
changeset
|
2824 u->peer.tries++; |
70a45a504905
Workaround for cpu hog on errors with cached connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4114
diff
changeset
|
2825 |
479 | 2826 } else { |
2827 switch(ft_type) { | |
2828 | |
2829 case NGX_HTTP_UPSTREAM_FT_TIMEOUT: | |
2830 status = NGX_HTTP_GATEWAY_TIME_OUT; | |
2831 break; | |
2832 | |
2833 case NGX_HTTP_UPSTREAM_FT_HTTP_500: | |
2834 status = NGX_HTTP_INTERNAL_SERVER_ERROR; | |
2835 break; | |
2836 | |
2837 case NGX_HTTP_UPSTREAM_FT_HTTP_404: | |
2838 status = NGX_HTTP_NOT_FOUND; | |
2839 break; | |
2840 | |
2841 /* | |
2842 * NGX_HTTP_UPSTREAM_FT_BUSY_LOCK and NGX_HTTP_UPSTREAM_FT_MAX_WAITING | |
2843 * never reach here | |
2844 */ | |
2845 | |
2846 default: | |
2847 status = NGX_HTTP_BAD_GATEWAY; | |
2848 } | |
2849 } | |
2850 | |
583 | 2851 if (r->connection->error) { |
479 | 2852 ngx_http_upstream_finalize_request(r, u, |
2853 NGX_HTTP_CLIENT_CLOSED_REQUEST); | |
2854 return; | |
2855 } | |
2856 | |
2857 if (status) { | |
2858 u->state->status = status; | |
2859 | |
525 | 2860 if (u->peer.tries == 0 || !(u->conf->next_upstream & ft_type)) { |
479 | 2861 |
2862 #if (NGX_HTTP_CACHE) | |
2863 | |
2952 | 2864 if (u->cache_status == NGX_HTTP_CACHE_EXPIRED |
2865 && (u->conf->cache_use_stale & ft_type)) | |
2866 { | |
2805
60551422e150
reinit proxy/fastcgi header parser before ngx_http_upstream_cache_send()
Igor Sysoev <igor@sysoev.ru>
parents:
2804
diff
changeset
|
2867 ngx_int_t rc; |
60551422e150
reinit proxy/fastcgi header parser before ngx_http_upstream_cache_send()
Igor Sysoev <igor@sysoev.ru>
parents:
2804
diff
changeset
|
2868 |
60551422e150
reinit proxy/fastcgi header parser before ngx_http_upstream_cache_send()
Igor Sysoev <igor@sysoev.ru>
parents:
2804
diff
changeset
|
2869 rc = u->reinit_request(r); |
60551422e150
reinit proxy/fastcgi header parser before ngx_http_upstream_cache_send()
Igor Sysoev <igor@sysoev.ru>
parents:
2804
diff
changeset
|
2870 |
60551422e150
reinit proxy/fastcgi header parser before ngx_http_upstream_cache_send()
Igor Sysoev <igor@sysoev.ru>
parents:
2804
diff
changeset
|
2871 if (rc == NGX_OK) { |
2952 | 2872 u->cache_status = NGX_HTTP_CACHE_STALE; |
2805
60551422e150
reinit proxy/fastcgi header parser before ngx_http_upstream_cache_send()
Igor Sysoev <igor@sysoev.ru>
parents:
2804
diff
changeset
|
2873 rc = ngx_http_upstream_cache_send(r, u); |
60551422e150
reinit proxy/fastcgi header parser before ngx_http_upstream_cache_send()
Igor Sysoev <igor@sysoev.ru>
parents:
2804
diff
changeset
|
2874 } |
60551422e150
reinit proxy/fastcgi header parser before ngx_http_upstream_cache_send()
Igor Sysoev <igor@sysoev.ru>
parents:
2804
diff
changeset
|
2875 |
60551422e150
reinit proxy/fastcgi header parser before ngx_http_upstream_cache_send()
Igor Sysoev <igor@sysoev.ru>
parents:
2804
diff
changeset
|
2876 ngx_http_upstream_finalize_request(r, u, rc); |
479 | 2877 return; |
2878 } | |
2879 #endif | |
2880 | |
2881 ngx_http_upstream_finalize_request(r, u, status); | |
2882 return; | |
2883 } | |
2884 } | |
2885 | |
2886 if (u->peer.connection) { | |
2887 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
2888 "close http upstream connection: %d", | |
2889 u->peer.connection->fd); | |
577 | 2890 #if (NGX_HTTP_SSL) |
884 | 2891 |
577 | 2892 if (u->peer.connection->ssl) { |
884 | 2893 u->peer.connection->ssl->no_wait_shutdown = 1; |
2894 u->peer.connection->ssl->no_send_shutdown = 1; | |
2895 | |
2896 (void) ngx_ssl_shutdown(u->peer.connection); | |
577 | 2897 } |
2898 #endif | |
884 | 2899 |
4116
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
2900 ngx_destroy_pool(u->peer.connection->pool); |
479 | 2901 ngx_close_connection(u->peer.connection); |
2902 } | |
2903 | |
2904 #if 0 | |
2905 if (u->conf->busy_lock && !u->busy_locked) { | |
2906 ngx_http_upstream_busy_lock(p); | |
2907 return; | |
2908 } | |
2909 #endif | |
2910 | |
2911 ngx_http_upstream_connect(r, u); | |
2912 } | |
2913 | |
2914 | |
487 | 2915 static void |
569 | 2916 ngx_http_upstream_cleanup(void *data) |
2917 { | |
2918 ngx_http_request_t *r = data; | |
2919 | |
1705 | 2920 ngx_http_upstream_t *u; |
2921 | |
569 | 2922 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
2923 "cleanup http upstream request: \"%V\"", &r->uri); | |
2924 | |
1705 | 2925 u = r->upstream; |
2926 | |
2927 if (u->resolved && u->resolved->ctx) { | |
2928 ngx_resolve_name_done(u->resolved->ctx); | |
3169
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
2929 u->resolved->ctx = NULL; |
1658 | 2930 } |
2931 | |
1705 | 2932 ngx_http_upstream_finalize_request(r, u, NGX_DONE); |
569 | 2933 } |
2934 | |
2935 | |
2936 static void | |
487 | 2937 ngx_http_upstream_finalize_request(ngx_http_request_t *r, |
2938 ngx_http_upstream_t *u, ngx_int_t rc) | |
479 | 2939 { |
889
a9a7e4b1a72b
the previous fix does not actually fix overflow
Igor Sysoev <igor@sysoev.ru>
parents:
888
diff
changeset
|
2940 ngx_time_t *tp; |
563 | 2941 |
483 | 2942 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
2943 "finalize http upstream request: %i", rc); | |
479 | 2944 |
2413 | 2945 if (u->cleanup) { |
2946 *u->cleanup = NULL; | |
3418
a076e1823737
delete u->cleanup mark, this fixes large values in $upstream_response_time,
Igor Sysoev <igor@sysoev.ru>
parents:
3401
diff
changeset
|
2947 u->cleanup = NULL; |
2413 | 2948 } |
569 | 2949 |
3169
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
2950 if (u->resolved && u->resolved->ctx) { |
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
2951 ngx_resolve_name_done(u->resolved->ctx); |
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
2952 u->resolved->ctx = NULL; |
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
2953 } |
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
2954 |
1658 | 2955 if (u->state && u->state->response_sec) { |
563 | 2956 tp = ngx_timeofday(); |
889
a9a7e4b1a72b
the previous fix does not actually fix overflow
Igor Sysoev <igor@sysoev.ru>
parents:
888
diff
changeset
|
2957 u->state->response_sec = tp->sec - u->state->response_sec; |
a9a7e4b1a72b
the previous fix does not actually fix overflow
Igor Sysoev <igor@sysoev.ru>
parents:
888
diff
changeset
|
2958 u->state->response_msec = tp->msec - u->state->response_msec; |
2402 | 2959 |
2960 if (u->pipe) { | |
2961 u->state->response_length = u->pipe->read_length; | |
2962 } | |
563 | 2963 } |
2964 | |
479 | 2965 u->finalize_request(r, rc); |
2966 | |
1658 | 2967 if (u->peer.free) { |
2968 u->peer.free(&u->peer, u->peer.data, 0); | |
2969 } | |
884 | 2970 |
479 | 2971 if (u->peer.connection) { |
884 | 2972 |
577 | 2973 #if (NGX_HTTP_SSL) |
2974 | |
2975 /* TODO: do not shutdown persistent connection */ | |
2976 | |
2977 if (u->peer.connection->ssl) { | |
884 | 2978 |
2979 /* | |
2980 * We send the "close notify" shutdown alert to the upstream only | |
2981 * and do not wait its "close notify" shutdown alert. | |
2982 * It is acceptable according to the TLS standard. | |
2983 */ | |
2984 | |
2985 u->peer.connection->ssl->no_wait_shutdown = 1; | |
2986 | |
2987 (void) ngx_ssl_shutdown(u->peer.connection); | |
577 | 2988 } |
2989 #endif | |
884 | 2990 |
2991 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
2992 "close http upstream connection: %d", | |
2993 u->peer.connection->fd); | |
2994 | |
4116
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
2995 ngx_destroy_pool(u->peer.connection->pool); |
479 | 2996 ngx_close_connection(u->peer.connection); |
2997 } | |
2998 | |
483 | 2999 u->peer.connection = NULL; |
3000 | |
581 | 3001 if (u->pipe && u->pipe->temp_file) { |
479 | 3002 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
3003 "http upstream temp fd: %d", | |
581 | 3004 u->pipe->temp_file->file.fd); |
479 | 3005 } |
3006 | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3007 #if (NGX_HTTP_CACHE) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3008 |
3940
22f3e9197096
revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents:
3934
diff
changeset
|
3009 if (r->cache) { |
22f3e9197096
revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents:
3934
diff
changeset
|
3010 |
22f3e9197096
revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents:
3934
diff
changeset
|
3011 if (u->cacheable) { |
22f3e9197096
revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents:
3934
diff
changeset
|
3012 |
22f3e9197096
revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents:
3934
diff
changeset
|
3013 if (rc == NGX_HTTP_BAD_GATEWAY || rc == NGX_HTTP_GATEWAY_TIME_OUT) { |
22f3e9197096
revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents:
3934
diff
changeset
|
3014 time_t valid; |
22f3e9197096
revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents:
3934
diff
changeset
|
3015 |
22f3e9197096
revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents:
3934
diff
changeset
|
3016 valid = ngx_http_file_cache_valid(u->conf->cache_valid, rc); |
22f3e9197096
revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents:
3934
diff
changeset
|
3017 |
22f3e9197096
revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents:
3934
diff
changeset
|
3018 if (valid) { |
22f3e9197096
revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents:
3934
diff
changeset
|
3019 r->cache->valid_sec = ngx_time() + valid; |
22f3e9197096
revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents:
3934
diff
changeset
|
3020 r->cache->error = rc; |
22f3e9197096
revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents:
3934
diff
changeset
|
3021 } |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3022 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3023 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3024 |
3711
ce6ba077c270
several changes in cache cleanup handling:
Igor Sysoev <igor@sysoev.ru>
parents:
3709
diff
changeset
|
3025 ngx_http_file_cache_free(r->cache, u->pipe->temp_file); |
479 | 3026 } |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3027 |
479 | 3028 #endif |
3029 | |
2692 | 3030 if (u->header_sent |
3963
10fbb8f02a45
finalizing with rc == 0 in unbuffered proxy mode caused nginx to wait
Igor Sysoev <igor@sysoev.ru>
parents:
3944
diff
changeset
|
3031 && rc != NGX_HTTP_REQUEST_TIME_OUT |
2692 | 3032 && (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE)) |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3033 { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3034 rc = 0; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3035 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3036 |
515 | 3037 if (rc == NGX_DECLINED) { |
3038 return; | |
3039 } | |
3040 | |
483 | 3041 r->connection->log->action = "sending to client"; |
3042 | |
2971
87ddbe960172
fix ngx_http_send_special() for subrequests handled by perl
Igor Sysoev <igor@sysoev.ru>
parents:
2957
diff
changeset
|
3043 if (rc == 0) { |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
3044 rc = ngx_http_send_special(r, NGX_HTTP_LAST); |
479 | 3045 } |
3046 | |
3047 ngx_http_finalize_request(r, rc); | |
3048 } | |
3049 | |
3050 | |
509 | 3051 static ngx_int_t |
3052 ngx_http_upstream_process_header_line(ngx_http_request_t *r, ngx_table_elt_t *h, | |
3053 ngx_uint_t offset) | |
577 | 3054 { |
509 | 3055 ngx_table_elt_t **ph; |
577 | 3056 |
509 | 3057 ph = (ngx_table_elt_t **) ((char *) &r->upstream->headers_in + offset); |
3058 | |
3059 if (*ph == NULL) { | |
3060 *ph = h; | |
3061 } | |
3062 | |
3063 return NGX_OK; | |
3064 } | |
3065 | |
3066 | |
3067 static ngx_int_t | |
2669
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3068 ngx_http_upstream_ignore_header_line(ngx_http_request_t *r, ngx_table_elt_t *h, |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3069 ngx_uint_t offset) |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3070 { |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3071 return NGX_OK; |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3072 } |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3073 |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3074 |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3075 static ngx_int_t |
4117
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
3076 ngx_http_upstream_process_content_length(ngx_http_request_t *r, |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
3077 ngx_table_elt_t *h, ngx_uint_t offset) |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
3078 { |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
3079 ngx_http_upstream_t *u; |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
3080 |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
3081 u = r->upstream; |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
3082 |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
3083 u->headers_in.content_length = h; |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
3084 u->headers_in.content_length_n = ngx_atoof(h->value.data, h->value.len); |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
3085 |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
3086 return NGX_OK; |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
3087 } |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
3088 |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
3089 |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
3090 static ngx_int_t |
3669
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
3091 ngx_http_upstream_process_set_cookie(ngx_http_request_t *r, ngx_table_elt_t *h, |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
3092 ngx_uint_t offset) |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
3093 { |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
3094 #if (NGX_HTTP_CACHE) |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
3095 ngx_http_upstream_t *u; |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
3096 |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
3097 u = r->upstream; |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
3098 |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
3099 if (!(u->conf->ignore_headers & NGX_HTTP_UPSTREAM_IGN_SET_COOKIE)) { |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
3100 u->cacheable = 0; |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
3101 } |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
3102 #endif |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
3103 |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
3104 return NGX_OK; |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
3105 } |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
3106 |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
3107 |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
3108 static ngx_int_t |
2669
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3109 ngx_http_upstream_process_cache_control(ngx_http_request_t *r, |
509 | 3110 ngx_table_elt_t *h, ngx_uint_t offset) |
3111 { | |
2786
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
3112 ngx_array_t *pa; |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
3113 ngx_table_elt_t **ph; |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
3114 ngx_http_upstream_t *u; |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
3115 |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
3116 u = r->upstream; |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
3117 pa = &u->headers_in.cache_control; |
509 | 3118 |
3119 if (pa->elts == NULL) { | |
3120 if (ngx_array_init(pa, r->pool, 2, sizeof(ngx_table_elt_t *)) != NGX_OK) | |
3121 { | |
3122 return NGX_ERROR; | |
3123 } | |
3124 } | |
3125 | |
3126 ph = ngx_array_push(pa); | |
3127 if (ph == NULL) { | |
3128 return NGX_ERROR; | |
3129 } | |
3130 | |
3131 *ph = h; | |
3132 | |
2708
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
3133 #if (NGX_HTTP_CACHE) |
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
3134 { |
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
3135 u_char *p, *last; |
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
3136 ngx_int_t n; |
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
3137 |
2786
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
3138 if (u->conf->ignore_headers & NGX_HTTP_UPSTREAM_IGN_CACHE_CONTROL) { |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
3139 return NGX_OK; |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
3140 } |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
3141 |
2669
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3142 if (r->cache == NULL) { |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3143 return NGX_OK; |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3144 } |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3145 |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3146 if (r->cache->valid_sec != 0) { |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3147 return NGX_OK; |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3148 } |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3149 |
3517
a4ee4a075ac5
do not cache response if it has "no-store" or "private"
Igor Sysoev <igor@sysoev.ru>
parents:
3516
diff
changeset
|
3150 p = h->value.data; |
a4ee4a075ac5
do not cache response if it has "no-store" or "private"
Igor Sysoev <igor@sysoev.ru>
parents:
3516
diff
changeset
|
3151 last = p + h->value.len; |
a4ee4a075ac5
do not cache response if it has "no-store" or "private"
Igor Sysoev <igor@sysoev.ru>
parents:
3516
diff
changeset
|
3152 |
a4ee4a075ac5
do not cache response if it has "no-store" or "private"
Igor Sysoev <igor@sysoev.ru>
parents:
3516
diff
changeset
|
3153 if (ngx_strlcasestrn(p, last, (u_char *) "no-cache", 8 - 1) != NULL |
a4ee4a075ac5
do not cache response if it has "no-store" or "private"
Igor Sysoev <igor@sysoev.ru>
parents:
3516
diff
changeset
|
3154 || ngx_strlcasestrn(p, last, (u_char *) "no-store", 8 - 1) != NULL |
a4ee4a075ac5
do not cache response if it has "no-store" or "private"
Igor Sysoev <igor@sysoev.ru>
parents:
3516
diff
changeset
|
3155 || ngx_strlcasestrn(p, last, (u_char *) "private", 7 - 1) != NULL) |
2669
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3156 { |
2786
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
3157 u->cacheable = 0; |
2669
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3158 return NGX_OK; |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3159 } |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3160 |
3517
a4ee4a075ac5
do not cache response if it has "no-store" or "private"
Igor Sysoev <igor@sysoev.ru>
parents:
3516
diff
changeset
|
3161 p = ngx_strlcasestrn(p, last, (u_char *) "max-age=", 8 - 1); |
2669
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3162 |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3163 if (p == NULL) { |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3164 return NGX_OK; |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3165 } |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3166 |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3167 n = 0; |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3168 |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3169 for (p += 8; p < last; p++) { |
3198
48bfb7dc981b
test comma separator in "Cache-Control"
Igor Sysoev <igor@sysoev.ru>
parents:
3195
diff
changeset
|
3170 if (*p == ',' || *p == ';' || *p == ' ') { |
2669
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3171 break; |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3172 } |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3173 |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3174 if (*p >= '0' && *p <= '9') { |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3175 n = n * 10 + *p - '0'; |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3176 continue; |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3177 } |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3178 |
2786
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
3179 u->cacheable = 0; |
2669
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3180 return NGX_OK; |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3181 } |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3182 |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3183 if (n == 0) { |
2786
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
3184 u->cacheable = 0; |
2669
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3185 return NGX_OK; |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3186 } |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3187 |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3188 r->cache->valid_sec = ngx_time() + n; |
2708
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
3189 } |
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
3190 #endif |
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
3191 |
509 | 3192 return NGX_OK; |
3193 } | |
3194 | |
3195 | |
3196 static ngx_int_t | |
2666 | 3197 ngx_http_upstream_process_expires(ngx_http_request_t *r, ngx_table_elt_t *h, |
3198 ngx_uint_t offset) | |
3199 { | |
2786
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
3200 ngx_http_upstream_t *u; |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
3201 |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
3202 u = r->upstream; |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
3203 u->headers_in.expires = h; |
2708
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
3204 |
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
3205 #if (NGX_HTTP_CACHE) |
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
3206 { |
2666 | 3207 time_t expires; |
3208 | |
2786
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
3209 if (u->conf->ignore_headers & NGX_HTTP_UPSTREAM_IGN_EXPIRES) { |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
3210 return NGX_OK; |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
3211 } |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
3212 |
2666 | 3213 if (r->cache == NULL) { |
3214 return NGX_OK; | |
3215 } | |
3216 | |
3217 if (r->cache->valid_sec != 0) { | |
3218 return NGX_OK; | |
3219 } | |
3220 | |
3221 expires = ngx_http_parse_time(h->value.data, h->value.len); | |
3222 | |
3223 if (expires == NGX_ERROR || expires < ngx_time()) { | |
2786
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
3224 u->cacheable = 0; |
2666 | 3225 return NGX_OK; |
3226 } | |
3227 | |
3228 r->cache->valid_sec = expires; | |
2708
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
3229 } |
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
3230 #endif |
2666 | 3231 |
3232 return NGX_OK; | |
3233 } | |
3234 | |
3235 | |
3236 static ngx_int_t | |
2663
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
3237 ngx_http_upstream_process_accel_expires(ngx_http_request_t *r, |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
3238 ngx_table_elt_t *h, ngx_uint_t offset) |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
3239 { |
2786
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
3240 ngx_http_upstream_t *u; |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
3241 |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
3242 u = r->upstream; |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
3243 u->headers_in.x_accel_expires = h; |
2708
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
3244 |
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
3245 #if (NGX_HTTP_CACHE) |
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
3246 { |
2663
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
3247 u_char *p; |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
3248 size_t len; |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
3249 ngx_int_t n; |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
3250 |
2786
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
3251 if (u->conf->ignore_headers & NGX_HTTP_UPSTREAM_IGN_XA_EXPIRES) { |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
3252 return NGX_OK; |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
3253 } |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
3254 |
2663
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
3255 if (r->cache == NULL) { |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
3256 return NGX_OK; |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
3257 } |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
3258 |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
3259 len = h->value.len; |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
3260 p = h->value.data; |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
3261 |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
3262 if (p[0] != '@') { |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
3263 n = ngx_atoi(p, len); |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
3264 |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
3265 switch (n) { |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
3266 case 0: |
2786
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
3267 u->cacheable = 0; |
2663
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
3268 case NGX_ERROR: |
2667 | 3269 return NGX_OK; |
2663
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
3270 |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
3271 default: |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
3272 r->cache->valid_sec = ngx_time() + n; |
2667 | 3273 return NGX_OK; |
2663
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
3274 } |
2667 | 3275 } |
3276 | |
3277 p++; | |
3278 len--; | |
3279 | |
3280 n = ngx_atoi(p, len); | |
3281 | |
3282 if (n != NGX_ERROR) { | |
3283 r->cache->valid_sec = n; | |
2663
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
3284 } |
2708
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
3285 } |
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
3286 #endif |
2663
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
3287 |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
3288 return NGX_OK; |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
3289 } |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
3290 |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
3291 |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
3292 static ngx_int_t |
527 | 3293 ngx_http_upstream_process_limit_rate(ngx_http_request_t *r, ngx_table_elt_t *h, |
3294 ngx_uint_t offset) | |
577 | 3295 { |
527 | 3296 ngx_int_t n; |
3297 | |
3298 r->upstream->headers_in.x_accel_limit_rate = h; | |
3299 | |
3300 n = ngx_atoi(h->value.data, h->value.len); | |
3301 | |
3302 if (n != NGX_ERROR) { | |
3303 r->limit_rate = (size_t) n; | |
3304 } | |
3305 | |
3306 return NGX_OK; | |
3307 } | |
3308 | |
3309 | |
3310 static ngx_int_t | |
649 | 3311 ngx_http_upstream_process_buffering(ngx_http_request_t *r, ngx_table_elt_t *h, |
3312 ngx_uint_t offset) | |
3313 { | |
3314 u_char c0, c1, c2; | |
3315 | |
3316 if (r->upstream->conf->change_buffering) { | |
3317 | |
3318 if (h->value.len == 2) { | |
3319 c0 = ngx_tolower(h->value.data[0]); | |
3320 c1 = ngx_tolower(h->value.data[1]); | |
3321 | |
3322 if (c0 == 'n' && c1 == 'o') { | |
3323 r->upstream->buffering = 0; | |
3324 } | |
3325 | |
3326 } else if (h->value.len == 3) { | |
3327 c0 = ngx_tolower(h->value.data[0]); | |
3328 c1 = ngx_tolower(h->value.data[1]); | |
3329 c2 = ngx_tolower(h->value.data[2]); | |
3330 | |
3331 if (c0 == 'y' && c1 == 'e' && c2 == 's') { | |
3332 r->upstream->buffering = 1; | |
3333 } | |
3334 } | |
3335 } | |
3336 | |
3337 return NGX_OK; | |
3338 } | |
3339 | |
3340 | |
3341 static ngx_int_t | |
657 | 3342 ngx_http_upstream_process_charset(ngx_http_request_t *r, ngx_table_elt_t *h, |
3343 ngx_uint_t offset) | |
3344 { | |
3345 r->headers_out.override_charset = &h->value; | |
3346 | |
3347 return NGX_OK; | |
3348 } | |
3349 | |
3350 | |
3351 static ngx_int_t | |
509 | 3352 ngx_http_upstream_copy_header_line(ngx_http_request_t *r, ngx_table_elt_t *h, |
3353 ngx_uint_t offset) | |
3354 { | |
573 | 3355 ngx_table_elt_t *ho, **ph; |
509 | 3356 |
3357 ho = ngx_list_push(&r->headers_out.headers); | |
3358 if (ho == NULL) { | |
3359 return NGX_ERROR; | |
3360 } | |
3361 | |
3362 *ho = *h; | |
3363 | |
573 | 3364 if (offset) { |
3365 ph = (ngx_table_elt_t **) ((char *) &r->headers_out + offset); | |
3366 *ph = ho; | |
3367 } | |
3368 | |
509 | 3369 return NGX_OK; |
3370 } | |
3371 | |
3372 | |
3373 static ngx_int_t | |
3374 ngx_http_upstream_copy_multi_header_lines(ngx_http_request_t *r, | |
3375 ngx_table_elt_t *h, ngx_uint_t offset) | |
3376 { | |
3377 ngx_array_t *pa; | |
3378 ngx_table_elt_t *ho, **ph; | |
3379 | |
3380 pa = (ngx_array_t *) ((char *) &r->headers_out + offset); | |
3381 | |
3382 if (pa->elts == NULL) { | |
3383 if (ngx_array_init(pa, r->pool, 2, sizeof(ngx_table_elt_t *)) != NGX_OK) | |
3384 { | |
3385 return NGX_ERROR; | |
3386 } | |
3387 } | |
3388 | |
3389 ph = ngx_array_push(pa); | |
3390 if (ph == NULL) { | |
3391 return NGX_ERROR; | |
3392 } | |
3393 | |
3394 ho = ngx_list_push(&r->headers_out.headers); | |
3395 if (ho == NULL) { | |
3396 return NGX_ERROR; | |
3397 } | |
3398 | |
3399 *ho = *h; | |
3400 *ph = ho; | |
3401 | |
3402 return NGX_OK; | |
3403 } | |
3404 | |
3405 | |
3406 static ngx_int_t | |
3407 ngx_http_upstream_copy_content_type(ngx_http_request_t *r, ngx_table_elt_t *h, | |
3408 ngx_uint_t offset) | |
3409 { | |
657 | 3410 u_char *p, *last; |
3411 | |
3412 r->headers_out.content_type_len = h->value.len; | |
509 | 3413 r->headers_out.content_type = h->value; |
2882
896db5a09bd2
reset content_type hash value, this fixes a bug when XSLT responses
Igor Sysoev <igor@sysoev.ru>
parents:
2875
diff
changeset
|
3414 r->headers_out.content_type_lowcase = NULL; |
509 | 3415 |
657 | 3416 for (p = h->value.data; *p; p++) { |
3417 | |
3418 if (*p != ';') { | |
3419 continue; | |
3420 } | |
3421 | |
3422 last = p; | |
3423 | |
3424 while (*++p == ' ') { /* void */ } | |
3425 | |
1968 | 3426 if (*p == '\0') { |
3427 return NGX_OK; | |
3428 } | |
3429 | |
1107
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1098
diff
changeset
|
3430 if (ngx_strncasecmp(p, (u_char *) "charset=", 8) != 0) { |
657 | 3431 continue; |
3432 } | |
3433 | |
3434 p += 8; | |
3435 | |
3436 r->headers_out.content_type_len = last - h->value.data; | |
3437 | |
2244 | 3438 if (*p == '"') { |
3439 p++; | |
3440 } | |
3441 | |
3442 last = h->value.data + h->value.len; | |
3443 | |
3444 if (*(last - 1) == '"') { | |
3445 last--; | |
3446 } | |
3447 | |
3448 r->headers_out.charset.len = last - p; | |
657 | 3449 r->headers_out.charset.data = p; |
1143
c6c42497106c
fix segfault if upstream sends trailing ";" in "charset="
Igor Sysoev <igor@sysoev.ru>
parents:
1109
diff
changeset
|
3450 |
c6c42497106c
fix segfault if upstream sends trailing ";" in "charset="
Igor Sysoev <igor@sysoev.ru>
parents:
1109
diff
changeset
|
3451 return NGX_OK; |
657 | 3452 } |
3453 | |
509 | 3454 return NGX_OK; |
3455 } | |
3456 | |
3457 | |
3458 static ngx_int_t | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3459 ngx_http_upstream_copy_last_modified(ngx_http_request_t *r, ngx_table_elt_t *h, |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3460 ngx_uint_t offset) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3461 { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3462 ngx_table_elt_t *ho; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3463 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3464 ho = ngx_list_push(&r->headers_out.headers); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3465 if (ho == NULL) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3466 return NGX_ERROR; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3467 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3468 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3469 *ho = *h; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3470 |
3004
4121acaf7a04
fix handling "Last-Modified" and "Accept-Ranges" for upstream responses
Igor Sysoev <igor@sysoev.ru>
parents:
3003
diff
changeset
|
3471 r->headers_out.last_modified = ho; |
4121acaf7a04
fix handling "Last-Modified" and "Accept-Ranges" for upstream responses
Igor Sysoev <igor@sysoev.ru>
parents:
3003
diff
changeset
|
3472 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3473 #if (NGX_HTTP_CACHE) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3474 |
2952 | 3475 if (r->upstream->cacheable) { |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3476 r->headers_out.last_modified_time = ngx_http_parse_time(h->value.data, |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3477 h->value.len); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3478 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3479 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3480 #endif |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3481 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3482 return NGX_OK; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3483 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3484 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3485 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3486 static ngx_int_t |
509 | 3487 ngx_http_upstream_rewrite_location(ngx_http_request_t *r, ngx_table_elt_t *h, |
3488 ngx_uint_t offset) | |
3489 { | |
3490 ngx_int_t rc; | |
3491 ngx_table_elt_t *ho; | |
3492 | |
3493 ho = ngx_list_push(&r->headers_out.headers); | |
3494 if (ho == NULL) { | |
3495 return NGX_ERROR; | |
3496 } | |
3497 | |
3498 *ho = *h; | |
3499 | |
3500 if (r->upstream->rewrite_redirect) { | |
3501 rc = r->upstream->rewrite_redirect(r, ho, 0); | |
3502 | |
529 | 3503 if (rc == NGX_DECLINED) { |
3504 return NGX_OK; | |
3505 } | |
3506 | |
509 | 3507 if (rc == NGX_OK) { |
3508 r->headers_out.location = ho; | |
3509 | |
3510 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
3511 "rewritten location: \"%V\"", &ho->value); | |
3512 } | |
3513 | |
3514 return rc; | |
3515 } | |
3516 | |
1653
ea681a6a0c61
set r->headers_out.location for non-local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
3517 if (ho->value.data[0] != '/') { |
ea681a6a0c61
set r->headers_out.location for non-local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
3518 r->headers_out.location = ho; |
ea681a6a0c61
set r->headers_out.location for non-local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
3519 } |
ea681a6a0c61
set r->headers_out.location for non-local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
3520 |
509 | 3521 /* |
3522 * we do not set r->headers_out.location here to avoid the handling | |
3523 * the local redirects without a host name by ngx_http_header_filter() | |
3524 */ | |
3525 | |
3526 return NGX_OK; | |
3527 } | |
3528 | |
3529 | |
3530 static ngx_int_t | |
3531 ngx_http_upstream_rewrite_refresh(ngx_http_request_t *r, ngx_table_elt_t *h, | |
3532 ngx_uint_t offset) | |
3533 { | |
3534 u_char *p; | |
3535 ngx_int_t rc; | |
3536 ngx_table_elt_t *ho; | |
3537 | |
3538 ho = ngx_list_push(&r->headers_out.headers); | |
3539 if (ho == NULL) { | |
3540 return NGX_ERROR; | |
3541 } | |
3542 | |
3543 *ho = *h; | |
3544 | |
3545 if (r->upstream->rewrite_redirect) { | |
3546 | |
1549 | 3547 p = ngx_strcasestrn(ho->value.data, "url=", 4 - 1); |
509 | 3548 |
3549 if (p) { | |
3550 rc = r->upstream->rewrite_redirect(r, ho, p + 4 - ho->value.data); | |
3551 | |
3552 } else { | |
3553 return NGX_OK; | |
3554 } | |
3555 | |
529 | 3556 if (rc == NGX_DECLINED) { |
3557 return NGX_OK; | |
3558 } | |
3559 | |
509 | 3560 if (rc == NGX_OK) { |
1654 | 3561 r->headers_out.refresh = ho; |
3562 | |
509 | 3563 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
3564 "rewritten refresh: \"%V\"", &ho->value); | |
3565 } | |
3566 | |
3567 return rc; | |
3568 } | |
3569 | |
1654 | 3570 r->headers_out.refresh = ho; |
3571 | |
509 | 3572 return NGX_OK; |
3573 } | |
3574 | |
3575 | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3576 static ngx_int_t |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3577 ngx_http_upstream_copy_allow_ranges(ngx_http_request_t *r, |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3578 ngx_table_elt_t *h, ngx_uint_t offset) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3579 { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3580 ngx_table_elt_t *ho; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3581 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3582 #if (NGX_HTTP_CACHE) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3583 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3584 if (r->cached) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3585 r->allow_ranges = 1; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3586 return NGX_OK; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3587 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3588 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3589 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3590 #endif |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3591 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3592 ho = ngx_list_push(&r->headers_out.headers); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3593 if (ho == NULL) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3594 return NGX_ERROR; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3595 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3596 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3597 *ho = *h; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3598 |
3004
4121acaf7a04
fix handling "Last-Modified" and "Accept-Ranges" for upstream responses
Igor Sysoev <igor@sysoev.ru>
parents:
3003
diff
changeset
|
3599 r->headers_out.accept_ranges = ho; |
4121acaf7a04
fix handling "Last-Modified" and "Accept-Ranges" for upstream responses
Igor Sysoev <igor@sysoev.ru>
parents:
3003
diff
changeset
|
3600 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3601 return NGX_OK; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3602 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3603 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3604 |
509 | 3605 #if (NGX_HTTP_GZIP) |
3606 | |
3607 static ngx_int_t | |
3608 ngx_http_upstream_copy_content_encoding(ngx_http_request_t *r, | |
3609 ngx_table_elt_t *h, ngx_uint_t offset) | |
3610 { | |
3611 ngx_table_elt_t *ho; | |
3612 | |
3613 ho = ngx_list_push(&r->headers_out.headers); | |
3614 if (ho == NULL) { | |
3615 return NGX_ERROR; | |
3616 } | |
3617 | |
3618 *ho = *h; | |
3619 | |
3620 r->headers_out.content_encoding = ho; | |
3621 | |
3622 return NGX_OK; | |
3623 } | |
3624 | |
3625 #endif | |
3626 | |
3627 | |
487 | 3628 static ngx_int_t |
573 | 3629 ngx_http_upstream_add_variables(ngx_conf_t *cf) |
479 | 3630 { |
880 | 3631 ngx_http_variable_t *var, *v; |
479 | 3632 |
573 | 3633 for (v = ngx_http_upstream_vars; v->name.len; v++) { |
3634 var = ngx_http_add_variable(cf, &v->name, v->flags); | |
3635 if (var == NULL) { | |
3636 return NGX_ERROR; | |
3637 } | |
3638 | |
637 | 3639 var->get_handler = v->get_handler; |
573 | 3640 var->data = v->data; |
3641 } | |
3642 | |
479 | 3643 return NGX_OK; |
3644 } | |
509 | 3645 |
3646 | |
573 | 3647 static ngx_int_t |
1181 | 3648 ngx_http_upstream_addr_variable(ngx_http_request_t *r, |
3649 ngx_http_variable_value_t *v, uintptr_t data) | |
3650 { | |
3651 u_char *p; | |
3652 size_t len; | |
3653 ngx_uint_t i; | |
3654 ngx_http_upstream_state_t *state; | |
3655 | |
3656 v->valid = 1; | |
1565 | 3657 v->no_cacheable = 0; |
1181 | 3658 v->not_found = 0; |
3659 | |
3660 if (r->upstream_states == NULL || r->upstream_states->nelts == 0) { | |
3661 v->not_found = 1; | |
3662 return NGX_OK; | |
3663 } | |
3664 | |
3665 len = 0; | |
3666 state = r->upstream_states->elts; | |
3667 | |
3668 for (i = 0; i < r->upstream_states->nelts; i++) { | |
3669 if (state[i].peer) { | |
3670 len += state[i].peer->len + 2; | |
3671 | |
3672 } else { | |
3673 len += 3; | |
3674 } | |
3675 } | |
3676 | |
2049 | 3677 p = ngx_pnalloc(r->pool, len); |
1181 | 3678 if (p == NULL) { |
3679 return NGX_ERROR; | |
3680 } | |
3681 | |
3682 v->data = p; | |
3683 | |
3684 i = 0; | |
3685 | |
3686 for ( ;; ) { | |
3687 if (state[i].peer) { | |
3688 p = ngx_cpymem(p, state[i].peer->data, state[i].peer->len); | |
3689 } | |
3690 | |
3691 if (++i == r->upstream_states->nelts) { | |
3692 break; | |
3693 } | |
3694 | |
3695 if (state[i].peer) { | |
3696 *p++ = ','; | |
3697 *p++ = ' '; | |
3698 | |
3699 } else { | |
3700 *p++ = ' '; | |
3701 *p++ = ':'; | |
3702 *p++ = ' '; | |
3703 | |
3704 if (++i == r->upstream_states->nelts) { | |
3705 break; | |
3706 } | |
3707 | |
3708 continue; | |
3709 } | |
3710 } | |
3711 | |
3712 v->len = p - v->data; | |
3713 | |
3714 return NGX_OK; | |
3715 } | |
3716 | |
3717 | |
3718 static ngx_int_t | |
573 | 3719 ngx_http_upstream_status_variable(ngx_http_request_t *r, |
3720 ngx_http_variable_value_t *v, uintptr_t data) | |
3721 { | |
3722 u_char *p; | |
3723 size_t len; | |
3724 ngx_uint_t i; | |
3725 ngx_http_upstream_state_t *state; | |
3726 | |
3727 v->valid = 1; | |
1565 | 3728 v->no_cacheable = 0; |
573 | 3729 v->not_found = 0; |
3730 | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
3731 if (r->upstream_states == NULL || r->upstream_states->nelts == 0) { |
573 | 3732 v->not_found = 1; |
3733 return NGX_OK; | |
3734 } | |
3735 | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
3736 len = r->upstream_states->nelts * (3 + 2); |
573 | 3737 |
2049 | 3738 p = ngx_pnalloc(r->pool, len); |
573 | 3739 if (p == NULL) { |
3740 return NGX_ERROR; | |
3741 } | |
3742 | |
3743 v->data = p; | |
3744 | |
3745 i = 0; | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
3746 state = r->upstream_states->elts; |
573 | 3747 |
3748 for ( ;; ) { | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
3749 if (state[i].status) { |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
3750 p = ngx_sprintf(p, "%ui", state[i].status); |
573 | 3751 |
3752 } else { | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
3753 *p++ = '-'; |
573 | 3754 } |
3755 | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
3756 if (++i == r->upstream_states->nelts) { |
573 | 3757 break; |
3758 } | |
3759 | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
3760 if (state[i].peer) { |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
3761 *p++ = ','; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
3762 *p++ = ' '; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
3763 |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
3764 } else { |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
3765 *p++ = ' '; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
3766 *p++ = ':'; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
3767 *p++ = ' '; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
3768 |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
3769 if (++i == r->upstream_states->nelts) { |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
3770 break; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
3771 } |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
3772 |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
3773 continue; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
3774 } |
573 | 3775 } |
3776 | |
3777 v->len = p - v->data; | |
3778 | |
3779 return NGX_OK; | |
3780 } | |
3781 | |
3782 | |
3783 static ngx_int_t | |
3784 ngx_http_upstream_response_time_variable(ngx_http_request_t *r, | |
3785 ngx_http_variable_value_t *v, uintptr_t data) | |
3786 { | |
3787 u_char *p; | |
3788 size_t len; | |
3789 ngx_uint_t i; | |
889
a9a7e4b1a72b
the previous fix does not actually fix overflow
Igor Sysoev <igor@sysoev.ru>
parents:
888
diff
changeset
|
3790 ngx_msec_int_t ms; |
573 | 3791 ngx_http_upstream_state_t *state; |
3792 | |
3793 v->valid = 1; | |
1565 | 3794 v->no_cacheable = 0; |
573 | 3795 v->not_found = 0; |
3796 | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
3797 if (r->upstream_states == NULL || r->upstream_states->nelts == 0) { |
573 | 3798 v->not_found = 1; |
3799 return NGX_OK; | |
3800 } | |
3801 | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
3802 len = r->upstream_states->nelts * (NGX_TIME_T_LEN + 4 + 2); |
573 | 3803 |
2049 | 3804 p = ngx_pnalloc(r->pool, len); |
573 | 3805 if (p == NULL) { |
3806 return NGX_ERROR; | |
3807 } | |
3808 | |
3809 v->data = p; | |
3810 | |
3811 i = 0; | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
3812 state = r->upstream_states->elts; |
573 | 3813 |
3814 for ( ;; ) { | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
3815 if (state[i].status) { |
1640 | 3816 ms = (ngx_msec_int_t) |
3817 (state[i].response_sec * 1000 + state[i].response_msec); | |
3515 | 3818 ms = ngx_max(ms, 0); |
889
a9a7e4b1a72b
the previous fix does not actually fix overflow
Igor Sysoev <igor@sysoev.ru>
parents:
888
diff
changeset
|
3819 p = ngx_sprintf(p, "%d.%03d", ms / 1000, ms % 1000); |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
3820 |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
3821 } else { |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
3822 *p++ = '-'; |
573 | 3823 } |
3824 | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
3825 if (++i == r->upstream_states->nelts) { |
573 | 3826 break; |
3827 } | |
3828 | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
3829 if (state[i].peer) { |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
3830 *p++ = ','; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
3831 *p++ = ' '; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
3832 |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
3833 } else { |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
3834 *p++ = ' '; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
3835 *p++ = ':'; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
3836 *p++ = ' '; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
3837 |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
3838 if (++i == r->upstream_states->nelts) { |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
3839 break; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
3840 } |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
3841 |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
3842 continue; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
3843 } |
573 | 3844 } |
3845 | |
3846 v->len = p - v->data; | |
3847 | |
3848 return NGX_OK; | |
3849 } | |
3850 | |
3851 | |
2402 | 3852 static ngx_int_t |
3853 ngx_http_upstream_response_length_variable(ngx_http_request_t *r, | |
3854 ngx_http_variable_value_t *v, uintptr_t data) | |
3855 { | |
3856 u_char *p; | |
3857 size_t len; | |
3858 ngx_uint_t i; | |
3859 ngx_http_upstream_state_t *state; | |
3860 | |
3861 v->valid = 1; | |
3862 v->no_cacheable = 0; | |
3863 v->not_found = 0; | |
3864 | |
3865 if (r->upstream_states == NULL || r->upstream_states->nelts == 0) { | |
3866 v->not_found = 1; | |
3867 return NGX_OK; | |
3868 } | |
3869 | |
3870 len = r->upstream_states->nelts * (NGX_OFF_T_LEN + 2); | |
3871 | |
3872 p = ngx_pnalloc(r->pool, len); | |
3873 if (p == NULL) { | |
3874 return NGX_ERROR; | |
3875 } | |
3876 | |
3877 v->data = p; | |
3878 | |
3879 i = 0; | |
3880 state = r->upstream_states->elts; | |
3881 | |
3882 for ( ;; ) { | |
3883 p = ngx_sprintf(p, "%O", state[i].response_length); | |
3884 | |
3885 if (++i == r->upstream_states->nelts) { | |
3886 break; | |
3887 } | |
3888 | |
3889 if (state[i].peer) { | |
3890 *p++ = ','; | |
3891 *p++ = ' '; | |
3892 | |
3893 } else { | |
3894 *p++ = ' '; | |
3895 *p++ = ':'; | |
3896 *p++ = ' '; | |
3897 | |
3898 if (++i == r->upstream_states->nelts) { | |
3899 break; | |
3900 } | |
3901 | |
3902 continue; | |
3903 } | |
3904 } | |
3905 | |
3906 v->len = p - v->data; | |
3907 | |
3908 return NGX_OK; | |
3909 } | |
3910 | |
3911 | |
1162 | 3912 ngx_int_t |
3913 ngx_http_upstream_header_variable(ngx_http_request_t *r, | |
3914 ngx_http_variable_value_t *v, uintptr_t data) | |
3915 { | |
3916 if (r->upstream == NULL) { | |
3917 v->not_found = 1; | |
3918 return NGX_OK; | |
3919 } | |
3920 | |
3921 return ngx_http_variable_unknown_header(v, (ngx_str_t *) data, | |
3922 &r->upstream->headers_in.headers.part, | |
3923 sizeof("upstream_http_") - 1); | |
3924 } | |
3925 | |
3926 | |
2952 | 3927 #if (NGX_HTTP_CACHE) |
3928 | |
3929 ngx_int_t | |
3930 ngx_http_upstream_cache_status(ngx_http_request_t *r, | |
3931 ngx_http_variable_value_t *v, uintptr_t data) | |
3932 { | |
3933 ngx_uint_t n; | |
3934 | |
3935 if (r->upstream == NULL || r->upstream->cache_status == 0) { | |
3936 v->not_found = 1; | |
3937 return NGX_OK; | |
3938 } | |
3939 | |
3940 n = r->upstream->cache_status - 1; | |
3941 | |
3942 v->valid = 1; | |
3943 v->no_cacheable = 0; | |
3944 v->not_found = 0; | |
3945 v->len = ngx_http_cache_status[n].len; | |
3946 v->data = ngx_http_cache_status[n].data; | |
3947 | |
3948 return NGX_OK; | |
3949 } | |
3950 | |
3951 #endif | |
3952 | |
3953 | |
651 | 3954 static char * |
3955 ngx_http_upstream(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy) | |
3956 { | |
884 | 3957 char *rv; |
3958 void *mconf; | |
3959 ngx_str_t *value; | |
3960 ngx_url_t u; | |
3961 ngx_uint_t m; | |
3962 ngx_conf_t pcf; | |
3963 ngx_http_module_t *module; | |
3964 ngx_http_conf_ctx_t *ctx, *http_ctx; | |
3965 ngx_http_upstream_srv_conf_t *uscf; | |
3966 | |
3967 ngx_memzero(&u, sizeof(ngx_url_t)); | |
3968 | |
3969 value = cf->args->elts; | |
3970 u.host = value[1]; | |
3971 u.no_resolve = 1; | |
3972 | |
3973 uscf = ngx_http_upstream_add(cf, &u, NGX_HTTP_UPSTREAM_CREATE | |
3974 |NGX_HTTP_UPSTREAM_WEIGHT | |
3975 |NGX_HTTP_UPSTREAM_MAX_FAILS | |
3976 |NGX_HTTP_UPSTREAM_FAIL_TIMEOUT | |
3977 |NGX_HTTP_UPSTREAM_DOWN | |
3978 |NGX_HTTP_UPSTREAM_BACKUP); | |
3979 if (uscf == NULL) { | |
3980 return NGX_CONF_ERROR; | |
3981 } | |
3982 | |
651 | 3983 |
3984 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)); | |
3985 if (ctx == NULL) { | |
3986 return NGX_CONF_ERROR; | |
3987 } | |
3988 | |
884 | 3989 http_ctx = cf->ctx; |
3990 ctx->main_conf = http_ctx->main_conf; | |
651 | 3991 |
3992 /* the upstream{}'s srv_conf */ | |
3993 | |
3994 ctx->srv_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module); | |
3995 if (ctx->srv_conf == NULL) { | |
3996 return NGX_CONF_ERROR; | |
3997 } | |
3998 | |
3999 ctx->srv_conf[ngx_http_upstream_module.ctx_index] = uscf; | |
4000 | |
884 | 4001 uscf->srv_conf = ctx->srv_conf; |
4002 | |
651 | 4003 |
4004 /* the upstream{}'s loc_conf */ | |
4005 | |
4006 ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module); | |
4007 if (ctx->loc_conf == NULL) { | |
4008 return NGX_CONF_ERROR; | |
4009 } | |
4010 | |
4011 for (m = 0; ngx_modules[m]; m++) { | |
4012 if (ngx_modules[m]->type != NGX_HTTP_MODULE) { | |
4013 continue; | |
4014 } | |
4015 | |
4016 module = ngx_modules[m]->ctx; | |
4017 | |
884 | 4018 if (module->create_srv_conf) { |
4019 mconf = module->create_srv_conf(cf); | |
4020 if (mconf == NULL) { | |
4021 return NGX_CONF_ERROR; | |
4022 } | |
4023 | |
4024 ctx->srv_conf[ngx_modules[m]->ctx_index] = mconf; | |
4025 } | |
4026 | |
651 | 4027 if (module->create_loc_conf) { |
4028 mconf = module->create_loc_conf(cf); | |
4029 if (mconf == NULL) { | |
4030 return NGX_CONF_ERROR; | |
4031 } | |
4032 | |
4033 ctx->loc_conf[ngx_modules[m]->ctx_index] = mconf; | |
4034 } | |
4035 } | |
4036 | |
4037 | |
4038 /* parse inside upstream{} */ | |
4039 | |
4040 pcf = *cf; | |
4041 cf->ctx = ctx; | |
4042 cf->cmd_type = NGX_HTTP_UPS_CONF; | |
4043 | |
4044 rv = ngx_conf_parse(cf, NULL); | |
4045 | |
4046 *cf = pcf; | |
4047 | |
4048 if (rv != NGX_CONF_OK) { | |
4049 return rv; | |
4050 } | |
4051 | |
4052 if (uscf->servers == NULL) { | |
4053 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
4054 "no servers are inside upstream"); | |
4055 return NGX_CONF_ERROR; | |
4056 } | |
4057 | |
4058 return rv; | |
4059 } | |
4060 | |
4061 | |
4062 static char * | |
4063 ngx_http_upstream_server(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
4064 { | |
4065 ngx_http_upstream_srv_conf_t *uscf = conf; | |
4066 | |
884 | 4067 time_t fail_timeout; |
4068 ngx_str_t *value, s; | |
4069 ngx_url_t u; | |
4070 ngx_int_t weight, max_fails; | |
4071 ngx_uint_t i; | |
4072 ngx_http_upstream_server_t *us; | |
651 | 4073 |
4074 if (uscf->servers == NULL) { | |
884 | 4075 uscf->servers = ngx_array_create(cf->pool, 4, |
4076 sizeof(ngx_http_upstream_server_t)); | |
651 | 4077 if (uscf->servers == NULL) { |
4078 return NGX_CONF_ERROR; | |
4079 } | |
4080 } | |
4081 | |
884 | 4082 us = ngx_array_push(uscf->servers); |
4083 if (us == NULL) { | |
651 | 4084 return NGX_CONF_ERROR; |
4085 } | |
4086 | |
884 | 4087 ngx_memzero(us, sizeof(ngx_http_upstream_server_t)); |
4088 | |
651 | 4089 value = cf->args->elts; |
4090 | |
4091 ngx_memzero(&u, sizeof(ngx_url_t)); | |
4092 | |
4093 u.url = value[1]; | |
906 | 4094 u.default_port = 80; |
651 | 4095 |
1559
fe11e2a3946d
use pool instead of ngx_conf_t
Igor Sysoev <igor@sysoev.ru>
parents:
1558
diff
changeset
|
4096 if (ngx_parse_url(cf->pool, &u) != NGX_OK) { |
651 | 4097 if (u.err) { |
4098 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
4099 "%s in upstream \"%V\"", u.err, &u.url); | |
4100 } | |
4101 | |
4102 return NGX_CONF_ERROR; | |
4103 } | |
4104 | |
663 | 4105 weight = 1; |
884 | 4106 max_fails = 1; |
4107 fail_timeout = 10; | |
4108 | |
4109 for (i = 2; i < cf->args->nelts; i++) { | |
4110 | |
4111 if (ngx_strncmp(value[i].data, "weight=", 7) == 0) { | |
4112 | |
4113 if (!(uscf->flags & NGX_HTTP_UPSTREAM_WEIGHT)) { | |
4114 goto invalid; | |
4115 } | |
4116 | |
4117 weight = ngx_atoi(&value[i].data[7], value[i].len - 7); | |
663 | 4118 |
4119 if (weight == NGX_ERROR || weight == 0) { | |
4120 goto invalid; | |
4121 } | |
4122 | |
884 | 4123 continue; |
4124 } | |
4125 | |
4126 if (ngx_strncmp(value[i].data, "max_fails=", 10) == 0) { | |
4127 | |
4128 if (!(uscf->flags & NGX_HTTP_UPSTREAM_MAX_FAILS)) { | |
4129 goto invalid; | |
4130 } | |
4131 | |
4132 max_fails = ngx_atoi(&value[i].data[10], value[i].len - 10); | |
4133 | |
4134 if (max_fails == NGX_ERROR) { | |
4135 goto invalid; | |
4136 } | |
4137 | |
4138 continue; | |
663 | 4139 } |
884 | 4140 |
4141 if (ngx_strncmp(value[i].data, "fail_timeout=", 13) == 0) { | |
4142 | |
4143 if (!(uscf->flags & NGX_HTTP_UPSTREAM_FAIL_TIMEOUT)) { | |
4144 goto invalid; | |
4145 } | |
4146 | |
4147 s.len = value[i].len - 13; | |
4148 s.data = &value[i].data[13]; | |
4149 | |
4150 fail_timeout = ngx_parse_time(&s, 1); | |
4151 | |
1973 | 4152 if (fail_timeout == NGX_ERROR) { |
884 | 4153 goto invalid; |
4154 } | |
4155 | |
4156 continue; | |
4157 } | |
4158 | |
1378 | 4159 if (ngx_strncmp(value[i].data, "backup", 6) == 0) { |
4160 | |
4161 if (!(uscf->flags & NGX_HTTP_UPSTREAM_BACKUP)) { | |
4162 goto invalid; | |
4163 } | |
4164 | |
4165 us->backup = 1; | |
4166 | |
4167 continue; | |
4168 } | |
4169 | |
884 | 4170 if (ngx_strncmp(value[i].data, "down", 4) == 0) { |
4171 | |
4172 if (!(uscf->flags & NGX_HTTP_UPSTREAM_DOWN)) { | |
4173 goto invalid; | |
4174 } | |
4175 | |
4176 us->down = 1; | |
4177 | |
4178 continue; | |
4179 } | |
4180 | |
4181 goto invalid; | |
663 | 4182 } |
4183 | |
884 | 4184 us->addrs = u.addrs; |
4185 us->naddrs = u.naddrs; | |
4186 us->weight = weight; | |
4187 us->max_fails = max_fails; | |
4188 us->fail_timeout = fail_timeout; | |
651 | 4189 |
4190 return NGX_CONF_OK; | |
663 | 4191 |
4192 invalid: | |
4193 | |
884 | 4194 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
4195 "invalid parameter \"%V\"", &value[i]); | |
663 | 4196 |
4197 return NGX_CONF_ERROR; | |
651 | 4198 } |
4199 | |
4200 | |
4201 ngx_http_upstream_srv_conf_t * | |
884 | 4202 ngx_http_upstream_add(ngx_conf_t *cf, ngx_url_t *u, ngx_uint_t flags) |
651 | 4203 { |
4204 ngx_uint_t i; | |
884 | 4205 ngx_http_upstream_server_t *us; |
651 | 4206 ngx_http_upstream_srv_conf_t *uscf, **uscfp; |
4207 ngx_http_upstream_main_conf_t *umcf; | |
4208 | |
884 | 4209 if (!(flags & NGX_HTTP_UPSTREAM_CREATE)) { |
4210 | |
1559
fe11e2a3946d
use pool instead of ngx_conf_t
Igor Sysoev <igor@sysoev.ru>
parents:
1558
diff
changeset
|
4211 if (ngx_parse_url(cf->pool, u) != NGX_OK) { |
651 | 4212 if (u->err) { |
4213 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
4214 "%s in upstream \"%V\"", u->err, &u->url); | |
4215 } | |
4216 | |
4217 return NULL; | |
4218 } | |
4219 } | |
4220 | |
4221 umcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_upstream_module); | |
4222 | |
4223 uscfp = umcf->upstreams.elts; | |
4224 | |
4225 for (i = 0; i < umcf->upstreams.nelts; i++) { | |
906 | 4226 |
4227 if (uscfp[i]->host.len != u->host.len | |
884 | 4228 || ngx_strncasecmp(uscfp[i]->host.data, u->host.data, u->host.len) |
4229 != 0) | |
4230 { | |
651 | 4231 continue; |
4232 } | |
4233 | |
884 | 4234 if ((flags & NGX_HTTP_UPSTREAM_CREATE) |
4235 && (uscfp[i]->flags & NGX_HTTP_UPSTREAM_CREATE)) | |
651 | 4236 { |
884 | 4237 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
4238 "duplicate upstream \"%V\"", &u->host); | |
4239 return NULL; | |
651 | 4240 } |
884 | 4241 |
906 | 4242 if ((uscfp[i]->flags & NGX_HTTP_UPSTREAM_CREATE) && u->port) { |
884 | 4243 ngx_conf_log_error(NGX_LOG_WARN, cf, 0, |
906 | 4244 "upstream \"%V\" may not have port %d", |
4245 &u->host, u->port); | |
4246 return NULL; | |
4247 } | |
4248 | |
4249 if ((flags & NGX_HTTP_UPSTREAM_CREATE) && uscfp[i]->port) { | |
4250 ngx_log_error(NGX_LOG_WARN, cf->log, 0, | |
4251 "upstream \"%V\" may not have port %d in %s:%ui", | |
4252 &u->host, uscfp[i]->port, | |
1489
56f1ea5baabb
u_char* is enough to keep file name
Igor Sysoev <igor@sysoev.ru>
parents:
1469
diff
changeset
|
4253 uscfp[i]->file_name, uscfp[i]->line); |
906 | 4254 return NULL; |
4255 } | |
4256 | |
4257 if (uscfp[i]->port != u->port) { | |
4258 continue; | |
884 | 4259 } |
4260 | |
1340 | 4261 if (uscfp[i]->default_port && u->default_port |
4262 && uscfp[i]->default_port != u->default_port) | |
4263 { | |
4264 continue; | |
4265 } | |
4266 | |
884 | 4267 return uscfp[i]; |
651 | 4268 } |
4269 | |
4270 uscf = ngx_pcalloc(cf->pool, sizeof(ngx_http_upstream_srv_conf_t)); | |
4271 if (uscf == NULL) { | |
4272 return NULL; | |
4273 } | |
4274 | |
884 | 4275 uscf->flags = flags; |
651 | 4276 uscf->host = u->host; |
1489
56f1ea5baabb
u_char* is enough to keep file name
Igor Sysoev <igor@sysoev.ru>
parents:
1469
diff
changeset
|
4277 uscf->file_name = cf->conf_file->file.name.data; |
651 | 4278 uscf->line = cf->conf_file->line; |
906 | 4279 uscf->port = u->port; |
4280 uscf->default_port = u->default_port; | |
884 | 4281 |
4282 if (u->naddrs == 1) { | |
4283 uscf->servers = ngx_array_create(cf->pool, 1, | |
4284 sizeof(ngx_http_upstream_server_t)); | |
4285 if (uscf->servers == NULL) { | |
4286 return NGX_CONF_ERROR; | |
4287 } | |
4288 | |
4289 us = ngx_array_push(uscf->servers); | |
4290 if (us == NULL) { | |
4291 return NGX_CONF_ERROR; | |
4292 } | |
4293 | |
4294 ngx_memzero(us, sizeof(ngx_http_upstream_server_t)); | |
4295 | |
4296 us->addrs = u->addrs; | |
4297 us->naddrs = u->naddrs; | |
4298 } | |
651 | 4299 |
4300 uscfp = ngx_array_push(&umcf->upstreams); | |
4301 if (uscfp == NULL) { | |
4302 return NULL; | |
4303 } | |
4304 | |
4305 *uscfp = uscf; | |
4306 | |
4307 return uscf; | |
4308 } | |
4309 | |
4310 | |
3271
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3198
diff
changeset
|
4311 char * |
3399 | 4312 ngx_http_upstream_bind_set_slot(ngx_conf_t *cf, ngx_command_t *cmd, |
3271
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3198
diff
changeset
|
4313 void *conf) |
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3198
diff
changeset
|
4314 { |
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3198
diff
changeset
|
4315 char *p = conf; |
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3198
diff
changeset
|
4316 |
3272
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3271
diff
changeset
|
4317 ngx_int_t rc; |
3271
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3198
diff
changeset
|
4318 ngx_str_t *value; |
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3198
diff
changeset
|
4319 ngx_addr_t **paddr; |
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3198
diff
changeset
|
4320 |
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3198
diff
changeset
|
4321 paddr = (ngx_addr_t **) (p + cmd->offset); |
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3198
diff
changeset
|
4322 |
3272
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3271
diff
changeset
|
4323 *paddr = ngx_palloc(cf->pool, sizeof(ngx_addr_t)); |
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3271
diff
changeset
|
4324 if (*paddr == NULL) { |
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3271
diff
changeset
|
4325 return NGX_CONF_ERROR; |
3271
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3198
diff
changeset
|
4326 } |
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3198
diff
changeset
|
4327 |
3272
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3271
diff
changeset
|
4328 value = cf->args->elts; |
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3271
diff
changeset
|
4329 |
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3271
diff
changeset
|
4330 rc = ngx_parse_addr(cf->pool, *paddr, value[1].data, value[1].len); |
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3271
diff
changeset
|
4331 |
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3271
diff
changeset
|
4332 switch (rc) { |
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3271
diff
changeset
|
4333 case NGX_OK: |
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3271
diff
changeset
|
4334 (*paddr)->name = value[1]; |
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3271
diff
changeset
|
4335 return NGX_CONF_OK; |
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3271
diff
changeset
|
4336 |
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3271
diff
changeset
|
4337 case NGX_DECLINED: |
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3271
diff
changeset
|
4338 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3271
diff
changeset
|
4339 "invalid address \"%V\"", &value[1]); |
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3271
diff
changeset
|
4340 default: |
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3271
diff
changeset
|
4341 return NGX_CONF_ERROR; |
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3271
diff
changeset
|
4342 } |
3271
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3198
diff
changeset
|
4343 } |
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3198
diff
changeset
|
4344 |
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3198
diff
changeset
|
4345 |
1701
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4346 ngx_int_t |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4347 ngx_http_upstream_hide_headers_hash(ngx_conf_t *cf, |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4348 ngx_http_upstream_conf_t *conf, ngx_http_upstream_conf_t *prev, |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4349 ngx_str_t *default_hide_headers, ngx_hash_init_t *hash) |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4350 { |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4351 ngx_str_t *h; |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4352 ngx_uint_t i, j; |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4353 ngx_array_t hide_headers; |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4354 ngx_hash_key_t *hk; |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4355 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4356 if (conf->hide_headers == NGX_CONF_UNSET_PTR |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4357 && conf->pass_headers == NGX_CONF_UNSET_PTR) |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4358 { |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4359 conf->hide_headers_hash = prev->hide_headers_hash; |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4360 |
2929
37b7cd336fdf
inherit proxy_set_header, proxy_hide_header, and fastcgi_hide_header
Igor Sysoev <igor@sysoev.ru>
parents:
2927
diff
changeset
|
4361 if (conf->hide_headers_hash.buckets |
2949
fe484c0be7c0
fix building --without-http-cache, broken in r2930
Igor Sysoev <igor@sysoev.ru>
parents:
2929
diff
changeset
|
4362 #if (NGX_HTTP_CACHE) |
fe484c0be7c0
fix building --without-http-cache, broken in r2930
Igor Sysoev <igor@sysoev.ru>
parents:
2929
diff
changeset
|
4363 && ((conf->cache == NULL) == (prev->cache == NULL)) |
fe484c0be7c0
fix building --without-http-cache, broken in r2930
Igor Sysoev <igor@sysoev.ru>
parents:
2929
diff
changeset
|
4364 #endif |
fe484c0be7c0
fix building --without-http-cache, broken in r2930
Igor Sysoev <igor@sysoev.ru>
parents:
2929
diff
changeset
|
4365 ) |
2929
37b7cd336fdf
inherit proxy_set_header, proxy_hide_header, and fastcgi_hide_header
Igor Sysoev <igor@sysoev.ru>
parents:
2927
diff
changeset
|
4366 { |
1701
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4367 return NGX_OK; |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4368 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4369 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4370 conf->hide_headers = prev->hide_headers; |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4371 conf->pass_headers = prev->pass_headers; |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4372 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4373 } else { |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4374 if (conf->hide_headers == NGX_CONF_UNSET_PTR) { |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4375 conf->hide_headers = prev->hide_headers; |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4376 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4377 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4378 if (conf->pass_headers == NGX_CONF_UNSET_PTR) { |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4379 conf->pass_headers = prev->pass_headers; |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4380 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4381 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4382 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4383 if (ngx_array_init(&hide_headers, cf->temp_pool, 4, sizeof(ngx_hash_key_t)) |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4384 != NGX_OK) |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4385 { |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4386 return NGX_ERROR; |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4387 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4388 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4389 for (h = default_hide_headers; h->len; h++) { |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4390 hk = ngx_array_push(&hide_headers); |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4391 if (hk == NULL) { |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4392 return NGX_ERROR; |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4393 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4394 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4395 hk->key = *h; |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4396 hk->key_hash = ngx_hash_key_lc(h->data, h->len); |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4397 hk->value = (void *) 1; |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4398 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4399 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4400 if (conf->hide_headers != NGX_CONF_UNSET_PTR) { |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4401 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4402 h = conf->hide_headers->elts; |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4403 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4404 for (i = 0; i < conf->hide_headers->nelts; i++) { |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4405 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4406 hk = hide_headers.elts; |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4407 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4408 for (j = 0; j < hide_headers.nelts; j++) { |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4409 if (ngx_strcasecmp(h[i].data, hk[j].key.data) == 0) { |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4410 goto exist; |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4411 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4412 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4413 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4414 hk = ngx_array_push(&hide_headers); |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4415 if (hk == NULL) { |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4416 return NGX_ERROR; |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4417 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4418 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4419 hk->key = h[i]; |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4420 hk->key_hash = ngx_hash_key_lc(h[i].data, h[i].len); |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4421 hk->value = (void *) 1; |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4422 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4423 exist: |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4424 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4425 continue; |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4426 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4427 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4428 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4429 if (conf->pass_headers != NGX_CONF_UNSET_PTR) { |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4430 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4431 h = conf->pass_headers->elts; |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4432 hk = hide_headers.elts; |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4433 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4434 for (i = 0; i < conf->pass_headers->nelts; i++) { |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4435 for (j = 0; j < hide_headers.nelts; j++) { |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4436 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4437 if (hk[j].key.data == NULL) { |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4438 continue; |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4439 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4440 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4441 if (ngx_strcasecmp(h[i].data, hk[j].key.data) == 0) { |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4442 hk[j].key.data = NULL; |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4443 break; |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4444 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4445 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4446 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4447 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4448 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4449 hash->hash = &conf->hide_headers_hash; |
1706
9242e21d2f8d
style fix: remove trailing spaces
Igor Sysoev <igor@sysoev.ru>
parents:
1705
diff
changeset
|
4450 hash->key = ngx_hash_key_lc; |
1701
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4451 hash->pool = cf->pool; |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4452 hash->temp_pool = NULL; |
1706
9242e21d2f8d
style fix: remove trailing spaces
Igor Sysoev <igor@sysoev.ru>
parents:
1705
diff
changeset
|
4453 |
1701
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4454 return ngx_hash_init(hash, hide_headers.elts, hide_headers.nelts); |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4455 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4456 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
4457 |
509 | 4458 static void * |
4459 ngx_http_upstream_create_main_conf(ngx_conf_t *cf) | |
4460 { | |
4461 ngx_http_upstream_main_conf_t *umcf; | |
4462 | |
4463 umcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_upstream_main_conf_t)); | |
4464 if (umcf == NULL) { | |
4465 return NULL; | |
4466 } | |
4467 | |
651 | 4468 if (ngx_array_init(&umcf->upstreams, cf->pool, 4, |
4469 sizeof(ngx_http_upstream_srv_conf_t *)) | |
4470 != NGX_OK) | |
4471 { | |
2912
c7d57b539248
return NULL instead of NGX_CONF_ERROR on a create conf failure
Igor Sysoev <igor@sysoev.ru>
parents:
2882
diff
changeset
|
4472 return NULL; |
651 | 4473 } |
4474 | |
509 | 4475 return umcf; |
4476 } | |
4477 | |
4478 | |
4479 static char * | |
651 | 4480 ngx_http_upstream_init_main_conf(ngx_conf_t *cf, void *conf) |
509 | 4481 { |
4482 ngx_http_upstream_main_conf_t *umcf = conf; | |
4483 | |
651 | 4484 ngx_uint_t i; |
4485 ngx_array_t headers_in; | |
4486 ngx_hash_key_t *hk; | |
4487 ngx_hash_init_t hash; | |
884 | 4488 ngx_http_upstream_init_pt init; |
651 | 4489 ngx_http_upstream_header_t *header; |
4490 ngx_http_upstream_srv_conf_t **uscfp; | |
4491 | |
4492 uscfp = umcf->upstreams.elts; | |
4493 | |
4494 for (i = 0; i < umcf->upstreams.nelts; i++) { | |
884 | 4495 |
4496 init = uscfp[i]->peer.init_upstream ? uscfp[i]->peer.init_upstream: | |
4497 ngx_http_upstream_init_round_robin; | |
4498 | |
4499 if (init(cf, uscfp[i]) != NGX_OK) { | |
651 | 4500 return NGX_CONF_ERROR; |
4501 } | |
4502 } | |
649 | 4503 |
663 | 4504 |
884 | 4505 /* upstream_headers_in_hash */ |
4506 | |
649 | 4507 if (ngx_array_init(&headers_in, cf->temp_pool, 32, sizeof(ngx_hash_key_t)) |
4508 != NGX_OK) | |
509 | 4509 { |
4510 return NGX_CONF_ERROR; | |
4511 } | |
4512 | |
649 | 4513 for (header = ngx_http_upstream_headers_in; header->name.len; header++) { |
4514 hk = ngx_array_push(&headers_in); | |
4515 if (hk == NULL) { | |
4516 return NGX_CONF_ERROR; | |
4517 } | |
4518 | |
4519 hk->key = header->name; | |
4520 hk->key_hash = ngx_hash_key_lc(header->name.data, header->name.len); | |
4521 hk->value = header; | |
4522 } | |
4523 | |
4524 hash.hash = &umcf->headers_in_hash; | |
4525 hash.key = ngx_hash_key_lc; | |
4526 hash.max_size = 512; | |
751
bae59a740c40
align hash bucket size to cache line
Igor Sysoev <igor@sysoev.ru>
parents:
750
diff
changeset
|
4527 hash.bucket_size = ngx_align(64, ngx_cacheline_size); |
649 | 4528 hash.name = "upstream_headers_in_hash"; |
4529 hash.pool = cf->pool; | |
4530 hash.temp_pool = NULL; | |
4531 | |
4532 if (ngx_hash_init(&hash, headers_in.elts, headers_in.nelts) != NGX_OK) { | |
4533 return NGX_CONF_ERROR; | |
4534 } | |
509 | 4535 |
4536 return NGX_CONF_OK; | |
4537 } |