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