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