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