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