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