Mercurial > hg > nginx-quic
annotate src/http/ngx_http_upstream.c @ 5928:8dfee01ff0bd
Upstream: improved subrequest logging.
To ensure proper logging make sure to set current_request in all event
handlers, including resolve, ssl handshake, cache lock wait timer and
aio read handlers. A macro ngx_http_set_log_request() introduced to
simplify this.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Tue, 02 Dec 2014 05:54:54 +0300 |
parents | 88d55e5934f7 |
children | 1573fc7875fa |
rev | line source |
---|---|
479 | 1 |
2 /* | |
3 * Copyright (C) Igor Sysoev | |
4412 | 4 * Copyright (C) Nginx, Inc. |
479 | 5 */ |
6 | |
7 | |
8 #include <ngx_config.h> | |
9 #include <ngx_core.h> | |
10 #include <ngx_http.h> | |
11 | |
12 | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
13 #if (NGX_HTTP_CACHE) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
14 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
|
15 ngx_http_upstream_t *u); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
16 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
|
17 ngx_http_upstream_t *u); |
2952 | 18 static ngx_int_t ngx_http_upstream_cache_status(ngx_http_request_t *r, |
19 ngx_http_variable_value_t *v, uintptr_t data); | |
5441
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
20 static ngx_int_t ngx_http_upstream_cache_last_modified(ngx_http_request_t *r, |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
21 ngx_http_variable_value_t *v, uintptr_t data); |
5738
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
22 static ngx_int_t ngx_http_upstream_cache_etag(ngx_http_request_t *r, |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
23 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
|
24 #endif |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
25 |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
26 static void ngx_http_upstream_init_request(ngx_http_request_t *r); |
1658 | 27 static void ngx_http_upstream_resolve_handler(ngx_resolver_ctx_t *ctx); |
509 | 28 static void ngx_http_upstream_rd_check_broken_connection(ngx_http_request_t *r); |
29 static void ngx_http_upstream_wr_check_broken_connection(ngx_http_request_t *r); | |
30 static void ngx_http_upstream_check_broken_connection(ngx_http_request_t *r, | |
31 ngx_event_t *ev); | |
479 | 32 static void ngx_http_upstream_connect(ngx_http_request_t *r, |
487 | 33 ngx_http_upstream_t *u); |
509 | 34 static ngx_int_t ngx_http_upstream_reinit(ngx_http_request_t *r, |
487 | 35 ngx_http_upstream_t *u); |
479 | 36 static void ngx_http_upstream_send_request(ngx_http_request_t *r, |
487 | 37 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
|
38 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
|
39 ngx_http_upstream_t *u); |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
40 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
|
41 ngx_http_upstream_t *u); |
2268
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
42 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
|
43 ngx_http_upstream_t *u); |
2267
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
44 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
|
45 ngx_http_upstream_t *u); |
1153
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
46 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
|
47 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
|
48 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
|
49 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
|
50 ngx_http_upstream_t *u); |
479 | 51 static void ngx_http_upstream_send_response(ngx_http_request_t *r, |
487 | 52 ngx_http_upstream_t *u); |
5072
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
53 static void ngx_http_upstream_upgrade(ngx_http_request_t *r, |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
54 ngx_http_upstream_t *u); |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
55 static void ngx_http_upstream_upgraded_read_downstream(ngx_http_request_t *r); |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
56 static void ngx_http_upstream_upgraded_write_downstream(ngx_http_request_t *r); |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
57 static void ngx_http_upstream_upgraded_read_upstream(ngx_http_request_t *r, |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
58 ngx_http_upstream_t *u); |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
59 static void ngx_http_upstream_upgraded_write_upstream(ngx_http_request_t *r, |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
60 ngx_http_upstream_t *u); |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
61 static void ngx_http_upstream_process_upgraded(ngx_http_request_t *r, |
5073
52eb762c68a9
Proxy: fixed do_write handling in previous commit.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5072
diff
changeset
|
62 ngx_uint_t from_upstream, ngx_uint_t do_write); |
581 | 63 static void |
64 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
|
65 static void |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
66 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
|
67 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
|
68 static void |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
69 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
|
70 ngx_uint_t do_write); |
581 | 71 static ngx_int_t ngx_http_upstream_non_buffered_filter_init(void *data); |
72 static ngx_int_t ngx_http_upstream_non_buffered_filter(void *data, | |
73 ssize_t bytes); | |
509 | 74 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
|
75 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
|
76 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
|
77 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
|
78 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
|
79 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
|
80 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
|
81 ngx_http_upstream_t *u); |
479 | 82 static void ngx_http_upstream_next(ngx_http_request_t *r, |
487 | 83 ngx_http_upstream_t *u, ngx_uint_t ft_type); |
569 | 84 static void ngx_http_upstream_cleanup(void *data); |
479 | 85 static void ngx_http_upstream_finalize_request(ngx_http_request_t *r, |
487 | 86 ngx_http_upstream_t *u, ngx_int_t rc); |
479 | 87 |
509 | 88 static ngx_int_t ngx_http_upstream_process_header_line(ngx_http_request_t *r, |
89 ngx_table_elt_t *h, ngx_uint_t offset); | |
4117
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
90 static ngx_int_t ngx_http_upstream_process_content_length(ngx_http_request_t *r, |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
91 ngx_table_elt_t *h, ngx_uint_t offset); |
5732
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
92 static ngx_int_t ngx_http_upstream_process_last_modified(ngx_http_request_t *r, |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
93 ngx_table_elt_t *h, ngx_uint_t offset); |
3669
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
94 static ngx_int_t ngx_http_upstream_process_set_cookie(ngx_http_request_t *r, |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
95 ngx_table_elt_t *h, ngx_uint_t offset); |
509 | 96 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
|
97 ngx_http_upstream_process_cache_control(ngx_http_request_t *r, |
509 | 98 ngx_table_elt_t *h, ngx_uint_t offset); |
99 static ngx_int_t ngx_http_upstream_ignore_header_line(ngx_http_request_t *r, | |
100 ngx_table_elt_t *h, ngx_uint_t offset); | |
2666 | 101 static ngx_int_t ngx_http_upstream_process_expires(ngx_http_request_t *r, |
102 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
|
103 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
|
104 ngx_table_elt_t *h, ngx_uint_t offset); |
527 | 105 static ngx_int_t ngx_http_upstream_process_limit_rate(ngx_http_request_t *r, |
106 ngx_table_elt_t *h, ngx_uint_t offset); | |
649 | 107 static ngx_int_t ngx_http_upstream_process_buffering(ngx_http_request_t *r, |
509 | 108 ngx_table_elt_t *h, ngx_uint_t offset); |
657 | 109 static ngx_int_t ngx_http_upstream_process_charset(ngx_http_request_t *r, |
110 ngx_table_elt_t *h, ngx_uint_t offset); | |
4124
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
111 static ngx_int_t ngx_http_upstream_process_connection(ngx_http_request_t *r, |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
112 ngx_table_elt_t *h, ngx_uint_t offset); |
4123
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
113 static ngx_int_t |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
114 ngx_http_upstream_process_transfer_encoding(ngx_http_request_t *r, |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
115 ngx_table_elt_t *h, ngx_uint_t offset); |
5877
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
116 static ngx_int_t ngx_http_upstream_process_vary(ngx_http_request_t *r, |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
117 ngx_table_elt_t *h, ngx_uint_t offset); |
649 | 118 static ngx_int_t ngx_http_upstream_copy_header_line(ngx_http_request_t *r, |
509 | 119 ngx_table_elt_t *h, ngx_uint_t offset); |
120 static ngx_int_t | |
121 ngx_http_upstream_copy_multi_header_lines(ngx_http_request_t *r, | |
122 ngx_table_elt_t *h, ngx_uint_t offset); | |
123 static ngx_int_t ngx_http_upstream_copy_content_type(ngx_http_request_t *r, | |
124 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
|
125 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
|
126 ngx_table_elt_t *h, ngx_uint_t offset); |
509 | 127 static ngx_int_t ngx_http_upstream_rewrite_location(ngx_http_request_t *r, |
128 ngx_table_elt_t *h, ngx_uint_t offset); | |
129 static ngx_int_t ngx_http_upstream_rewrite_refresh(ngx_http_request_t *r, | |
130 ngx_table_elt_t *h, ngx_uint_t offset); | |
4464
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
131 static ngx_int_t ngx_http_upstream_rewrite_set_cookie(ngx_http_request_t *r, |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
132 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
|
133 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
|
134 ngx_table_elt_t *h, ngx_uint_t offset); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
135 |
509 | 136 #if (NGX_HTTP_GZIP) |
137 static ngx_int_t ngx_http_upstream_copy_content_encoding(ngx_http_request_t *r, | |
138 ngx_table_elt_t *h, ngx_uint_t offset); | |
139 #endif | |
140 | |
573 | 141 static ngx_int_t ngx_http_upstream_add_variables(ngx_conf_t *cf); |
1181 | 142 static ngx_int_t ngx_http_upstream_addr_variable(ngx_http_request_t *r, |
143 ngx_http_variable_value_t *v, uintptr_t data); | |
573 | 144 static ngx_int_t ngx_http_upstream_status_variable(ngx_http_request_t *r, |
145 ngx_http_variable_value_t *v, uintptr_t data); | |
146 static ngx_int_t ngx_http_upstream_response_time_variable(ngx_http_request_t *r, | |
147 ngx_http_variable_value_t *v, uintptr_t data); | |
2402 | 148 static ngx_int_t ngx_http_upstream_response_length_variable( |
149 ngx_http_request_t *r, ngx_http_variable_value_t *v, uintptr_t data); | |
573 | 150 |
651 | 151 static char *ngx_http_upstream(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy); |
152 static char *ngx_http_upstream_server(ngx_conf_t *cf, ngx_command_t *cmd, | |
153 void *conf); | |
154 | |
5008
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
155 static ngx_addr_t *ngx_http_upstream_get_local(ngx_http_request_t *r, |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
156 ngx_http_upstream_local_t *local); |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
157 |
509 | 158 static void *ngx_http_upstream_create_main_conf(ngx_conf_t *cf); |
651 | 159 static char *ngx_http_upstream_init_main_conf(ngx_conf_t *cf, void *conf); |
509 | 160 |
577 | 161 #if (NGX_HTTP_SSL) |
591 | 162 static void ngx_http_upstream_ssl_init_connection(ngx_http_request_t *, |
163 ngx_http_upstream_t *u, ngx_connection_t *c); | |
577 | 164 static void ngx_http_upstream_ssl_handshake(ngx_connection_t *c); |
5660
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
165 static ngx_int_t ngx_http_upstream_ssl_name(ngx_http_request_t *r, |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
166 ngx_http_upstream_t *u, ngx_connection_t *c); |
577 | 167 #endif |
168 | |
509 | 169 |
170 ngx_http_upstream_header_t ngx_http_upstream_headers_in[] = { | |
171 | |
172 { ngx_string("Status"), | |
173 ngx_http_upstream_process_header_line, | |
174 offsetof(ngx_http_upstream_headers_in_t, status), | |
649 | 175 ngx_http_upstream_copy_header_line, 0, 0 }, |
509 | 176 |
177 { ngx_string("Content-Type"), | |
178 ngx_http_upstream_process_header_line, | |
179 offsetof(ngx_http_upstream_headers_in_t, content_type), | |
673 | 180 ngx_http_upstream_copy_content_type, 0, 1 }, |
509 | 181 |
182 { ngx_string("Content-Length"), | |
5731
02674312be45
Upstream: removed unused offset to content_length.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5730
diff
changeset
|
183 ngx_http_upstream_process_content_length, 0, |
4117
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
184 ngx_http_upstream_ignore_header_line, 0, 0 }, |
509 | 185 |
186 { ngx_string("Date"), | |
187 ngx_http_upstream_process_header_line, | |
188 offsetof(ngx_http_upstream_headers_in_t, date), | |
649 | 189 ngx_http_upstream_copy_header_line, |
190 offsetof(ngx_http_headers_out_t, date), 0 }, | |
509 | 191 |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
192 { ngx_string("Last-Modified"), |
5732
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
193 ngx_http_upstream_process_last_modified, 0, |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
194 ngx_http_upstream_copy_last_modified, 0, 0 }, |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
195 |
3037 | 196 { ngx_string("ETag"), |
197 ngx_http_upstream_process_header_line, | |
198 offsetof(ngx_http_upstream_headers_in_t, etag), | |
199 ngx_http_upstream_copy_header_line, | |
200 offsetof(ngx_http_headers_out_t, etag), 0 }, | |
201 | |
509 | 202 { ngx_string("Server"), |
203 ngx_http_upstream_process_header_line, | |
204 offsetof(ngx_http_upstream_headers_in_t, server), | |
649 | 205 ngx_http_upstream_copy_header_line, |
206 offsetof(ngx_http_headers_out_t, server), 0 }, | |
509 | 207 |
529 | 208 { ngx_string("WWW-Authenticate"), |
209 ngx_http_upstream_process_header_line, | |
210 offsetof(ngx_http_upstream_headers_in_t, www_authenticate), | |
211 ngx_http_upstream_copy_header_line, 0, 0 }, | |
212 | |
509 | 213 { ngx_string("Location"), |
2140
dce5ddef5af9
if upstream sent a location header without status use 302
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
214 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
|
215 offsetof(ngx_http_upstream_headers_in_t, location), |
515 | 216 ngx_http_upstream_rewrite_location, 0, 0 }, |
509 | 217 |
218 { ngx_string("Refresh"), | |
219 ngx_http_upstream_ignore_header_line, 0, | |
515 | 220 ngx_http_upstream_rewrite_refresh, 0, 0 }, |
221 | |
222 { ngx_string("Set-Cookie"), | |
5677
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
223 ngx_http_upstream_process_set_cookie, |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
224 offsetof(ngx_http_upstream_headers_in_t, cookies), |
4464
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
225 ngx_http_upstream_rewrite_set_cookie, 0, 1 }, |
531 | 226 |
227 { ngx_string("Content-Disposition"), | |
228 ngx_http_upstream_ignore_header_line, 0, | |
229 ngx_http_upstream_copy_header_line, 0, 1 }, | |
509 | 230 |
231 { 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
|
232 ngx_http_upstream_process_cache_control, 0, |
509 | 233 ngx_http_upstream_copy_multi_header_lines, |
515 | 234 offsetof(ngx_http_headers_out_t, cache_control), 1 }, |
509 | 235 |
573 | 236 { ngx_string("Expires"), |
2666 | 237 ngx_http_upstream_process_expires, 0, |
573 | 238 ngx_http_upstream_copy_header_line, |
239 offsetof(ngx_http_headers_out_t, expires), 1 }, | |
240 | |
577 | 241 { ngx_string("Accept-Ranges"), |
242 ngx_http_upstream_process_header_line, | |
243 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
|
244 ngx_http_upstream_copy_allow_ranges, |
577 | 245 offsetof(ngx_http_headers_out_t, accept_ranges), 1 }, |
246 | |
509 | 247 { ngx_string("Connection"), |
4124
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
248 ngx_http_upstream_process_connection, 0, |
515 | 249 ngx_http_upstream_ignore_header_line, 0, 0 }, |
509 | 250 |
641 | 251 { ngx_string("Keep-Alive"), |
252 ngx_http_upstream_ignore_header_line, 0, | |
253 ngx_http_upstream_ignore_header_line, 0, 0 }, | |
254 | |
5877
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
255 { ngx_string("Vary"), |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
256 ngx_http_upstream_process_vary, 0, |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
257 ngx_http_upstream_copy_header_line, 0, 0 }, |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
258 |
509 | 259 { ngx_string("X-Powered-By"), |
260 ngx_http_upstream_ignore_header_line, 0, | |
649 | 261 ngx_http_upstream_copy_header_line, 0, 0 }, |
509 | 262 |
263 { ngx_string("X-Accel-Expires"), | |
2664 | 264 ngx_http_upstream_process_accel_expires, 0, |
649 | 265 ngx_http_upstream_copy_header_line, 0, 0 }, |
515 | 266 |
267 { ngx_string("X-Accel-Redirect"), | |
268 ngx_http_upstream_process_header_line, | |
269 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
|
270 ngx_http_upstream_copy_header_line, 0, 0 }, |
509 | 271 |
527 | 272 { ngx_string("X-Accel-Limit-Rate"), |
273 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
|
274 ngx_http_upstream_copy_header_line, 0, 0 }, |
527 | 275 |
649 | 276 { ngx_string("X-Accel-Buffering"), |
277 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
|
278 ngx_http_upstream_copy_header_line, 0, 0 }, |
649 | 279 |
657 | 280 { ngx_string("X-Accel-Charset"), |
281 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
|
282 ngx_http_upstream_copy_header_line, 0, 0 }, |
657 | 283 |
4123
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
284 { ngx_string("Transfer-Encoding"), |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
285 ngx_http_upstream_process_transfer_encoding, 0, |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
286 ngx_http_upstream_ignore_header_line, 0, 0 }, |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
287 |
509 | 288 #if (NGX_HTTP_GZIP) |
289 { ngx_string("Content-Encoding"), | |
290 ngx_http_upstream_process_header_line, | |
291 offsetof(ngx_http_upstream_headers_in_t, content_encoding), | |
515 | 292 ngx_http_upstream_copy_content_encoding, 0, 0 }, |
509 | 293 #endif |
294 | |
515 | 295 { ngx_null_string, NULL, 0, NULL, 0, 0 } |
509 | 296 }; |
479 | 297 |
298 | |
651 | 299 static ngx_command_t ngx_http_upstream_commands[] = { |
300 | |
301 { ngx_string("upstream"), | |
302 NGX_HTTP_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_TAKE1, | |
303 ngx_http_upstream, | |
304 0, | |
305 0, | |
306 NULL }, | |
307 | |
308 { ngx_string("server"), | |
884 | 309 NGX_HTTP_UPS_CONF|NGX_CONF_1MORE, |
651 | 310 ngx_http_upstream_server, |
311 NGX_HTTP_SRV_CONF_OFFSET, | |
312 0, | |
313 NULL }, | |
314 | |
315 ngx_null_command | |
316 }; | |
317 | |
318 | |
319 static ngx_http_module_t ngx_http_upstream_module_ctx = { | |
573 | 320 ngx_http_upstream_add_variables, /* preconfiguration */ |
509 | 321 NULL, /* postconfiguration */ |
322 | |
323 ngx_http_upstream_create_main_conf, /* create main configuration */ | |
651 | 324 ngx_http_upstream_init_main_conf, /* init main configuration */ |
479 | 325 |
326 NULL, /* create server configuration */ | |
327 NULL, /* merge server configuration */ | |
328 | |
329 NULL, /* create location configuration */ | |
330 NULL /* merge location configuration */ | |
331 }; | |
577 | 332 |
479 | 333 |
334 ngx_module_t ngx_http_upstream_module = { | |
509 | 335 NGX_MODULE_V1, |
479 | 336 &ngx_http_upstream_module_ctx, /* module context */ |
651 | 337 ngx_http_upstream_commands, /* module directives */ |
479 | 338 NGX_HTTP_MODULE, /* module type */ |
541 | 339 NULL, /* init master */ |
479 | 340 NULL, /* init module */ |
541 | 341 NULL, /* init process */ |
342 NULL, /* init thread */ | |
343 NULL, /* exit thread */ | |
344 NULL, /* exit process */ | |
345 NULL, /* exit master */ | |
346 NGX_MODULE_V1_PADDING | |
479 | 347 }; |
348 | |
349 | |
573 | 350 static ngx_http_variable_t ngx_http_upstream_vars[] = { |
351 | |
1181 | 352 { 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
|
353 ngx_http_upstream_addr_variable, 0, |
3898
bd1222fb0192
allow to use $upstream_... variables in SSI
Igor Sysoev <igor@sysoev.ru>
parents:
3879
diff
changeset
|
354 NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
1181 | 355 |
637 | 356 { 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
|
357 ngx_http_upstream_status_variable, 0, |
3898
bd1222fb0192
allow to use $upstream_... variables in SSI
Igor Sysoev <igor@sysoev.ru>
parents:
3879
diff
changeset
|
358 NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
573 | 359 |
637 | 360 { 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
|
361 ngx_http_upstream_response_time_variable, 0, |
3898
bd1222fb0192
allow to use $upstream_... variables in SSI
Igor Sysoev <igor@sysoev.ru>
parents:
3879
diff
changeset
|
362 NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
573 | 363 |
2402 | 364 { ngx_string("upstream_response_length"), NULL, |
365 ngx_http_upstream_response_length_variable, 0, | |
3898
bd1222fb0192
allow to use $upstream_... variables in SSI
Igor Sysoev <igor@sysoev.ru>
parents:
3879
diff
changeset
|
366 NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
2402 | 367 |
2957
b4f39842523b
fix building --without-http-cache, broken in r2953
Igor Sysoev <igor@sysoev.ru>
parents:
2953
diff
changeset
|
368 #if (NGX_HTTP_CACHE) |
b4f39842523b
fix building --without-http-cache, broken in r2953
Igor Sysoev <igor@sysoev.ru>
parents:
2953
diff
changeset
|
369 |
2952 | 370 { ngx_string("upstream_cache_status"), NULL, |
371 ngx_http_upstream_cache_status, 0, | |
3898
bd1222fb0192
allow to use $upstream_... variables in SSI
Igor Sysoev <igor@sysoev.ru>
parents:
3879
diff
changeset
|
372 NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
2952 | 373 |
5441
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
374 { ngx_string("upstream_cache_last_modified"), NULL, |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
375 ngx_http_upstream_cache_last_modified, 0, |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
376 NGX_HTTP_VAR_NOCACHEABLE|NGX_HTTP_VAR_NOHASH, 0 }, |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
377 |
5738
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
378 { ngx_string("upstream_cache_etag"), NULL, |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
379 ngx_http_upstream_cache_etag, 0, |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
380 NGX_HTTP_VAR_NOCACHEABLE|NGX_HTTP_VAR_NOHASH, 0 }, |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
381 |
2957
b4f39842523b
fix building --without-http-cache, broken in r2953
Igor Sysoev <igor@sysoev.ru>
parents:
2953
diff
changeset
|
382 #endif |
b4f39842523b
fix building --without-http-cache, broken in r2953
Igor Sysoev <igor@sysoev.ru>
parents:
2953
diff
changeset
|
383 |
637 | 384 { ngx_null_string, NULL, NULL, 0, 0, 0 } |
573 | 385 }; |
386 | |
387 | |
2268
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
388 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
|
389 { 500, NGX_HTTP_UPSTREAM_FT_HTTP_500 }, |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
390 { 502, NGX_HTTP_UPSTREAM_FT_HTTP_502 }, |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
391 { 503, NGX_HTTP_UPSTREAM_FT_HTTP_503 }, |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
392 { 504, NGX_HTTP_UPSTREAM_FT_HTTP_504 }, |
5231
05c53652e7b4
Upstream: http_403 support in proxy_next_upstream (and friends).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5217
diff
changeset
|
393 { 403, NGX_HTTP_UPSTREAM_FT_HTTP_403 }, |
2268
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
394 { 404, NGX_HTTP_UPSTREAM_FT_HTTP_404 }, |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
395 { 0, 0 } |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
396 }; |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
397 |
2875
6e1941b321b7
proxy_cache_methods and fastcgi_cache_methods
Igor Sysoev <igor@sysoev.ru>
parents:
2874
diff
changeset
|
398 |
6e1941b321b7
proxy_cache_methods and fastcgi_cache_methods
Igor Sysoev <igor@sysoev.ru>
parents:
2874
diff
changeset
|
399 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
|
400 { ngx_string("GET"), NGX_HTTP_GET}, |
6e1941b321b7
proxy_cache_methods and fastcgi_cache_methods
Igor Sysoev <igor@sysoev.ru>
parents:
2874
diff
changeset
|
401 { ngx_string("HEAD"), NGX_HTTP_HEAD }, |
6e1941b321b7
proxy_cache_methods and fastcgi_cache_methods
Igor Sysoev <igor@sysoev.ru>
parents:
2874
diff
changeset
|
402 { ngx_string("POST"), NGX_HTTP_POST }, |
6e1941b321b7
proxy_cache_methods and fastcgi_cache_methods
Igor Sysoev <igor@sysoev.ru>
parents:
2874
diff
changeset
|
403 { ngx_null_string, 0 } |
6e1941b321b7
proxy_cache_methods and fastcgi_cache_methods
Igor Sysoev <igor@sysoev.ru>
parents:
2874
diff
changeset
|
404 }; |
6e1941b321b7
proxy_cache_methods and fastcgi_cache_methods
Igor Sysoev <igor@sysoev.ru>
parents:
2874
diff
changeset
|
405 |
6e1941b321b7
proxy_cache_methods and fastcgi_cache_methods
Igor Sysoev <igor@sysoev.ru>
parents:
2874
diff
changeset
|
406 |
3667
12bd9e26fadb
use shared ngx_http_upstream_ignore_headers_masks[]
Igor Sysoev <igor@sysoev.ru>
parents:
3527
diff
changeset
|
407 ngx_conf_bitmask_t ngx_http_upstream_ignore_headers_masks[] = { |
12bd9e26fadb
use shared ngx_http_upstream_ignore_headers_masks[]
Igor Sysoev <igor@sysoev.ru>
parents:
3527
diff
changeset
|
408 { ngx_string("X-Accel-Redirect"), NGX_HTTP_UPSTREAM_IGN_XA_REDIRECT }, |
12bd9e26fadb
use shared ngx_http_upstream_ignore_headers_masks[]
Igor Sysoev <igor@sysoev.ru>
parents:
3527
diff
changeset
|
409 { ngx_string("X-Accel-Expires"), NGX_HTTP_UPSTREAM_IGN_XA_EXPIRES }, |
4197
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
410 { ngx_string("X-Accel-Limit-Rate"), NGX_HTTP_UPSTREAM_IGN_XA_LIMIT_RATE }, |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
411 { ngx_string("X-Accel-Buffering"), NGX_HTTP_UPSTREAM_IGN_XA_BUFFERING }, |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
412 { ngx_string("X-Accel-Charset"), NGX_HTTP_UPSTREAM_IGN_XA_CHARSET }, |
3667
12bd9e26fadb
use shared ngx_http_upstream_ignore_headers_masks[]
Igor Sysoev <igor@sysoev.ru>
parents:
3527
diff
changeset
|
413 { ngx_string("Expires"), NGX_HTTP_UPSTREAM_IGN_EXPIRES }, |
12bd9e26fadb
use shared ngx_http_upstream_ignore_headers_masks[]
Igor Sysoev <igor@sysoev.ru>
parents:
3527
diff
changeset
|
414 { ngx_string("Cache-Control"), NGX_HTTP_UPSTREAM_IGN_CACHE_CONTROL }, |
3669
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
415 { ngx_string("Set-Cookie"), NGX_HTTP_UPSTREAM_IGN_SET_COOKIE }, |
5877
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
416 { ngx_string("Vary"), NGX_HTTP_UPSTREAM_IGN_VARY }, |
3667
12bd9e26fadb
use shared ngx_http_upstream_ignore_headers_masks[]
Igor Sysoev <igor@sysoev.ru>
parents:
3527
diff
changeset
|
417 { ngx_null_string, 0 } |
12bd9e26fadb
use shared ngx_http_upstream_ignore_headers_masks[]
Igor Sysoev <igor@sysoev.ru>
parents:
3527
diff
changeset
|
418 }; |
12bd9e26fadb
use shared ngx_http_upstream_ignore_headers_masks[]
Igor Sysoev <igor@sysoev.ru>
parents:
3527
diff
changeset
|
419 |
12bd9e26fadb
use shared ngx_http_upstream_ignore_headers_masks[]
Igor Sysoev <igor@sysoev.ru>
parents:
3527
diff
changeset
|
420 |
3006
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
421 ngx_int_t |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
422 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
|
423 { |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
424 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
|
425 |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
426 u = r->upstream; |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
427 |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
428 if (u && u->cleanup) { |
3112
5ddc9458e4bb
increase request counter before an upstream cleanup because the cleanup
Igor Sysoev <igor@sysoev.ru>
parents:
3083
diff
changeset
|
429 r->main->count++; |
3006
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
430 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
|
431 } |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
432 |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
433 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
|
434 if (u == NULL) { |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
435 return NGX_ERROR; |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
436 } |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
437 |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
438 r->upstream = u; |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
439 |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
440 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
|
441 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
|
442 #if (NGX_THREADS) |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
443 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
|
444 #endif |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
445 |
3056
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
446 #if (NGX_HTTP_CACHE) |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
447 r->cache = NULL; |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
448 #endif |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
449 |
4117
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
450 u->headers_in.content_length_n = -1; |
5869
fd283aa92e04
Upstream: fix $upstream_cache_last_modified variable.
Piotr Sikora <piotr@cloudflare.com>
parents:
5848
diff
changeset
|
451 u->headers_in.last_modified_time = -1; |
4117
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
452 |
3006
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
453 return NGX_OK; |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
454 } |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
455 |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
456 |
487 | 457 void |
458 ngx_http_upstream_init(ngx_http_request_t *r) | |
479 | 459 { |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
460 ngx_connection_t *c; |
479 | 461 |
462 c = r->connection; | |
463 | |
464 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
465 "http init upstream, client timer: %d", c->read->timer_set); | |
466 | |
5121
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
5113
diff
changeset
|
467 #if (NGX_HTTP_SPDY) |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
5113
diff
changeset
|
468 if (r->spdy_stream) { |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
5113
diff
changeset
|
469 ngx_http_upstream_init_request(r); |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
5113
diff
changeset
|
470 return; |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
5113
diff
changeset
|
471 } |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
5113
diff
changeset
|
472 #endif |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
5113
diff
changeset
|
473 |
479 | 474 if (c->read->timer_set) { |
475 ngx_del_timer(c->read); | |
476 } | |
477 | |
478 if (ngx_event_flags & NGX_USE_CLEAR_EVENT) { | |
479 | |
480 if (!c->write->active) { | |
531 | 481 if (ngx_add_event(c->write, NGX_WRITE_EVENT, NGX_CLEAR_EVENT) |
482 == NGX_ERROR) | |
479 | 483 { |
484 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | |
485 return; | |
486 } | |
487 } | |
488 } | |
489 | |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
490 ngx_http_upstream_init_request(r); |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
491 } |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
492 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
493 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
494 static void |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
495 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
|
496 { |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
497 ngx_str_t *host; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
498 ngx_uint_t i; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
499 ngx_resolver_ctx_t *ctx, temp; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
500 ngx_http_cleanup_t *cln; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
501 ngx_http_upstream_t *u; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
502 ngx_http_core_loc_conf_t *clcf; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
503 ngx_http_upstream_srv_conf_t *uscf, **uscfp; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
504 ngx_http_upstream_main_conf_t *umcf; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
505 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
506 if (r->aio) { |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
507 return; |
537 | 508 } |
509 | 509 |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
510 u = r->upstream; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
511 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
512 #if (NGX_HTTP_CACHE) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
513 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
514 if (u->conf->cache) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
515 ngx_int_t rc; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
516 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
517 rc = ngx_http_upstream_cache(r, u); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
518 |
3055
92b6cfaa3c27
fix sending a cached file using AIO
Igor Sysoev <igor@sysoev.ru>
parents:
3053
diff
changeset
|
519 if (rc == NGX_BUSY) { |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
520 r->write_event_handler = ngx_http_upstream_init_request; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
521 return; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
522 } |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
523 |
3055
92b6cfaa3c27
fix sending a cached file using AIO
Igor Sysoev <igor@sysoev.ru>
parents:
3053
diff
changeset
|
524 r->write_event_handler = ngx_http_request_empty_handler; |
92b6cfaa3c27
fix sending a cached file using AIO
Igor Sysoev <igor@sysoev.ru>
parents:
3053
diff
changeset
|
525 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
526 if (rc == NGX_DONE) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
527 return; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
528 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
529 |
5827
54e9b83d00f0
Upstream: avoided directly terminating the connection.
FengGu <flygoast@126.com>
parents:
5818
diff
changeset
|
530 if (rc == NGX_ERROR) { |
54e9b83d00f0
Upstream: avoided directly terminating the connection.
FengGu <flygoast@126.com>
parents:
5818
diff
changeset
|
531 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); |
54e9b83d00f0
Upstream: avoided directly terminating the connection.
FengGu <flygoast@126.com>
parents:
5818
diff
changeset
|
532 return; |
54e9b83d00f0
Upstream: avoided directly terminating the connection.
FengGu <flygoast@126.com>
parents:
5818
diff
changeset
|
533 } |
54e9b83d00f0
Upstream: avoided directly terminating the connection.
FengGu <flygoast@126.com>
parents:
5818
diff
changeset
|
534 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
535 if (rc != NGX_DECLINED) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
536 ngx_http_finalize_request(r, rc); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
537 return; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
538 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
539 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
540 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
541 #endif |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
542 |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
543 u->store = (u->conf->store || u->conf->store_lengths); |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
544 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
545 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
|
546 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
|
547 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
|
548 } |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
549 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
550 if (r->request_body) { |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
551 u->request_bufs = r->request_body->bufs; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
552 } |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
553 |
537 | 554 if (u->create_request(r) != NGX_OK) { |
479 | 555 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); |
556 return; | |
557 } | |
558 | |
5008
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
559 u->peer.local = ngx_http_upstream_get_local(r, u->conf->local); |
3271
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3198
diff
changeset
|
560 |
509 | 561 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
479 | 562 |
3053 | 563 u->output.alignment = clcf->directio_alignment; |
479 | 564 u->output.pool = r->pool; |
565 u->output.bufs.num = 1; | |
509 | 566 u->output.bufs.size = clcf->client_body_buffer_size; |
479 | 567 u->output.output_filter = ngx_chain_writer; |
568 u->output.filter_ctx = &u->writer; | |
569 | |
570 u->writer.pool = r->pool; | |
571 | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
572 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
|
573 |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
574 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
|
575 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
|
576 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
|
577 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
|
578 return; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
579 } |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
580 |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
581 } else { |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
582 |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
583 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
|
584 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
|
585 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
|
586 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
|
587 return; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
588 } |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
589 |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
590 ngx_memzero(u->state, sizeof(ngx_http_upstream_state_t)); |
479 | 591 } |
592 | |
593 | 593 cln = ngx_http_cleanup_add(r, 0); |
569 | 594 if (cln == NULL) { |
595 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | |
596 return; | |
597 } | |
598 | |
599 cln->handler = ngx_http_upstream_cleanup; | |
600 cln->data = r; | |
601 u->cleanup = &cln->handler; | |
602 | |
1658 | 603 if (u->resolved == NULL) { |
604 | |
605 uscf = u->conf->upstream; | |
606 | |
607 } else { | |
608 | |
5660
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
609 #if (NGX_HTTP_SSL) |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
610 u->ssl_name = u->resolved->host; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
611 #endif |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
612 |
2422
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2413
diff
changeset
|
613 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
|
614 |
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2413
diff
changeset
|
615 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
|
616 != NGX_OK) |
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2413
diff
changeset
|
617 { |
3169
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
618 ngx_http_upstream_finalize_request(r, u, |
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
619 NGX_HTTP_INTERNAL_SERVER_ERROR); |
2422
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2413
diff
changeset
|
620 return; |
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2413
diff
changeset
|
621 } |
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2413
diff
changeset
|
622 |
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2413
diff
changeset
|
623 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
|
624 |
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2413
diff
changeset
|
625 return; |
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2413
diff
changeset
|
626 } |
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2413
diff
changeset
|
627 |
1705 | 628 host = &u->resolved->host; |
1658 | 629 |
630 umcf = ngx_http_get_module_main_conf(r, ngx_http_upstream_module); | |
631 | |
632 uscfp = umcf->upstreams.elts; | |
633 | |
634 for (i = 0; i < umcf->upstreams.nelts; i++) { | |
635 | |
636 uscf = uscfp[i]; | |
637 | |
638 if (uscf->host.len == host->len | |
2285 | 639 && ((uscf->port == 0 && u->resolved->no_port) |
1912 | 640 || uscf->port == u->resolved->port) |
5546
f385349d584b
Proxy: fixed upstream search by proxy_pass with variables.
Ruslan Ermilov <ru@nginx.com>
parents:
5532
diff
changeset
|
641 && ngx_strncasecmp(uscf->host.data, host->data, host->len) == 0) |
1658 | 642 { |
643 goto found; | |
644 } | |
645 } | |
646 | |
3879
502a6b0acf3f
fix case when a host in fastcgi_pass, scgi_pass, and uwsgi_pass
Igor Sysoev <igor@sysoev.ru>
parents:
3713
diff
changeset
|
647 if (u->resolved->port == 0) { |
502a6b0acf3f
fix case when a host in fastcgi_pass, scgi_pass, and uwsgi_pass
Igor Sysoev <igor@sysoev.ru>
parents:
3713
diff
changeset
|
648 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
502a6b0acf3f
fix case when a host in fastcgi_pass, scgi_pass, and uwsgi_pass
Igor Sysoev <igor@sysoev.ru>
parents:
3713
diff
changeset
|
649 "no port in upstream \"%V\"", host); |
502a6b0acf3f
fix case when a host in fastcgi_pass, scgi_pass, and uwsgi_pass
Igor Sysoev <igor@sysoev.ru>
parents:
3713
diff
changeset
|
650 ngx_http_upstream_finalize_request(r, u, |
502a6b0acf3f
fix case when a host in fastcgi_pass, scgi_pass, and uwsgi_pass
Igor Sysoev <igor@sysoev.ru>
parents:
3713
diff
changeset
|
651 NGX_HTTP_INTERNAL_SERVER_ERROR); |
502a6b0acf3f
fix case when a host in fastcgi_pass, scgi_pass, and uwsgi_pass
Igor Sysoev <igor@sysoev.ru>
parents:
3713
diff
changeset
|
652 return; |
502a6b0acf3f
fix case when a host in fastcgi_pass, scgi_pass, and uwsgi_pass
Igor Sysoev <igor@sysoev.ru>
parents:
3713
diff
changeset
|
653 } |
502a6b0acf3f
fix case when a host in fastcgi_pass, scgi_pass, and uwsgi_pass
Igor Sysoev <igor@sysoev.ru>
parents:
3713
diff
changeset
|
654 |
1658 | 655 temp.name = *host; |
656 | |
657 ctx = ngx_resolve_start(clcf->resolver, &temp); | |
658 if (ctx == NULL) { | |
3169
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
659 ngx_http_upstream_finalize_request(r, u, |
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
660 NGX_HTTP_INTERNAL_SERVER_ERROR); |
1658 | 661 return; |
662 } | |
663 | |
1683
1e0b028055ec
allow to use IP addresses without defined resolver
Igor Sysoev <igor@sysoev.ru>
parents:
1658
diff
changeset
|
664 if (ctx == NGX_NO_RESOLVER) { |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
665 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
|
666 "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
|
667 |
3169
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
668 ngx_http_upstream_finalize_request(r, u, NGX_HTTP_BAD_GATEWAY); |
1683
1e0b028055ec
allow to use IP addresses without defined resolver
Igor Sysoev <igor@sysoev.ru>
parents:
1658
diff
changeset
|
669 return; |
1e0b028055ec
allow to use IP addresses without defined resolver
Igor Sysoev <igor@sysoev.ru>
parents:
1658
diff
changeset
|
670 } |
1e0b028055ec
allow to use IP addresses without defined resolver
Igor Sysoev <igor@sysoev.ru>
parents:
1658
diff
changeset
|
671 |
1658 | 672 ctx->name = *host; |
673 ctx->handler = ngx_http_upstream_resolve_handler; | |
674 ctx->data = r; | |
675 ctx->timeout = clcf->resolver_timeout; | |
676 | |
1959
4f16186f5603
quick resolving handles u->resolved->ctx by itself
Igor Sysoev <igor@sysoev.ru>
parents:
1958
diff
changeset
|
677 u->resolved->ctx = ctx; |
4f16186f5603
quick resolving handles u->resolved->ctx by itself
Igor Sysoev <igor@sysoev.ru>
parents:
1958
diff
changeset
|
678 |
1658 | 679 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
|
680 u->resolved->ctx = NULL; |
3169
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
681 ngx_http_upstream_finalize_request(r, u, |
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
682 NGX_HTTP_INTERNAL_SERVER_ERROR); |
1658 | 683 return; |
684 } | |
685 | |
686 return; | |
687 } | |
688 | |
689 found: | |
690 | |
4964
2464ccebdb52
Upstream: fixed SIGSEGV with the "if" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4916
diff
changeset
|
691 if (uscf == NULL) { |
2464ccebdb52
Upstream: fixed SIGSEGV with the "if" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4916
diff
changeset
|
692 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, |
2464ccebdb52
Upstream: fixed SIGSEGV with the "if" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4916
diff
changeset
|
693 "no upstream configuration"); |
2464ccebdb52
Upstream: fixed SIGSEGV with the "if" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4916
diff
changeset
|
694 ngx_http_upstream_finalize_request(r, u, |
2464ccebdb52
Upstream: fixed SIGSEGV with the "if" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4916
diff
changeset
|
695 NGX_HTTP_INTERNAL_SERVER_ERROR); |
2464ccebdb52
Upstream: fixed SIGSEGV with the "if" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4916
diff
changeset
|
696 return; |
2464ccebdb52
Upstream: fixed SIGSEGV with the "if" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4916
diff
changeset
|
697 } |
2464ccebdb52
Upstream: fixed SIGSEGV with the "if" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4916
diff
changeset
|
698 |
5682
110b50657d77
Upstream: restored workaround for "if".
Maxim Dounin <mdounin@mdounin.ru>
parents:
5677
diff
changeset
|
699 #if (NGX_HTTP_SSL) |
110b50657d77
Upstream: restored workaround for "if".
Maxim Dounin <mdounin@mdounin.ru>
parents:
5677
diff
changeset
|
700 u->ssl_name = uscf->host; |
110b50657d77
Upstream: restored workaround for "if".
Maxim Dounin <mdounin@mdounin.ru>
parents:
5677
diff
changeset
|
701 #endif |
110b50657d77
Upstream: restored workaround for "if".
Maxim Dounin <mdounin@mdounin.ru>
parents:
5677
diff
changeset
|
702 |
1658 | 703 if (uscf->peer.init(r, uscf) != NGX_OK) { |
3169
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
704 ngx_http_upstream_finalize_request(r, u, |
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
705 NGX_HTTP_INTERNAL_SERVER_ERROR); |
1658 | 706 return; |
707 } | |
708 | |
5832
d09b689911ac
Upstream: limited next_upstream time and tries (ticket #544).
Roman Arutyunyan <arut@nginx.com>
parents:
5827
diff
changeset
|
709 u->peer.start_time = ngx_current_msec; |
d09b689911ac
Upstream: limited next_upstream time and tries (ticket #544).
Roman Arutyunyan <arut@nginx.com>
parents:
5827
diff
changeset
|
710 |
d09b689911ac
Upstream: limited next_upstream time and tries (ticket #544).
Roman Arutyunyan <arut@nginx.com>
parents:
5827
diff
changeset
|
711 if (u->conf->next_upstream_tries |
d09b689911ac
Upstream: limited next_upstream time and tries (ticket #544).
Roman Arutyunyan <arut@nginx.com>
parents:
5827
diff
changeset
|
712 && u->peer.tries > u->conf->next_upstream_tries) |
d09b689911ac
Upstream: limited next_upstream time and tries (ticket #544).
Roman Arutyunyan <arut@nginx.com>
parents:
5827
diff
changeset
|
713 { |
d09b689911ac
Upstream: limited next_upstream time and tries (ticket #544).
Roman Arutyunyan <arut@nginx.com>
parents:
5827
diff
changeset
|
714 u->peer.tries = u->conf->next_upstream_tries; |
d09b689911ac
Upstream: limited next_upstream time and tries (ticket #544).
Roman Arutyunyan <arut@nginx.com>
parents:
5827
diff
changeset
|
715 } |
d09b689911ac
Upstream: limited next_upstream time and tries (ticket #544).
Roman Arutyunyan <arut@nginx.com>
parents:
5827
diff
changeset
|
716 |
479 | 717 ngx_http_upstream_connect(r, u); |
718 } | |
719 | |
720 | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
721 #if (NGX_HTTP_CACHE) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
722 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
723 static ngx_int_t |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
724 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
|
725 { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
726 ngx_int_t rc; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
727 ngx_http_cache_t *c; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
728 |
3056
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
729 c = r->cache; |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
730 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
731 if (c == NULL) { |
3056
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
732 |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
733 if (!(r->method & u->conf->cache_methods)) { |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
734 return NGX_DECLINED; |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
735 } |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
736 |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
737 if (r->method & NGX_HTTP_HEAD) { |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
738 u->method = ngx_http_core_get_method; |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
739 } |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
740 |
3698
d11227f0107f
rename ngx_http_file_cache_create() to ngx_http_file_cache_new()
Igor Sysoev <igor@sysoev.ru>
parents:
3697
diff
changeset
|
741 if (ngx_http_file_cache_new(r) != NGX_OK) { |
3056
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
742 return NGX_ERROR; |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
743 } |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
744 |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
745 if (u->create_key(r) != NGX_OK) { |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
746 return NGX_ERROR; |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
747 } |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
748 |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
749 /* TODO: add keys */ |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
750 |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
751 ngx_http_file_cache_create_key(r); |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
752 |
3976
215fe9223419
update r3945 with more descriptive error message
Igor Sysoev <igor@sysoev.ru>
parents:
3963
diff
changeset
|
753 if (r->cache->header_start + 256 >= u->conf->buffer_size) { |
3944
f1f194ceab16
fix segfault if cache key is larger than upstream buffer size
Igor Sysoev <igor@sysoev.ru>
parents:
3940
diff
changeset
|
754 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
3976
215fe9223419
update r3945 with more descriptive error message
Igor Sysoev <igor@sysoev.ru>
parents:
3963
diff
changeset
|
755 "%V_buffer_size %uz is not enough for cache key, " |
5581
4dee5ad51e9e
Upstream: fixed error message wording.
Konstantin Pavlov <thresh@nginx.com>
parents:
5579
diff
changeset
|
756 "it should be increased to at least %uz", |
3976
215fe9223419
update r3945 with more descriptive error message
Igor Sysoev <igor@sysoev.ru>
parents:
3963
diff
changeset
|
757 &u->conf->module, u->conf->buffer_size, |
215fe9223419
update r3945 with more descriptive error message
Igor Sysoev <igor@sysoev.ru>
parents:
3963
diff
changeset
|
758 ngx_align(r->cache->header_start + 256, 1024)); |
3944
f1f194ceab16
fix segfault if cache key is larger than upstream buffer size
Igor Sysoev <igor@sysoev.ru>
parents:
3940
diff
changeset
|
759 |
f1f194ceab16
fix segfault if cache key is larger than upstream buffer size
Igor Sysoev <igor@sysoev.ru>
parents:
3940
diff
changeset
|
760 r->cache = NULL; |
f1f194ceab16
fix segfault if cache key is larger than upstream buffer size
Igor Sysoev <igor@sysoev.ru>
parents:
3940
diff
changeset
|
761 return NGX_DECLINED; |
f1f194ceab16
fix segfault if cache key is larger than upstream buffer size
Igor Sysoev <igor@sysoev.ru>
parents:
3940
diff
changeset
|
762 } |
f1f194ceab16
fix segfault if cache key is larger than upstream buffer size
Igor Sysoev <igor@sysoev.ru>
parents:
3940
diff
changeset
|
763 |
4176
2b5151a2300b
Fixed cache bypass caching of non-cacheable replies (ticket #21).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4152
diff
changeset
|
764 u->cacheable = 1; |
2b5151a2300b
Fixed cache bypass caching of non-cacheable replies (ticket #21).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4152
diff
changeset
|
765 |
3917
2a70484a6580
fix a broken cached response if bypass/no_cache directive values are different,
Igor Sysoev <igor@sysoev.ru>
parents:
3898
diff
changeset
|
766 switch (ngx_http_test_predicates(r, u->conf->cache_bypass)) { |
2a70484a6580
fix a broken cached response if bypass/no_cache directive values are different,
Igor Sysoev <igor@sysoev.ru>
parents:
3898
diff
changeset
|
767 |
2a70484a6580
fix a broken cached response if bypass/no_cache directive values are different,
Igor Sysoev <igor@sysoev.ru>
parents:
3898
diff
changeset
|
768 case NGX_ERROR: |
2a70484a6580
fix a broken cached response if bypass/no_cache directive values are different,
Igor Sysoev <igor@sysoev.ru>
parents:
3898
diff
changeset
|
769 return NGX_ERROR; |
2a70484a6580
fix a broken cached response if bypass/no_cache directive values are different,
Igor Sysoev <igor@sysoev.ru>
parents:
3898
diff
changeset
|
770 |
2a70484a6580
fix a broken cached response if bypass/no_cache directive values are different,
Igor Sysoev <igor@sysoev.ru>
parents:
3898
diff
changeset
|
771 case NGX_DECLINED: |
2a70484a6580
fix a broken cached response if bypass/no_cache directive values are different,
Igor Sysoev <igor@sysoev.ru>
parents:
3898
diff
changeset
|
772 u->cache_status = NGX_HTTP_CACHE_BYPASS; |
2a70484a6580
fix a broken cached response if bypass/no_cache directive values are different,
Igor Sysoev <igor@sysoev.ru>
parents:
3898
diff
changeset
|
773 return NGX_DECLINED; |
2a70484a6580
fix a broken cached response if bypass/no_cache directive values are different,
Igor Sysoev <igor@sysoev.ru>
parents:
3898
diff
changeset
|
774 |
2a70484a6580
fix a broken cached response if bypass/no_cache directive values are different,
Igor Sysoev <igor@sysoev.ru>
parents:
3898
diff
changeset
|
775 default: /* NGX_OK */ |
2a70484a6580
fix a broken cached response if bypass/no_cache directive values are different,
Igor Sysoev <igor@sysoev.ru>
parents:
3898
diff
changeset
|
776 break; |
2a70484a6580
fix a broken cached response if bypass/no_cache directive values are different,
Igor Sysoev <igor@sysoev.ru>
parents:
3898
diff
changeset
|
777 } |
2a70484a6580
fix a broken cached response if bypass/no_cache directive values are different,
Igor Sysoev <igor@sysoev.ru>
parents:
3898
diff
changeset
|
778 |
3697 | 779 c = r->cache; |
780 | |
3056
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
781 c->min_uses = u->conf->cache_min_uses; |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
782 c->body_start = u->conf->buffer_size; |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
783 c->file_cache = u->conf->cache->data; |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
784 |
4385
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4375
diff
changeset
|
785 c->lock = u->conf->cache_lock; |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4375
diff
changeset
|
786 c->lock_timeout = u->conf->cache_lock_timeout; |
5905
2f7e557eab5b
Cache: proxy_cache_lock_age and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5901
diff
changeset
|
787 c->lock_age = u->conf->cache_lock_age; |
4385
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4375
diff
changeset
|
788 |
3056
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
789 u->cache_status = NGX_HTTP_CACHE_MISS; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
790 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
791 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
792 rc = ngx_http_file_cache_open(r); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
793 |
2926
80a314b63c56
delete useless r->cache->uses
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
794 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
|
795 "http upstream cache: %i", rc); |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
796 |
2952 | 797 switch (rc) { |
798 | |
799 case NGX_HTTP_CACHE_UPDATING: | |
800 | |
2927
55ceaef03d34
proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents:
2926
diff
changeset
|
801 if (u->conf->cache_use_stale & NGX_HTTP_UPSTREAM_FT_UPDATING) { |
2952 | 802 u->cache_status = rc; |
2927
55ceaef03d34
proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents:
2926
diff
changeset
|
803 rc = NGX_OK; |
55ceaef03d34
proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents:
2926
diff
changeset
|
804 |
55ceaef03d34
proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents:
2926
diff
changeset
|
805 } else { |
55ceaef03d34
proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents:
2926
diff
changeset
|
806 rc = NGX_HTTP_CACHE_STALE; |
55ceaef03d34
proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents:
2926
diff
changeset
|
807 } |
2952 | 808 |
809 break; | |
810 | |
811 case NGX_OK: | |
812 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
|
813 } |
55ceaef03d34
proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents:
2926
diff
changeset
|
814 |
2952 | 815 switch (rc) { |
816 | |
817 case NGX_OK: | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
818 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
819 rc = ngx_http_upstream_cache_send(r, u); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
820 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
821 if (rc != NGX_HTTP_UPSTREAM_INVALID_HEADER) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
822 return rc; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
823 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
824 |
2952 | 825 break; |
826 | |
827 case NGX_HTTP_CACHE_STALE: | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
828 |
2665
4d627567c324
fix r2664: ..._cache_valid did not work for stale responses
Igor Sysoev <igor@sysoev.ru>
parents:
2664
diff
changeset
|
829 c->valid_sec = 0; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
830 u->buffer.start = NULL; |
2952 | 831 u->cache_status = NGX_HTTP_CACHE_EXPIRED; |
832 | |
833 break; | |
834 | |
835 case NGX_DECLINED: | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
836 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
837 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
|
838 u->buffer.start = NULL; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
839 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
840 } else { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
841 u->buffer.pos = u->buffer.start + c->header_start; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
842 u->buffer.last = u->buffer.pos; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
843 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
844 |
2952 | 845 break; |
846 | |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
847 case NGX_HTTP_CACHE_SCARCE: |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
848 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
849 u->cacheable = 0; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
850 |
2952 | 851 break; |
852 | |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
853 case NGX_AGAIN: |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
854 |
3055
92b6cfaa3c27
fix sending a cached file using AIO
Igor Sysoev <igor@sysoev.ru>
parents:
3053
diff
changeset
|
855 return NGX_BUSY; |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
856 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
857 case NGX_ERROR: |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
858 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
859 return NGX_ERROR; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
860 |
2952 | 861 default: |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
862 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
863 /* 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
|
864 |
2952 | 865 u->cache_status = NGX_HTTP_CACHE_HIT; |
866 | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
867 return rc; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
868 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
869 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
870 r->cached = 0; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
871 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
872 return NGX_DECLINED; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
873 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
874 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
875 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
876 static ngx_int_t |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
877 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
|
878 { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
879 ngx_int_t rc; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
880 ngx_http_cache_t *c; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
881 |
2952 | 882 r->cached = 1; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
883 c = r->cache; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
884 |
3369
479468a7d982
fix handling cached HTTP/0.9 response
Igor Sysoev <igor@sysoev.ru>
parents:
3272
diff
changeset
|
885 if (c->header_start == c->body_start) { |
479468a7d982
fix handling cached HTTP/0.9 response
Igor Sysoev <igor@sysoev.ru>
parents:
3272
diff
changeset
|
886 r->http_version = NGX_HTTP_VERSION_9; |
479468a7d982
fix handling cached HTTP/0.9 response
Igor Sysoev <igor@sysoev.ru>
parents:
3272
diff
changeset
|
887 return ngx_http_cache_send(r); |
479468a7d982
fix handling cached HTTP/0.9 response
Igor Sysoev <igor@sysoev.ru>
parents:
3272
diff
changeset
|
888 } |
479468a7d982
fix handling cached HTTP/0.9 response
Igor Sysoev <igor@sysoev.ru>
parents:
3272
diff
changeset
|
889 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
890 /* TODO: cache stack */ |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
891 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
892 u->buffer = *c->buf; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
893 u->buffer.pos += c->header_start; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
894 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
895 ngx_memzero(&u->headers_in, sizeof(ngx_http_upstream_headers_in_t)); |
4117
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
896 u->headers_in.content_length_n = -1; |
5869
fd283aa92e04
Upstream: fix $upstream_cache_last_modified variable.
Piotr Sikora <piotr@cloudflare.com>
parents:
5848
diff
changeset
|
897 u->headers_in.last_modified_time = -1; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
898 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
899 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
|
900 sizeof(ngx_table_elt_t)) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
901 != NGX_OK) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
902 { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
903 return NGX_ERROR; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
904 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
905 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
906 rc = u->process_header(r); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
907 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
908 if (rc == NGX_OK) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
909 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
910 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
|
911 return NGX_DONE; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
912 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
913 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
914 return ngx_http_cache_send(r); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
915 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
916 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
917 if (rc == NGX_ERROR) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
918 return NGX_ERROR; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
919 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
920 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
921 /* rc == NGX_HTTP_UPSTREAM_INVALID_HEADER */ |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
922 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
923 /* TODO: delete file */ |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
924 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
925 return rc; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
926 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
927 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
928 #endif |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
929 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
930 |
487 | 931 static void |
1658 | 932 ngx_http_upstream_resolve_handler(ngx_resolver_ctx_t *ctx) |
933 { | |
5113
08b36f2afc3f
Upstream: fixed previous commit.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5112
diff
changeset
|
934 ngx_connection_t *c; |
1658 | 935 ngx_http_request_t *r; |
3169
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
936 ngx_http_upstream_t *u; |
1658 | 937 ngx_http_upstream_resolved_t *ur; |
938 | |
939 r = ctx->data; | |
5113
08b36f2afc3f
Upstream: fixed previous commit.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5112
diff
changeset
|
940 c = r->connection; |
1658 | 941 |
3169
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
942 u = r->upstream; |
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
943 ur = u->resolved; |
1658 | 944 |
5928
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5911
diff
changeset
|
945 ngx_http_set_log_request(c->log, r); |
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5911
diff
changeset
|
946 |
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5911
diff
changeset
|
947 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, |
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5911
diff
changeset
|
948 "http upstream resolve: \"%V?%V\"", &r->uri, &r->args); |
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5911
diff
changeset
|
949 |
1658 | 950 if (ctx->state) { |
951 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
952 "%V could not be resolved (%i: %s)", | |
953 &ctx->name, ctx->state, | |
954 ngx_resolver_strerror(ctx->state)); | |
955 | |
3169
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
956 ngx_http_upstream_finalize_request(r, u, NGX_HTTP_BAD_GATEWAY); |
5112
d3c15c7831eb
Upstream: call ngx_http_run_posted_requests() on resolve errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5104
diff
changeset
|
957 goto failed; |
1658 | 958 } |
959 | |
960 ur->naddrs = ctx->naddrs; | |
961 ur->addrs = ctx->addrs; | |
962 | |
963 #if (NGX_DEBUG) | |
964 { | |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5453
diff
changeset
|
965 u_char text[NGX_SOCKADDR_STRLEN]; |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5453
diff
changeset
|
966 ngx_str_t addr; |
1658 | 967 ngx_uint_t i; |
968 | |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5453
diff
changeset
|
969 addr.data = text; |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5453
diff
changeset
|
970 |
1658 | 971 for (i = 0; i < ctx->naddrs; i++) { |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5453
diff
changeset
|
972 addr.len = ngx_sock_ntop(ur->addrs[i].sockaddr, ur->addrs[i].socklen, |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5453
diff
changeset
|
973 text, NGX_SOCKADDR_STRLEN, 0); |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5453
diff
changeset
|
974 |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5453
diff
changeset
|
975 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5453
diff
changeset
|
976 "name was resolved to %V", &addr); |
1658 | 977 } |
978 } | |
979 #endif | |
980 | |
981 if (ngx_http_upstream_create_round_robin_peer(r, ur) != NGX_OK) { | |
3169
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
982 ngx_http_upstream_finalize_request(r, u, |
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
983 NGX_HTTP_INTERNAL_SERVER_ERROR); |
5112
d3c15c7831eb
Upstream: call ngx_http_run_posted_requests() on resolve errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5104
diff
changeset
|
984 goto failed; |
1658 | 985 } |
986 | |
987 ngx_resolve_name_done(ctx); | |
3169
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
988 ur->ctx = NULL; |
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
989 |
5885
5a042519bfe7
Upstream: limited next_upstream time and tries when resolving DNS.
Gu Feng <flygoast@126.com>
parents:
5883
diff
changeset
|
990 u->peer.start_time = ngx_current_msec; |
5a042519bfe7
Upstream: limited next_upstream time and tries when resolving DNS.
Gu Feng <flygoast@126.com>
parents:
5883
diff
changeset
|
991 |
5a042519bfe7
Upstream: limited next_upstream time and tries when resolving DNS.
Gu Feng <flygoast@126.com>
parents:
5883
diff
changeset
|
992 if (u->conf->next_upstream_tries |
5a042519bfe7
Upstream: limited next_upstream time and tries when resolving DNS.
Gu Feng <flygoast@126.com>
parents:
5883
diff
changeset
|
993 && u->peer.tries > u->conf->next_upstream_tries) |
5a042519bfe7
Upstream: limited next_upstream time and tries when resolving DNS.
Gu Feng <flygoast@126.com>
parents:
5883
diff
changeset
|
994 { |
5a042519bfe7
Upstream: limited next_upstream time and tries when resolving DNS.
Gu Feng <flygoast@126.com>
parents:
5883
diff
changeset
|
995 u->peer.tries = u->conf->next_upstream_tries; |
5a042519bfe7
Upstream: limited next_upstream time and tries when resolving DNS.
Gu Feng <flygoast@126.com>
parents:
5883
diff
changeset
|
996 } |
5a042519bfe7
Upstream: limited next_upstream time and tries when resolving DNS.
Gu Feng <flygoast@126.com>
parents:
5883
diff
changeset
|
997 |
3169
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
998 ngx_http_upstream_connect(r, u); |
5112
d3c15c7831eb
Upstream: call ngx_http_run_posted_requests() on resolve errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5104
diff
changeset
|
999 |
d3c15c7831eb
Upstream: call ngx_http_run_posted_requests() on resolve errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5104
diff
changeset
|
1000 failed: |
d3c15c7831eb
Upstream: call ngx_http_run_posted_requests() on resolve errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5104
diff
changeset
|
1001 |
5113
08b36f2afc3f
Upstream: fixed previous commit.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5112
diff
changeset
|
1002 ngx_http_run_posted_requests(c); |
1658 | 1003 } |
1004 | |
1005 | |
1006 static void | |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1007 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
|
1008 { |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1009 ngx_connection_t *c; |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1010 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
|
1011 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
|
1012 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1013 c = ev->data; |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1014 r = c->data; |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1015 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1016 u = r->upstream; |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1017 c = r->connection; |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1018 |
5928
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5911
diff
changeset
|
1019 ngx_http_set_log_request(c->log, r); |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1020 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1021 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
|
1022 "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
|
1023 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1024 if (ev->write) { |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1025 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
|
1026 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1027 } else { |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1028 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
|
1029 } |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1030 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1031 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
|
1032 } |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1033 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1034 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1035 static void |
509 | 1036 ngx_http_upstream_rd_check_broken_connection(ngx_http_request_t *r) |
1037 { | |
1038 ngx_http_upstream_check_broken_connection(r, r->connection->read); | |
1039 } | |
1040 | |
1041 | |
1042 static void | |
1043 ngx_http_upstream_wr_check_broken_connection(ngx_http_request_t *r) | |
1044 { | |
1045 ngx_http_upstream_check_broken_connection(r, r->connection->write); | |
1046 } | |
1047 | |
1048 | |
1049 static void | |
1050 ngx_http_upstream_check_broken_connection(ngx_http_request_t *r, | |
1051 ngx_event_t *ev) | |
479 | 1052 { |
1053 int n; | |
1054 char buf[1]; | |
577 | 1055 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
|
1056 ngx_int_t event; |
479 | 1057 ngx_connection_t *c; |
1058 ngx_http_upstream_t *u; | |
1059 | |
527 | 1060 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, ev->log, 0, |
1061 "http upstream check client, write event:%d, \"%V\"", | |
1062 ev->write, &r->uri); | |
479 | 1063 |
509 | 1064 c = r->connection; |
483 | 1065 u = r->upstream; |
1066 | |
583 | 1067 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
|
1068 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
|
1069 |
6ad4bba6313e
delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents:
2805
diff
changeset
|
1070 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
|
1071 |
6ad4bba6313e
delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents:
2805
diff
changeset
|
1072 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
|
1073 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
|
1074 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
|
1075 return; |
6ad4bba6313e
delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents:
2805
diff
changeset
|
1076 } |
6ad4bba6313e
delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents:
2805
diff
changeset
|
1077 } |
6ad4bba6313e
delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents:
2805
diff
changeset
|
1078 |
2757
9cc973b46af1
get a full response if the response is cacheable or storable even
Igor Sysoev <igor@sysoev.ru>
parents:
2708
diff
changeset
|
1079 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
|
1080 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
|
1081 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
|
1082 } |
2807
6ad4bba6313e
delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents:
2805
diff
changeset
|
1083 |
527 | 1084 return; |
1085 } | |
1086 | |
5121
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
5113
diff
changeset
|
1087 #if (NGX_HTTP_SPDY) |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
5113
diff
changeset
|
1088 if (r->spdy_stream) { |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
5113
diff
changeset
|
1089 return; |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
5113
diff
changeset
|
1090 } |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
5113
diff
changeset
|
1091 #endif |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
5113
diff
changeset
|
1092 |
479 | 1093 #if (NGX_HAVE_KQUEUE) |
1094 | |
1095 if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) { | |
1096 | |
1097 if (!ev->pending_eof) { | |
1098 return; | |
1099 } | |
1100 | |
1101 ev->eof = 1; | |
583 | 1102 c->error = 1; |
479 | 1103 |
1104 if (ev->kq_errno) { | |
1105 ev->error = 1; | |
1106 } | |
1107 | |
2757
9cc973b46af1
get a full response if the response is cacheable or storable even
Igor Sysoev <igor@sysoev.ru>
parents:
2708
diff
changeset
|
1108 if (!u->cacheable && u->peer.connection) { |
479 | 1109 ngx_log_error(NGX_LOG_INFO, ev->log, ev->kq_errno, |
4182 | 1110 "kevent() reported that client prematurely closed " |
527 | 1111 "connection, so upstream connection is closed too"); |
479 | 1112 ngx_http_upstream_finalize_request(r, u, |
1113 NGX_HTTP_CLIENT_CLOSED_REQUEST); | |
1114 return; | |
1115 } | |
1116 | |
1117 ngx_log_error(NGX_LOG_INFO, ev->log, ev->kq_errno, | |
4182 | 1118 "kevent() reported that client prematurely closed " |
1119 "connection"); | |
479 | 1120 |
1121 if (u->peer.connection == NULL) { | |
1122 ngx_http_upstream_finalize_request(r, u, | |
1123 NGX_HTTP_CLIENT_CLOSED_REQUEST); | |
1124 } | |
1125 | |
1126 return; | |
1127 } | |
1128 | |
1129 #endif | |
1130 | |
5373
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1131 #if (NGX_HAVE_EPOLLRDHUP) |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1132 |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1133 if ((ngx_event_flags & NGX_USE_EPOLL_EVENT) && ev->pending_eof) { |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1134 socklen_t len; |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1135 |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1136 ev->eof = 1; |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1137 c->error = 1; |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1138 |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1139 err = 0; |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1140 len = sizeof(ngx_err_t); |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1141 |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1142 /* |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1143 * BSDs and Linux return 0 and set a pending error in err |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1144 * Solaris returns -1 and sets errno |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1145 */ |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1146 |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1147 if (getsockopt(c->fd, SOL_SOCKET, SO_ERROR, (void *) &err, &len) |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1148 == -1) |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1149 { |
5557
188481078faf
Use ngx_socket_errno where appropriate.
Piotr Sikora <piotr@cloudflare.com>
parents:
5546
diff
changeset
|
1150 err = ngx_socket_errno; |
5373
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1151 } |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1152 |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1153 if (err) { |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1154 ev->error = 1; |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1155 } |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1156 |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1157 if (!u->cacheable && u->peer.connection) { |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1158 ngx_log_error(NGX_LOG_INFO, ev->log, err, |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1159 "epoll_wait() reported that client prematurely closed " |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1160 "connection, so upstream connection is closed too"); |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1161 ngx_http_upstream_finalize_request(r, u, |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1162 NGX_HTTP_CLIENT_CLOSED_REQUEST); |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1163 return; |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1164 } |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1165 |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1166 ngx_log_error(NGX_LOG_INFO, ev->log, err, |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1167 "epoll_wait() reported that client prematurely closed " |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1168 "connection"); |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1169 |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1170 if (u->peer.connection == NULL) { |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1171 ngx_http_upstream_finalize_request(r, u, |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1172 NGX_HTTP_CLIENT_CLOSED_REQUEST); |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1173 } |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1174 |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1175 return; |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1176 } |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1177 |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1178 #endif |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1179 |
479 | 1180 n = recv(c->fd, buf, 1, MSG_PEEK); |
1181 | |
1182 err = ngx_socket_errno; | |
1183 | |
1109 | 1184 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ev->log, err, |
1185 "http upstream recv(): %d", n); | |
1186 | |
479 | 1187 if (ev->write && (n >= 0 || err == NGX_EAGAIN)) { |
1188 return; | |
1189 } | |
1190 | |
1191 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
|
1192 |
6ad4bba6313e
delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents:
2805
diff
changeset
|
1193 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
|
1194 |
6ad4bba6313e
delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents:
2805
diff
changeset
|
1195 if (ngx_del_event(ev, event, 0) != NGX_OK) { |
479 | 1196 ngx_http_upstream_finalize_request(r, u, |
1197 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
1198 return; | |
1199 } | |
1200 } | |
1201 | |
1202 if (n > 0) { | |
1203 return; | |
1204 } | |
1205 | |
1206 if (n == -1) { | |
1207 if (err == NGX_EAGAIN) { | |
1208 return; | |
1209 } | |
1210 | |
1211 ev->error = 1; | |
1212 | |
483 | 1213 } else { /* n == 0 */ |
479 | 1214 err = 0; |
1215 } | |
1216 | |
529 | 1217 ev->eof = 1; |
583 | 1218 c->error = 1; |
529 | 1219 |
2757
9cc973b46af1
get a full response if the response is cacheable or storable even
Igor Sysoev <igor@sysoev.ru>
parents:
2708
diff
changeset
|
1220 if (!u->cacheable && u->peer.connection) { |
479 | 1221 ngx_log_error(NGX_LOG_INFO, ev->log, err, |
4182 | 1222 "client prematurely closed connection, " |
479 | 1223 "so upstream connection is closed too"); |
1224 ngx_http_upstream_finalize_request(r, u, | |
1225 NGX_HTTP_CLIENT_CLOSED_REQUEST); | |
1226 return; | |
1227 } | |
1228 | |
1229 ngx_log_error(NGX_LOG_INFO, ev->log, err, | |
4182 | 1230 "client prematurely closed connection"); |
479 | 1231 |
1232 if (u->peer.connection == NULL) { | |
1233 ngx_http_upstream_finalize_request(r, u, | |
1234 NGX_HTTP_CLIENT_CLOSED_REQUEST); | |
1235 } | |
1236 } | |
1237 | |
1238 | |
487 | 1239 static void |
1240 ngx_http_upstream_connect(ngx_http_request_t *r, ngx_http_upstream_t *u) | |
479 | 1241 { |
591 | 1242 ngx_int_t rc; |
665 | 1243 ngx_time_t *tp; |
591 | 1244 ngx_connection_t *c; |
479 | 1245 |
483 | 1246 r->connection->log->action = "connecting to upstream"; |
479 | 1247 |
889
a9a7e4b1a72b
the previous fix does not actually fix overflow
Igor Sysoev <igor@sysoev.ru>
parents:
888
diff
changeset
|
1248 if (u->state && u->state->response_sec) { |
665 | 1249 tp = ngx_timeofday(); |
889
a9a7e4b1a72b
the previous fix does not actually fix overflow
Igor Sysoev <igor@sysoev.ru>
parents:
888
diff
changeset
|
1250 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
|
1251 u->state->response_msec = tp->msec - u->state->response_msec; |
665 | 1252 } |
1253 | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
1254 u->state = ngx_array_push(r->upstream_states); |
665 | 1255 if (u->state == NULL) { |
1256 ngx_http_upstream_finalize_request(r, u, | |
1257 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
1258 return; | |
1259 } | |
1260 | |
1261 ngx_memzero(u->state, sizeof(ngx_http_upstream_state_t)); | |
1262 | |
1263 tp = ngx_timeofday(); | |
889
a9a7e4b1a72b
the previous fix does not actually fix overflow
Igor Sysoev <igor@sysoev.ru>
parents:
888
diff
changeset
|
1264 u->state->response_sec = tp->sec; |
a9a7e4b1a72b
the previous fix does not actually fix overflow
Igor Sysoev <igor@sysoev.ru>
parents:
888
diff
changeset
|
1265 u->state->response_msec = tp->msec; |
665 | 1266 |
479 | 1267 rc = ngx_event_connect_peer(&u->peer); |
1268 | |
1269 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
1270 "http upstream connect: %i", rc); | |
1271 | |
1272 if (rc == NGX_ERROR) { | |
1273 ngx_http_upstream_finalize_request(r, u, | |
1274 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
1275 return; | |
1276 } | |
1277 | |
1707
f3188f6eae1f
$upstream_addr did not contain last address, the bug was introduced in r1659
Igor Sysoev <igor@sysoev.ru>
parents:
1706
diff
changeset
|
1278 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
|
1279 |
543 | 1280 if (rc == NGX_BUSY) { |
1281 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "no live upstreams"); | |
1378 | 1282 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_NOLIVE); |
1283 return; | |
543 | 1284 } |
1285 | |
1378 | 1286 if (rc == NGX_DECLINED) { |
479 | 1287 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR); |
1288 return; | |
1289 } | |
1290 | |
5261
af60a210cb78
Upstream: updated list of ngx_event_connect_peer() return values.
Ruslan Ermilov <ru@nginx.com>
parents:
5231
diff
changeset
|
1291 /* rc == NGX_OK || rc == NGX_AGAIN || rc == NGX_DONE */ |
577 | 1292 |
479 | 1293 c = u->peer.connection; |
1294 | |
1295 c->data = r; | |
591 | 1296 |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1297 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
|
1298 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
|
1299 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1300 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
|
1301 u->read_event_handler = ngx_http_upstream_process_header; |
479 | 1302 |
1397
6c25a49e548a
upstream sendfile bit was overridden by r->connection->sendfile
Igor Sysoev <igor@sysoev.ru>
parents:
1378
diff
changeset
|
1303 c->sendfile &= r->connection->sendfile; |
1958 | 1304 u->output.sendfile = c->sendfile; |
479 | 1305 |
4116
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1306 if (c->pool == NULL) { |
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1307 |
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1308 /* we need separate pool here to be able to cache SSL connections */ |
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1309 |
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1310 c->pool = ngx_create_pool(128, r->connection->log); |
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1311 if (c->pool == NULL) { |
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1312 ngx_http_upstream_finalize_request(r, u, |
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1313 NGX_HTTP_INTERNAL_SERVER_ERROR); |
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1314 return; |
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1315 } |
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1316 } |
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1317 |
2847 | 1318 c->log = r->connection->log; |
4116
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1319 c->pool->log = c->log; |
2847 | 1320 c->read->log = c->log; |
1321 c->write->log = c->log; | |
479 | 1322 |
1323 /* init or reinit the ngx_output_chain() and ngx_chain_writer() contexts */ | |
1324 | |
1325 u->writer.out = NULL; | |
1326 u->writer.last = &u->writer.out; | |
1327 u->writer.connection = c; | |
1328 u->writer.limit = 0; | |
1329 | |
1330 if (u->request_sent) { | |
509 | 1331 if (ngx_http_upstream_reinit(r, u) != NGX_OK) { |
1332 ngx_http_upstream_finalize_request(r, u, | |
1333 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
1334 return; | |
1335 } | |
479 | 1336 } |
1337 | |
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
|
1338 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
|
1339 && 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
|
1340 && 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
|
1341 && 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
|
1342 { |
573 | 1343 /* |
1344 * the r->request_body->buf can be reused for one request only, | |
4572
67653855682e
Fixed spelling in multiline C comments.
Ruslan Ermilov <ru@nginx.com>
parents:
4546
diff
changeset
|
1345 * the subrequests should allocate their own temporary bufs |
573 | 1346 */ |
1347 | |
1348 u->output.free = ngx_alloc_chain_link(r->pool); | |
1349 if (u->output.free == NULL) { | |
1350 ngx_http_upstream_finalize_request(r, u, | |
1351 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
1352 return; | |
479 | 1353 } |
573 | 1354 |
1355 u->output.free->buf = r->request_body->buf; | |
1356 u->output.free->next = NULL; | |
1357 u->output.allocated = 1; | |
1358 | |
1359 r->request_body->buf->pos = r->request_body->buf->start; | |
1360 r->request_body->buf->last = r->request_body->buf->start; | |
1361 r->request_body->buf->tag = u->output.tag; | |
479 | 1362 } |
1363 | |
1364 u->request_sent = 0; | |
1365 | |
1366 if (rc == NGX_AGAIN) { | |
1367 ngx_add_timer(c->write, u->conf->connect_timeout); | |
1368 return; | |
1369 } | |
1370 | |
577 | 1371 #if (NGX_HTTP_SSL) |
1372 | |
1658 | 1373 if (u->ssl && c->ssl == NULL) { |
591 | 1374 ngx_http_upstream_ssl_init_connection(r, u, c); |
577 | 1375 return; |
1376 } | |
1377 | |
1378 #endif | |
1379 | |
479 | 1380 ngx_http_upstream_send_request(r, u); |
1381 } | |
1382 | |
1383 | |
577 | 1384 #if (NGX_HTTP_SSL) |
1385 | |
1386 static void | |
591 | 1387 ngx_http_upstream_ssl_init_connection(ngx_http_request_t *r, |
1388 ngx_http_upstream_t *u, ngx_connection_t *c) | |
1389 { | |
884 | 1390 ngx_int_t rc; |
591 | 1391 |
5305
12b750d35162
Upstream: reliably detect connection failures with SSL peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5304
diff
changeset
|
1392 if (ngx_http_upstream_test_connect(c) != NGX_OK) { |
12b750d35162
Upstream: reliably detect connection failures with SSL peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5304
diff
changeset
|
1393 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR); |
12b750d35162
Upstream: reliably detect connection failures with SSL peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5304
diff
changeset
|
1394 return; |
12b750d35162
Upstream: reliably detect connection failures with SSL peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5304
diff
changeset
|
1395 } |
12b750d35162
Upstream: reliably detect connection failures with SSL peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5304
diff
changeset
|
1396 |
591 | 1397 if (ngx_ssl_create_connection(u->conf->ssl, c, |
1398 NGX_SSL_BUFFER|NGX_SSL_CLIENT) | |
2536
a6d6d762c554
small optimization: " == NGX_ERROR" > " != NGX_OK"
Igor Sysoev <igor@sysoev.ru>
parents:
2463
diff
changeset
|
1399 != NGX_OK) |
591 | 1400 { |
1401 ngx_http_upstream_finalize_request(r, u, | |
1402 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
1403 return; | |
1404 } | |
1405 | |
1406 c->sendfile = 0; | |
619 | 1407 u->output.sendfile = 0; |
591 | 1408 |
5661
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1409 if (u->conf->ssl_server_name || u->conf->ssl_verify) { |
5660
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1410 if (ngx_http_upstream_ssl_name(r, u, c) != NGX_OK) { |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1411 ngx_http_upstream_finalize_request(r, u, |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1412 NGX_HTTP_INTERNAL_SERVER_ERROR); |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1413 return; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1414 } |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1415 } |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1416 |
2184 | 1417 if (u->conf->ssl_session_reuse) { |
1418 if (u->peer.set_session(&u->peer, u->peer.data) != NGX_OK) { | |
1419 ngx_http_upstream_finalize_request(r, u, | |
1420 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
1421 return; | |
1422 } | |
591 | 1423 } |
1424 | |
641 | 1425 r->connection->log->action = "SSL handshaking to upstream"; |
1426 | |
591 | 1427 rc = ngx_ssl_handshake(c); |
1428 | |
1429 if (rc == NGX_AGAIN) { | |
5774
9bf58a3da25b
Upstream: SSL handshake timeouts.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5770
diff
changeset
|
1430 |
9bf58a3da25b
Upstream: SSL handshake timeouts.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5770
diff
changeset
|
1431 if (!c->write->timer_set) { |
9bf58a3da25b
Upstream: SSL handshake timeouts.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5770
diff
changeset
|
1432 ngx_add_timer(c->write, u->conf->connect_timeout); |
9bf58a3da25b
Upstream: SSL handshake timeouts.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5770
diff
changeset
|
1433 } |
9bf58a3da25b
Upstream: SSL handshake timeouts.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5770
diff
changeset
|
1434 |
591 | 1435 c->ssl->handler = ngx_http_upstream_ssl_handshake; |
1436 return; | |
1437 } | |
1438 | |
1439 ngx_http_upstream_ssl_handshake(c); | |
1440 } | |
1441 | |
1442 | |
1443 static void | |
577 | 1444 ngx_http_upstream_ssl_handshake(ngx_connection_t *c) |
1445 { | |
5661
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1446 long rc; |
577 | 1447 ngx_http_request_t *r; |
1448 ngx_http_upstream_t *u; | |
1449 | |
1450 r = c->data; | |
1451 u = r->upstream; | |
1452 | |
5928
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5911
diff
changeset
|
1453 ngx_http_set_log_request(c->log, r); |
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5911
diff
changeset
|
1454 |
577 | 1455 if (c->ssl->handshaked) { |
1456 | |
5661
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1457 if (u->conf->ssl_verify) { |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1458 rc = SSL_get_verify_result(c->ssl->connection); |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1459 |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1460 if (rc != X509_V_OK) { |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1461 ngx_log_error(NGX_LOG_ERR, c->log, 0, |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1462 "upstream SSL certificate verify error: (%l:%s)", |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1463 rc, X509_verify_cert_error_string(rc)); |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1464 goto failed; |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1465 } |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1466 |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1467 if (ngx_ssl_check_host(c, &u->ssl_name) != NGX_OK) { |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1468 ngx_log_error(NGX_LOG_ERR, c->log, 0, |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1469 "upstream SSL certificate does not match \"%V\"", |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1470 &u->ssl_name); |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1471 goto failed; |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1472 } |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1473 } |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1474 |
2184 | 1475 if (u->conf->ssl_session_reuse) { |
1476 u->peer.save_session(&u->peer, u->peer.data); | |
1477 } | |
884 | 1478 |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1479 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
|
1480 c->read->handler = ngx_http_upstream_handler; |
577 | 1481 |
5340
13a5f4765887
Upstream: posted requests handling after ssl handshake errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5305
diff
changeset
|
1482 c = r->connection; |
13a5f4765887
Upstream: posted requests handling after ssl handshake errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5305
diff
changeset
|
1483 |
577 | 1484 ngx_http_upstream_send_request(r, u); |
1485 | |
5340
13a5f4765887
Upstream: posted requests handling after ssl handshake errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5305
diff
changeset
|
1486 ngx_http_run_posted_requests(c); |
577 | 1487 return; |
1488 } | |
1489 | |
5661
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1490 failed: |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1491 |
5340
13a5f4765887
Upstream: posted requests handling after ssl handshake errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5305
diff
changeset
|
1492 c = r->connection; |
13a5f4765887
Upstream: posted requests handling after ssl handshake errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5305
diff
changeset
|
1493 |
577 | 1494 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR); |
1495 | |
5340
13a5f4765887
Upstream: posted requests handling after ssl handshake errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5305
diff
changeset
|
1496 ngx_http_run_posted_requests(c); |
577 | 1497 } |
1498 | |
5660
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1499 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1500 static ngx_int_t |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1501 ngx_http_upstream_ssl_name(ngx_http_request_t *r, ngx_http_upstream_t *u, |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1502 ngx_connection_t *c) |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1503 { |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1504 u_char *p, *last; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1505 ngx_str_t name; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1506 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1507 if (u->conf->ssl_name) { |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1508 if (ngx_http_complex_value(r, u->conf->ssl_name, &name) != NGX_OK) { |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1509 return NGX_ERROR; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1510 } |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1511 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1512 } else { |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1513 name = u->ssl_name; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1514 } |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1515 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1516 if (name.len == 0) { |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1517 goto done; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1518 } |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1519 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1520 /* |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1521 * ssl name here may contain port, notably if derived from $proxy_host |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1522 * or $http_host; we have to strip it |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1523 */ |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1524 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1525 p = name.data; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1526 last = name.data + name.len; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1527 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1528 if (*p == '[') { |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1529 p = ngx_strlchr(p, last, ']'); |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1530 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1531 if (p == NULL) { |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1532 p = name.data; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1533 } |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1534 } |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1535 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1536 p = ngx_strlchr(p, last, ':'); |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1537 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1538 if (p != NULL) { |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1539 name.len = p - name.data; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1540 } |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1541 |
5661
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1542 if (!u->conf->ssl_server_name) { |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1543 goto done; |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1544 } |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1545 |
5660
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1546 #ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1547 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1548 /* as per RFC 6066, literal IPv4 and IPv6 addresses are not permitted */ |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1549 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1550 if (name.len == 0 || *name.data == '[') { |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1551 goto done; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1552 } |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1553 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1554 if (ngx_inet_addr(name.data, name.len) != INADDR_NONE) { |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1555 goto done; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1556 } |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1557 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1558 /* |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1559 * SSL_set_tlsext_host_name() needs a null-terminated string, |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1560 * hence we explicitly null-terminate name here |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1561 */ |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1562 |
5667
16405e02e612
Upstream: for ssl name, non-aligned memory allocation is enough.
Ruslan Ermilov <ru@nginx.com>
parents:
5661
diff
changeset
|
1563 p = ngx_pnalloc(r->pool, name.len + 1); |
5660
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1564 if (p == NULL) { |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1565 return NGX_ERROR; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1566 } |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1567 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1568 (void) ngx_cpystrn(p, name.data, name.len + 1); |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1569 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1570 name.data = p; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1571 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1572 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1573 "upstream SSL server name: \"%s\"", name.data); |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1574 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1575 if (SSL_set_tlsext_host_name(c->ssl->connection, name.data) == 0) { |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1576 ngx_ssl_error(NGX_LOG_ERR, r->connection->log, 0, |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1577 "SSL_set_tlsext_host_name(\"%s\") failed", name.data); |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1578 return NGX_ERROR; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1579 } |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1580 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1581 #endif |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1582 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1583 done: |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1584 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1585 u->ssl_name = name; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1586 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1587 return NGX_OK; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1588 } |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1589 |
577 | 1590 #endif |
1591 | |
1592 | |
509 | 1593 static ngx_int_t |
487 | 1594 ngx_http_upstream_reinit(ngx_http_request_t *r, ngx_http_upstream_t *u) |
479 | 1595 { |
5848
106a8bfa4f42
Upstream: fixed file buffers reinit in ngx_http_upstream_reinit().
Roman Arutyunyan <arut@nginx.com>
parents:
5832
diff
changeset
|
1596 off_t file_pos; |
479 | 1597 ngx_chain_t *cl; |
1598 | |
509 | 1599 if (u->reinit_request(r) != NGX_OK) { |
1600 return NGX_ERROR; | |
1601 } | |
1602 | |
4120
42135dd1f0ea
Upstream: keepalive flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4119
diff
changeset
|
1603 u->keepalive = 0; |
5072
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
1604 u->upgrade = 0; |
4120
42135dd1f0ea
Upstream: keepalive flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4119
diff
changeset
|
1605 |
1705 | 1606 ngx_memzero(&u->headers_in, sizeof(ngx_http_upstream_headers_in_t)); |
4117
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
1607 u->headers_in.content_length_n = -1; |
5869
fd283aa92e04
Upstream: fix $upstream_cache_last_modified variable.
Piotr Sikora <piotr@cloudflare.com>
parents:
5848
diff
changeset
|
1608 u->headers_in.last_modified_time = -1; |
1705 | 1609 |
1610 if (ngx_list_init(&u->headers_in.headers, r->pool, 8, | |
591 | 1611 sizeof(ngx_table_elt_t)) |
1612 != NGX_OK) | |
509 | 1613 { |
1614 return NGX_ERROR; | |
479 | 1615 } |
1616 | |
1617 /* reinit the request chain */ | |
577 | 1618 |
5848
106a8bfa4f42
Upstream: fixed file buffers reinit in ngx_http_upstream_reinit().
Roman Arutyunyan <arut@nginx.com>
parents:
5832
diff
changeset
|
1619 file_pos = 0; |
106a8bfa4f42
Upstream: fixed file buffers reinit in ngx_http_upstream_reinit().
Roman Arutyunyan <arut@nginx.com>
parents:
5832
diff
changeset
|
1620 |
509 | 1621 for (cl = u->request_bufs; cl; cl = cl->next) { |
479 | 1622 cl->buf->pos = cl->buf->start; |
5848
106a8bfa4f42
Upstream: fixed file buffers reinit in ngx_http_upstream_reinit().
Roman Arutyunyan <arut@nginx.com>
parents:
5832
diff
changeset
|
1623 |
106a8bfa4f42
Upstream: fixed file buffers reinit in ngx_http_upstream_reinit().
Roman Arutyunyan <arut@nginx.com>
parents:
5832
diff
changeset
|
1624 /* there is at most one file */ |
106a8bfa4f42
Upstream: fixed file buffers reinit in ngx_http_upstream_reinit().
Roman Arutyunyan <arut@nginx.com>
parents:
5832
diff
changeset
|
1625 |
106a8bfa4f42
Upstream: fixed file buffers reinit in ngx_http_upstream_reinit().
Roman Arutyunyan <arut@nginx.com>
parents:
5832
diff
changeset
|
1626 if (cl->buf->in_file) { |
106a8bfa4f42
Upstream: fixed file buffers reinit in ngx_http_upstream_reinit().
Roman Arutyunyan <arut@nginx.com>
parents:
5832
diff
changeset
|
1627 cl->buf->file_pos = file_pos; |
106a8bfa4f42
Upstream: fixed file buffers reinit in ngx_http_upstream_reinit().
Roman Arutyunyan <arut@nginx.com>
parents:
5832
diff
changeset
|
1628 file_pos = cl->buf->file_last; |
106a8bfa4f42
Upstream: fixed file buffers reinit in ngx_http_upstream_reinit().
Roman Arutyunyan <arut@nginx.com>
parents:
5832
diff
changeset
|
1629 } |
479 | 1630 } |
1631 | |
509 | 1632 /* reinit the subrequest's ngx_output_chain() context */ |
1633 | |
573 | 1634 if (r->request_body && r->request_body->temp_file |
597 | 1635 && r != r->main && u->output.buf) |
573 | 1636 { |
1637 u->output.free = ngx_alloc_chain_link(r->pool); | |
1638 if (u->output.free == NULL) { | |
1639 return NGX_ERROR; | |
509 | 1640 } |
573 | 1641 |
1642 u->output.free->buf = u->output.buf; | |
1643 u->output.free->next = NULL; | |
1644 | |
1645 u->output.buf->pos = u->output.buf->start; | |
1646 u->output.buf->last = u->output.buf->start; | |
509 | 1647 } |
479 | 1648 |
1649 u->output.buf = NULL; | |
1650 u->output.in = NULL; | |
1651 u->output.busy = NULL; | |
577 | 1652 |
581 | 1653 /* reinit u->buffer */ |
577 | 1654 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1655 u->buffer.pos = u->buffer.start; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1656 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1657 #if (NGX_HTTP_CACHE) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1658 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1659 if (r->cache) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1660 u->buffer.pos += r->cache->header_start; |
479 | 1661 } |
509 | 1662 |
479 | 1663 #endif |
1664 | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1665 u->buffer.last = u->buffer.pos; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1666 |
509 | 1667 return NGX_OK; |
479 | 1668 } |
1669 | |
1670 | |
487 | 1671 static void |
1672 ngx_http_upstream_send_request(ngx_http_request_t *r, ngx_http_upstream_t *u) | |
479 | 1673 { |
1153
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
1674 ngx_int_t rc; |
483 | 1675 ngx_connection_t *c; |
577 | 1676 |
479 | 1677 c = u->peer.connection; |
1678 | |
1679 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
1680 "http upstream send request"); | |
1681 | |
1153
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
1682 if (!u->request_sent && ngx_http_upstream_test_connect(c) != NGX_OK) { |
1166 | 1683 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
|
1684 return; |
479 | 1685 } |
1686 | |
483 | 1687 c->log->action = "sending request to upstream"; |
479 | 1688 |
509 | 1689 rc = ngx_output_chain(&u->output, u->request_sent ? NULL : u->request_bufs); |
479 | 1690 |
1691 u->request_sent = 1; | |
1692 | |
1693 if (rc == NGX_ERROR) { | |
1694 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR); | |
1695 return; | |
1696 } | |
1697 | |
1698 if (c->write->timer_set) { | |
1699 ngx_del_timer(c->write); | |
1700 } | |
1701 | |
1702 if (rc == NGX_AGAIN) { | |
1703 ngx_add_timer(c->write, u->conf->send_timeout); | |
1704 | |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1705 if (ngx_handle_write_event(c->write, u->conf->send_lowat) != NGX_OK) { |
479 | 1706 ngx_http_upstream_finalize_request(r, u, |
1707 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
1708 return; | |
1709 } | |
1710 | |
1711 return; | |
1712 } | |
1713 | |
1714 /* rc == NGX_OK */ | |
1715 | |
1716 if (c->tcp_nopush == NGX_TCP_NOPUSH_SET) { | |
1717 if (ngx_tcp_push(c->fd) == NGX_ERROR) { | |
1718 ngx_log_error(NGX_LOG_CRIT, c->log, ngx_socket_errno, | |
1719 ngx_tcp_push_n " failed"); | |
1720 ngx_http_upstream_finalize_request(r, u, | |
1721 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
577 | 1722 return; |
479 | 1723 } |
1724 | |
1725 c->tcp_nopush = NGX_TCP_NOPUSH_UNSET; | |
1726 } | |
577 | 1727 |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1728 u->write_event_handler = ngx_http_upstream_dummy_handler; |
479 | 1729 |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1730 if (ngx_handle_write_event(c->write, 0) != NGX_OK) { |
479 | 1731 ngx_http_upstream_finalize_request(r, u, |
1732 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
1733 return; | |
1734 } | |
5745
9d3a9c45fc43
Upstream: fixed handling of write event after sending request.
Valentin Bartenev <vbart@nginx.com>
parents:
5738
diff
changeset
|
1735 |
9d3a9c45fc43
Upstream: fixed handling of write event after sending request.
Valentin Bartenev <vbart@nginx.com>
parents:
5738
diff
changeset
|
1736 ngx_add_timer(c->read, u->conf->read_timeout); |
9d3a9c45fc43
Upstream: fixed handling of write event after sending request.
Valentin Bartenev <vbart@nginx.com>
parents:
5738
diff
changeset
|
1737 |
9d3a9c45fc43
Upstream: fixed handling of write event after sending request.
Valentin Bartenev <vbart@nginx.com>
parents:
5738
diff
changeset
|
1738 if (c->read->ready) { |
9d3a9c45fc43
Upstream: fixed handling of write event after sending request.
Valentin Bartenev <vbart@nginx.com>
parents:
5738
diff
changeset
|
1739 ngx_http_upstream_process_header(r, u); |
9d3a9c45fc43
Upstream: fixed handling of write event after sending request.
Valentin Bartenev <vbart@nginx.com>
parents:
5738
diff
changeset
|
1740 return; |
9d3a9c45fc43
Upstream: fixed handling of write event after sending request.
Valentin Bartenev <vbart@nginx.com>
parents:
5738
diff
changeset
|
1741 } |
479 | 1742 } |
1743 | |
1744 | |
487 | 1745 static void |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1746 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
|
1747 ngx_http_upstream_t *u) |
479 | 1748 { |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1749 ngx_connection_t *c; |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1750 |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1751 c = u->peer.connection; |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1752 |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1753 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
479 | 1754 "http upstream send request handler"); |
1755 | |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1756 if (c->write->timedout) { |
479 | 1757 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_TIMEOUT); |
1758 return; | |
1759 } | |
1760 | |
591 | 1761 #if (NGX_HTTP_SSL) |
1762 | |
1658 | 1763 if (u->ssl && c->ssl == NULL) { |
591 | 1764 ngx_http_upstream_ssl_init_connection(r, u, c); |
1765 return; | |
1766 } | |
1767 | |
1768 #endif | |
1769 | |
651 | 1770 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
|
1771 u->write_event_handler = ngx_http_upstream_dummy_handler; |
651 | 1772 |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1773 (void) ngx_handle_write_event(c->write, 0); |
651 | 1774 |
1775 return; | |
1776 } | |
1777 | |
479 | 1778 ngx_http_upstream_send_request(r, u); |
1779 } | |
1780 | |
1781 | |
487 | 1782 static void |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1783 ngx_http_upstream_process_header(ngx_http_request_t *r, ngx_http_upstream_t *u) |
479 | 1784 { |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1785 ssize_t n; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1786 ngx_int_t rc; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1787 ngx_connection_t *c; |
479 | 1788 |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1789 c = u->peer.connection; |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1790 |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1791 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, |
483 | 1792 "http upstream process header"); |
479 | 1793 |
483 | 1794 c->log->action = "reading response header from upstream"; |
479 | 1795 |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1796 if (c->read->timedout) { |
479 | 1797 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_TIMEOUT); |
1798 return; | |
1799 } | |
577 | 1800 |
1153
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
1801 if (!u->request_sent && ngx_http_upstream_test_connect(c) != NGX_OK) { |
1166 | 1802 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
|
1803 return; |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
1804 } |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
1805 |
581 | 1806 if (u->buffer.start == NULL) { |
1807 u->buffer.start = ngx_palloc(r->pool, u->conf->buffer_size); | |
1808 if (u->buffer.start == NULL) { | |
479 | 1809 ngx_http_upstream_finalize_request(r, u, |
1810 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
1811 return; | |
1812 } | |
1813 | |
581 | 1814 u->buffer.pos = u->buffer.start; |
1815 u->buffer.last = u->buffer.start; | |
1816 u->buffer.end = u->buffer.start + u->conf->buffer_size; | |
1817 u->buffer.temporary = 1; | |
1818 | |
1819 u->buffer.tag = u->output.tag; | |
479 | 1820 |
1705 | 1821 if (ngx_list_init(&u->headers_in.headers, r->pool, 8, |
581 | 1822 sizeof(ngx_table_elt_t)) |
1823 != NGX_OK) | |
509 | 1824 { |
1825 ngx_http_upstream_finalize_request(r, u, | |
1826 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
1827 return; | |
1828 } | |
1829 | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1830 #if (NGX_HTTP_CACHE) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1831 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1832 if (r->cache) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1833 u->buffer.pos += r->cache->header_start; |
581 | 1834 u->buffer.last = u->buffer.pos; |
479 | 1835 } |
1836 #endif | |
1837 } | |
1838 | |
2360
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1839 for ( ;; ) { |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1840 |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1841 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
|
1842 |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1843 if (n == NGX_AGAIN) { |
479 | 1844 #if 0 |
2360
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1845 ngx_add_timer(rev, u->read_timeout); |
479 | 1846 #endif |
1847 | |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1848 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
|
1849 ngx_http_upstream_finalize_request(r, u, |
479 | 1850 NGX_HTTP_INTERNAL_SERVER_ERROR); |
2360
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1851 return; |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1852 } |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1853 |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1854 return; |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1855 } |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1856 |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1857 if (n == 0) { |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1858 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
|
1859 "upstream prematurely closed connection"); |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1860 } |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1861 |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1862 if (n == NGX_ERROR || n == 0) { |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1863 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR); |
479 | 1864 return; |
1865 } | |
1866 | |
2360
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1867 u->buffer.last += n; |
479 | 1868 |
1869 #if 0 | |
2360
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1870 u->valid_header_in = 0; |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1871 |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1872 u->peer.cached = 0; |
479 | 1873 #endif |
1874 | |
2360
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1875 rc = u->process_header(r); |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1876 |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1877 if (rc == NGX_AGAIN) { |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1878 |
4460
6299d1c4dbb4
Upstream: fixed "too big header" check.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
1879 if (u->buffer.last == u->buffer.end) { |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1880 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
|
1881 "upstream sent too big header"); |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1882 |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1883 ngx_http_upstream_next(r, u, |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1884 NGX_HTTP_UPSTREAM_FT_INVALID_HEADER); |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1885 return; |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1886 } |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1887 |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1888 continue; |
479 | 1889 } |
1890 | |
2360
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
1891 break; |
479 | 1892 } |
1893 | |
1894 if (rc == NGX_HTTP_UPSTREAM_INVALID_HEADER) { | |
1895 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_INVALID_HEADER); | |
1896 return; | |
1897 } | |
1898 | |
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
|
1899 if (rc == NGX_ERROR) { |
479 | 1900 ngx_http_upstream_finalize_request(r, u, |
1901 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
1902 return; | |
1903 } | |
1904 | |
1905 /* rc == NGX_OK */ | |
1906 | |
5209
07e515e65984
Upstream: allow to intercept responses with status 300.
Ruslan Ermilov <ru@nginx.com>
parents:
5169
diff
changeset
|
1907 if (u->headers_in.status_n >= NGX_HTTP_SPECIAL_RESPONSE) { |
2268
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
1908 |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
1909 if (ngx_http_upstream_test_next(r, u) == NGX_OK) { |
509 | 1910 return; |
1911 } | |
1912 | |
2267
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
1913 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
|
1914 return; |
487 | 1915 } |
1916 } | |
1917 | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1918 if (ngx_http_upstream_process_headers(r, u) != NGX_OK) { |
515 | 1919 return; |
1920 } | |
1921 | |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1922 if (!r->subrequest_in_memory) { |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1923 ngx_http_upstream_send_response(r, u); |
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 /* subrequest content in memory */ |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1928 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1929 if (u->input_filter == NULL) { |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1930 u->input_filter_init = ngx_http_upstream_non_buffered_filter_init; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1931 u->input_filter = ngx_http_upstream_non_buffered_filter; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1932 u->input_filter_ctx = r; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1933 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1934 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1935 if (u->input_filter_init(u->input_filter_ctx) == NGX_ERROR) { |
5294
d44c3b36c53f
Upstream: consistent error handling after u->input_filter_init().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5293
diff
changeset
|
1936 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1937 return; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1938 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1939 |
2308
3f98400e31e9
memcached response was stored in variable with END
Igor Sysoev <igor@sysoev.ru>
parents:
2285
diff
changeset
|
1940 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
|
1941 |
3f98400e31e9
memcached response was stored in variable with END
Igor Sysoev <igor@sysoev.ru>
parents:
2285
diff
changeset
|
1942 if (n) { |
5216
4a40163772a1
Upstream: made the assignment more obvious.
Ruslan Ermilov <ru@nginx.com>
parents:
5209
diff
changeset
|
1943 u->buffer.last = u->buffer.pos; |
2308
3f98400e31e9
memcached response was stored in variable with END
Igor Sysoev <igor@sysoev.ru>
parents:
2285
diff
changeset
|
1944 |
2402 | 1945 u->state->response_length += n; |
1946 | |
2308
3f98400e31e9
memcached response was stored in variable with END
Igor Sysoev <igor@sysoev.ru>
parents:
2285
diff
changeset
|
1947 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
|
1948 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1949 return; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1950 } |
5217
ddba4e308ecc
Upstream: slightly optimized ngx_http_upstream_process_header().
Ruslan Ermilov <ru@nginx.com>
parents:
5216
diff
changeset
|
1951 } |
ddba4e308ecc
Upstream: slightly optimized ngx_http_upstream_process_header().
Ruslan Ermilov <ru@nginx.com>
parents:
5216
diff
changeset
|
1952 |
ddba4e308ecc
Upstream: slightly optimized ngx_http_upstream_process_header().
Ruslan Ermilov <ru@nginx.com>
parents:
5216
diff
changeset
|
1953 if (u->length == 0) { |
ddba4e308ecc
Upstream: slightly optimized ngx_http_upstream_process_header().
Ruslan Ermilov <ru@nginx.com>
parents:
5216
diff
changeset
|
1954 ngx_http_upstream_finalize_request(r, u, 0); |
ddba4e308ecc
Upstream: slightly optimized ngx_http_upstream_process_header().
Ruslan Ermilov <ru@nginx.com>
parents:
5216
diff
changeset
|
1955 return; |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1956 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1957 |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1958 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
|
1959 |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1960 ngx_http_upstream_process_body_in_memory(r, u); |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1961 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1962 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
1963 |
1153
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
1964 static ngx_int_t |
2268
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
1965 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
|
1966 { |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
1967 ngx_uint_t status; |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
1968 ngx_http_upstream_next_t *un; |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
1969 |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
1970 status = u->headers_in.status_n; |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
1971 |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
1972 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
|
1973 |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
1974 if (status != un->status) { |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
1975 continue; |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
1976 } |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
1977 |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
1978 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
|
1979 ngx_http_upstream_next(r, u, un->mask); |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
1980 return NGX_OK; |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
1981 } |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
1982 |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
1983 #if (NGX_HTTP_CACHE) |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
1984 |
2952 | 1985 if (u->cache_status == NGX_HTTP_CACHE_EXPIRED |
1986 && (u->conf->cache_use_stale & un->mask)) | |
1987 { | |
2824
d106509491b5
fix building --without-http-cache
Igor Sysoev <igor@sysoev.ru>
parents:
2807
diff
changeset
|
1988 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
|
1989 |
60551422e150
reinit proxy/fastcgi header parser before ngx_http_upstream_cache_send()
Igor Sysoev <igor@sysoev.ru>
parents:
2804
diff
changeset
|
1990 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
|
1991 |
60551422e150
reinit proxy/fastcgi header parser before ngx_http_upstream_cache_send()
Igor Sysoev <igor@sysoev.ru>
parents:
2804
diff
changeset
|
1992 if (rc == NGX_OK) { |
2952 | 1993 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
|
1994 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
|
1995 } |
60551422e150
reinit proxy/fastcgi header parser before ngx_http_upstream_cache_send()
Igor Sysoev <igor@sysoev.ru>
parents:
2804
diff
changeset
|
1996 |
60551422e150
reinit proxy/fastcgi header parser before ngx_http_upstream_cache_send()
Igor Sysoev <igor@sysoev.ru>
parents:
2804
diff
changeset
|
1997 ngx_http_upstream_finalize_request(r, u, rc); |
2268
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
1998 return NGX_OK; |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
1999 } |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2000 |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2001 #endif |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2002 } |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2003 |
5441
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2004 #if (NGX_HTTP_CACHE) |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2005 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2006 if (status == NGX_HTTP_NOT_MODIFIED |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2007 && u->cache_status == NGX_HTTP_CACHE_EXPIRED |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2008 && u->conf->cache_revalidate) |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2009 { |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2010 time_t now, valid; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2011 ngx_int_t rc; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2012 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2013 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2014 "http upstream not modified"); |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2015 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2016 now = ngx_time(); |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2017 valid = r->cache->valid_sec; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2018 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2019 rc = u->reinit_request(r); |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2020 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2021 if (rc != NGX_OK) { |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2022 ngx_http_upstream_finalize_request(r, u, rc); |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2023 return NGX_OK; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2024 } |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2025 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2026 u->cache_status = NGX_HTTP_CACHE_REVALIDATED; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2027 rc = ngx_http_upstream_cache_send(r, u); |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2028 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2029 if (valid == 0) { |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2030 valid = r->cache->valid_sec; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2031 } |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2032 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2033 if (valid == 0) { |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2034 valid = ngx_http_file_cache_valid(u->conf->cache_valid, |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2035 u->headers_in.status_n); |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2036 if (valid) { |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2037 valid = now + valid; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2038 } |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2039 } |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2040 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2041 if (valid) { |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2042 r->cache->valid_sec = valid; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2043 r->cache->date = now; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2044 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2045 ngx_http_file_cache_update_header(r); |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2046 } |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2047 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2048 ngx_http_upstream_finalize_request(r, u, rc); |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2049 return NGX_OK; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2050 } |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2051 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2052 #endif |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2053 |
2268
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2054 return NGX_DECLINED; |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2055 } |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2056 |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2057 |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2058 static ngx_int_t |
2267
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2059 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
|
2060 ngx_http_upstream_t *u) |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2061 { |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2062 ngx_int_t status; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2063 ngx_uint_t i; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2064 ngx_table_elt_t *h; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2065 ngx_http_err_page_t *err_page; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2066 ngx_http_core_loc_conf_t *clcf; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2067 |
2441
0c117a89f399
in miss case memcached module returned END instead of default 404 page body
Igor Sysoev <igor@sysoev.ru>
parents:
2422
diff
changeset
|
2068 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
|
2069 |
0c117a89f399
in miss case memcached module returned END instead of default 404 page body
Igor Sysoev <igor@sysoev.ru>
parents:
2422
diff
changeset
|
2070 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
|
2071 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
|
2072 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
|
2073 } |
0c117a89f399
in miss case memcached module returned END instead of default 404 page body
Igor Sysoev <igor@sysoev.ru>
parents:
2422
diff
changeset
|
2074 |
2267
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2075 if (!u->conf->intercept_errors) { |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2076 return NGX_DECLINED; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2077 } |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2078 |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2079 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
|
2080 |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2081 if (clcf->error_pages == NULL) { |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2082 return NGX_DECLINED; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2083 } |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2084 |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2085 err_page = clcf->error_pages->elts; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2086 for (i = 0; i < clcf->error_pages->nelts; i++) { |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2087 |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2088 if (err_page[i].status == status) { |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2089 |
2953
aa12525236da
fix segfault if there is error_page 401, proxy_intercept_errors is on
Igor Sysoev <igor@sysoev.ru>
parents:
2952
diff
changeset
|
2090 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
|
2091 && 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
|
2092 { |
2267
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2093 h = ngx_list_push(&r->headers_out.headers); |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2094 |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2095 if (h == NULL) { |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2096 ngx_http_upstream_finalize_request(r, u, |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2097 NGX_HTTP_INTERNAL_SERVER_ERROR); |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2098 return NGX_OK; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2099 } |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2100 |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2101 *h = *u->headers_in.www_authenticate; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2102 |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2103 r->headers_out.www_authenticate = h; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2104 } |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2105 |
3706
ea908f6ae499
an intercepted error code was not cached
Igor Sysoev <igor@sysoev.ru>
parents:
3705
diff
changeset
|
2106 #if (NGX_HTTP_CACHE) |
ea908f6ae499
an intercepted error code was not cached
Igor Sysoev <igor@sysoev.ru>
parents:
3705
diff
changeset
|
2107 |
3709
64777690c697
fix r3707: cache node should be freed be a response is not cached
Igor Sysoev <igor@sysoev.ru>
parents:
3708
diff
changeset
|
2108 if (r->cache) { |
3706
ea908f6ae499
an intercepted error code was not cached
Igor Sysoev <igor@sysoev.ru>
parents:
3705
diff
changeset
|
2109 time_t valid; |
ea908f6ae499
an intercepted error code was not cached
Igor Sysoev <igor@sysoev.ru>
parents:
3705
diff
changeset
|
2110 |
ea908f6ae499
an intercepted error code was not cached
Igor Sysoev <igor@sysoev.ru>
parents:
3705
diff
changeset
|
2111 valid = ngx_http_file_cache_valid(u->conf->cache_valid, status); |
ea908f6ae499
an intercepted error code was not cached
Igor Sysoev <igor@sysoev.ru>
parents:
3705
diff
changeset
|
2112 |
ea908f6ae499
an intercepted error code was not cached
Igor Sysoev <igor@sysoev.ru>
parents:
3705
diff
changeset
|
2113 if (valid) { |
ea908f6ae499
an intercepted error code was not cached
Igor Sysoev <igor@sysoev.ru>
parents:
3705
diff
changeset
|
2114 r->cache->valid_sec = ngx_time() + valid; |
ea908f6ae499
an intercepted error code was not cached
Igor Sysoev <igor@sysoev.ru>
parents:
3705
diff
changeset
|
2115 r->cache->error = status; |
ea908f6ae499
an intercepted error code was not cached
Igor Sysoev <igor@sysoev.ru>
parents:
3705
diff
changeset
|
2116 } |
ea908f6ae499
an intercepted error code was not cached
Igor Sysoev <igor@sysoev.ru>
parents:
3705
diff
changeset
|
2117 |
3711
ce6ba077c270
several changes in cache cleanup handling:
Igor Sysoev <igor@sysoev.ru>
parents:
3709
diff
changeset
|
2118 ngx_http_file_cache_free(r->cache, u->pipe->temp_file); |
3706
ea908f6ae499
an intercepted error code was not cached
Igor Sysoev <igor@sysoev.ru>
parents:
3705
diff
changeset
|
2119 } |
ea908f6ae499
an intercepted error code was not cached
Igor Sysoev <igor@sysoev.ru>
parents:
3705
diff
changeset
|
2120 #endif |
2267
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2121 ngx_http_upstream_finalize_request(r, u, status); |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2122 |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2123 return NGX_OK; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2124 } |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2125 } |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2126 |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2127 return NGX_DECLINED; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2128 } |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2129 |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2130 |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2131 static ngx_int_t |
1153
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2132 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
|
2133 { |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2134 int err; |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2135 socklen_t len; |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2136 |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2137 #if (NGX_HAVE_KQUEUE) |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2138 |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2139 if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) { |
4915
e62219793beb
Upstream: better detection of connect() failures with kqueue.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4895
diff
changeset
|
2140 if (c->write->pending_eof || c->read->pending_eof) { |
e62219793beb
Upstream: better detection of connect() failures with kqueue.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4895
diff
changeset
|
2141 if (c->write->pending_eof) { |
e62219793beb
Upstream: better detection of connect() failures with kqueue.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4895
diff
changeset
|
2142 err = c->write->kq_errno; |
e62219793beb
Upstream: better detection of connect() failures with kqueue.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4895
diff
changeset
|
2143 |
e62219793beb
Upstream: better detection of connect() failures with kqueue.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4895
diff
changeset
|
2144 } else { |
e62219793beb
Upstream: better detection of connect() failures with kqueue.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4895
diff
changeset
|
2145 err = c->read->kq_errno; |
e62219793beb
Upstream: better detection of connect() failures with kqueue.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4895
diff
changeset
|
2146 } |
e62219793beb
Upstream: better detection of connect() failures with kqueue.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4895
diff
changeset
|
2147 |
1469
0a269c464eaf
connection error should be logged with "connecting to upstream" action,
Igor Sysoev <igor@sysoev.ru>
parents:
1468
diff
changeset
|
2148 c->log->action = "connecting to upstream"; |
4916
79c8e87b1fcb
Trailing whitespace fix.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4915
diff
changeset
|
2149 (void) ngx_connection_error(c, err, |
1166 | 2150 "kevent() reported that connect() failed"); |
2151 return NGX_ERROR; | |
2152 } | |
1153
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2153 |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2154 } else |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2155 #endif |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2156 { |
1166 | 2157 err = 0; |
2158 len = sizeof(int); | |
2159 | |
2160 /* | |
2161 * BSDs and Linux return 0 and set a pending error in err | |
2162 * Solaris returns -1 and sets errno | |
2163 */ | |
2164 | |
2165 if (getsockopt(c->fd, SOL_SOCKET, SO_ERROR, (void *) &err, &len) | |
2166 == -1) | |
2167 { | |
5557
188481078faf
Use ngx_socket_errno where appropriate.
Piotr Sikora <piotr@cloudflare.com>
parents:
5546
diff
changeset
|
2168 err = ngx_socket_errno; |
1166 | 2169 } |
2170 | |
2171 if (err) { | |
1469
0a269c464eaf
connection error should be logged with "connecting to upstream" action,
Igor Sysoev <igor@sysoev.ru>
parents:
1468
diff
changeset
|
2172 c->log->action = "connecting to upstream"; |
1166 | 2173 (void) ngx_connection_error(c, err, "connect() failed"); |
2174 return NGX_ERROR; | |
2175 } | |
1153
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2176 } |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2177 |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2178 return NGX_OK; |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2179 } |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2180 |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2181 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2182 static ngx_int_t |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2183 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
|
2184 { |
5489
6d357b2a9d6e
Upstream: keep $upstream_http_x_accel_redirect intact.
Ruslan Ermilov <ru@nginx.com>
parents:
5477
diff
changeset
|
2185 ngx_str_t uri, args; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2186 ngx_uint_t i, flags; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2187 ngx_list_part_t *part; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2188 ngx_table_elt_t *h; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2189 ngx_http_upstream_header_t *hh; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2190 ngx_http_upstream_main_conf_t *umcf; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2191 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2192 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
|
2193 |
2786
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
2194 if (u->headers_in.x_accel_redirect |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
2195 && !(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
|
2196 { |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2197 ngx_http_upstream_finalize_request(r, u, NGX_DECLINED); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2198 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2199 part = &u->headers_in.headers.part; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2200 h = part->elts; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2201 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2202 for (i = 0; /* void */; i++) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2203 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2204 if (i >= part->nelts) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2205 if (part->next == NULL) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2206 break; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2207 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2208 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2209 part = part->next; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2210 h = part->elts; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2211 i = 0; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2212 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2213 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2214 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
|
2215 h[i].lowcase_key, h[i].key.len); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2216 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2217 if (hh && hh->redirect) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2218 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
|
2219 ngx_http_finalize_request(r, |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2220 NGX_HTTP_INTERNAL_SERVER_ERROR); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2221 return NGX_DONE; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2222 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2223 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2224 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2225 |
5489
6d357b2a9d6e
Upstream: keep $upstream_http_x_accel_redirect intact.
Ruslan Ermilov <ru@nginx.com>
parents:
5477
diff
changeset
|
2226 uri = u->headers_in.x_accel_redirect->value; |
5901
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2227 |
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2228 if (uri.data[0] == '@') { |
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2229 ngx_http_named_location(r, &uri); |
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2230 |
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2231 } else { |
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2232 ngx_str_null(&args); |
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2233 flags = NGX_HTTP_LOG_UNSAFE; |
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2234 |
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2235 if (ngx_http_parse_unsafe_uri(r, &uri, &args, &flags) != NGX_OK) { |
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2236 ngx_http_finalize_request(r, NGX_HTTP_NOT_FOUND); |
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2237 return NGX_DONE; |
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2238 } |
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2239 |
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2240 if (r->method != NGX_HTTP_HEAD) { |
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2241 r->method = NGX_HTTP_GET; |
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2242 } |
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2243 |
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2244 ngx_http_internal_redirect(r, &uri, &args); |
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2245 } |
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2246 |
3120
40b8b398dbbc
fix request counter for X-Accel-Redirect, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3112
diff
changeset
|
2247 ngx_http_finalize_request(r, NGX_DONE); |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2248 return NGX_DONE; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2249 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2250 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2251 part = &u->headers_in.headers.part; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2252 h = part->elts; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2253 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2254 for (i = 0; /* void */; i++) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2255 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2256 if (i >= part->nelts) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2257 if (part->next == NULL) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2258 break; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2259 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2260 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2261 part = part->next; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2262 h = part->elts; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2263 i = 0; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2264 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2265 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2266 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
|
2267 h[i].lowcase_key, h[i].key.len)) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2268 { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2269 continue; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2270 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2271 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2272 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
|
2273 h[i].lowcase_key, h[i].key.len); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2274 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2275 if (hh) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2276 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
|
2277 ngx_http_upstream_finalize_request(r, u, |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2278 NGX_HTTP_INTERNAL_SERVER_ERROR); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2279 return NGX_DONE; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2280 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2281 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2282 continue; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2283 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2284 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2285 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
|
2286 ngx_http_upstream_finalize_request(r, u, |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2287 NGX_HTTP_INTERNAL_SERVER_ERROR); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2288 return NGX_DONE; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2289 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2290 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2291 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2292 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
|
2293 r->headers_out.server->hash = 0; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2294 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2295 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2296 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
|
2297 r->headers_out.date->hash = 0; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2298 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2299 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2300 r->headers_out.status = u->headers_in.status_n; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2301 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
|
2302 |
4117
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
2303 r->headers_out.content_length_n = u->headers_in.content_length_n; |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
2304 |
5735
5fb1e57c758a
Entity tags: explicit flag to skip not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5732
diff
changeset
|
2305 r->disable_not_modified = !u->cacheable; |
5fb1e57c758a
Entity tags: explicit flag to skip not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5732
diff
changeset
|
2306 |
5874
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
2307 if (u->conf->force_ranges) { |
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
2308 r->allow_ranges = 1; |
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
2309 r->single_range = 1; |
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
2310 |
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
2311 #if (NGX_HTTP_CACHE) |
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
2312 if (r->cached) { |
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
2313 r->single_range = 0; |
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
2314 } |
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
2315 #endif |
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
2316 } |
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
2317 |
5300
f538a67c9f77
Upstream: u->length now defaults to -1 (API change).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5299
diff
changeset
|
2318 u->length = -1; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2319 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2320 return NGX_OK; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2321 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2322 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2323 |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2324 static void |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2325 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
|
2326 ngx_http_upstream_t *u) |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2327 { |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2328 size_t size; |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2329 ssize_t n; |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2330 ngx_buf_t *b; |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2331 ngx_event_t *rev; |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2332 ngx_connection_t *c; |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2333 |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2334 c = u->peer.connection; |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2335 rev = c->read; |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2336 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2337 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2338 "http upstream process body on memory"); |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2339 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2340 if (rev->timedout) { |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2341 ngx_connection_error(c, NGX_ETIMEDOUT, "upstream timed out"); |
5296
1ccdda1f37f3
Upstream: NGX_HTTP_GATEWAY_TIME_OUT after upstream timeouts.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5295
diff
changeset
|
2342 ngx_http_upstream_finalize_request(r, u, NGX_HTTP_GATEWAY_TIME_OUT); |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2343 return; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2344 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2345 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2346 b = &u->buffer; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2347 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2348 for ( ;; ) { |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2349 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2350 size = b->end - b->last; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2351 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2352 if (size == 0) { |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2353 ngx_log_error(NGX_LOG_ALERT, c->log, 0, |
3708 | 2354 "upstream buffer is too small to read response"); |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2355 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2356 return; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2357 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2358 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2359 n = c->recv(c, b->last, size); |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2360 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2361 if (n == NGX_AGAIN) { |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2362 break; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2363 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2364 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2365 if (n == 0 || n == NGX_ERROR) { |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2366 ngx_http_upstream_finalize_request(r, u, n); |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2367 return; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2368 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2369 |
2402 | 2370 u->state->response_length += n; |
2371 | |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2372 if (u->input_filter(u->input_filter_ctx, n) == NGX_ERROR) { |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2373 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2374 return; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2375 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2376 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2377 if (!rev->ready) { |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2378 break; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2379 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2380 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2381 |
4120
42135dd1f0ea
Upstream: keepalive flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4119
diff
changeset
|
2382 if (u->length == 0) { |
42135dd1f0ea
Upstream: keepalive flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4119
diff
changeset
|
2383 ngx_http_upstream_finalize_request(r, u, 0); |
42135dd1f0ea
Upstream: keepalive flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4119
diff
changeset
|
2384 return; |
42135dd1f0ea
Upstream: keepalive flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4119
diff
changeset
|
2385 } |
42135dd1f0ea
Upstream: keepalive flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4119
diff
changeset
|
2386 |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2387 if (ngx_handle_read_event(rev, 0) != NGX_OK) { |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2388 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2389 return; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2390 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2391 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2392 if (rev->active) { |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2393 ngx_add_timer(rev, u->conf->read_timeout); |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2394 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2395 } else if (rev->timer_set) { |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2396 ngx_del_timer(rev); |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2397 } |
681 | 2398 } |
2399 | |
2400 | |
2401 static void | |
2402 ngx_http_upstream_send_response(ngx_http_request_t *r, ngx_http_upstream_t *u) | |
2403 { | |
2404 int tcp_nodelay; | |
2402 | 2405 ssize_t n; |
681 | 2406 ngx_int_t rc; |
2407 ngx_event_pipe_t *p; | |
2408 ngx_connection_t *c; | |
2409 ngx_http_core_loc_conf_t *clcf; | |
2410 | |
509 | 2411 rc = ngx_http_send_header(r); |
479 | 2412 |
2701 | 2413 if (rc == NGX_ERROR || rc > NGX_OK || r->post_action) { |
485 | 2414 ngx_http_upstream_finalize_request(r, u, rc); |
479 | 2415 return; |
2416 } | |
2417 | |
5353
1608b1135a1d
Upstream: setting u->header_sent before ngx_http_upstream_upgrade().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5340
diff
changeset
|
2418 u->header_sent = 1; |
1608b1135a1d
Upstream: setting u->header_sent before ngx_http_upstream_upgrade().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5340
diff
changeset
|
2419 |
5072
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2420 if (u->upgrade) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2421 ngx_http_upstream_upgrade(r, u); |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2422 return; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2423 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2424 |
2704
ac1e2e199c9f
shutdown client connection for cacheable header only responses
Igor Sysoev <igor@sysoev.ru>
parents:
2703
diff
changeset
|
2425 c = r->connection; |
ac1e2e199c9f
shutdown client connection for cacheable header only responses
Igor Sysoev <igor@sysoev.ru>
parents:
2703
diff
changeset
|
2426 |
2701 | 2427 if (r->header_only) { |
2704
ac1e2e199c9f
shutdown client connection for cacheable header only responses
Igor Sysoev <igor@sysoev.ru>
parents:
2703
diff
changeset
|
2428 |
5746
35990c69b3ac
Upstream: p->downstream_error instead of closing connection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5745
diff
changeset
|
2429 if (!u->buffering) { |
2701 | 2430 ngx_http_upstream_finalize_request(r, u, rc); |
2431 return; | |
2432 } | |
5746
35990c69b3ac
Upstream: p->downstream_error instead of closing connection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5745
diff
changeset
|
2433 |
35990c69b3ac
Upstream: p->downstream_error instead of closing connection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5745
diff
changeset
|
2434 if (!u->cacheable && !u->store) { |
35990c69b3ac
Upstream: p->downstream_error instead of closing connection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5745
diff
changeset
|
2435 ngx_http_upstream_finalize_request(r, u, rc); |
35990c69b3ac
Upstream: p->downstream_error instead of closing connection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5745
diff
changeset
|
2436 return; |
35990c69b3ac
Upstream: p->downstream_error instead of closing connection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5745
diff
changeset
|
2437 } |
35990c69b3ac
Upstream: p->downstream_error instead of closing connection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5745
diff
changeset
|
2438 |
35990c69b3ac
Upstream: p->downstream_error instead of closing connection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5745
diff
changeset
|
2439 u->pipe->downstream_error = 1; |
2701 | 2440 } |
2441 | |
573 | 2442 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
|
2443 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
|
2444 r->request_body->temp_file->file.fd = NGX_INVALID_FILE; |
563 | 2445 } |
2446 | |
581 | 2447 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
2448 | |
649 | 2449 if (!u->buffering) { |
581 | 2450 |
2451 if (u->input_filter == NULL) { | |
2452 u->input_filter_init = ngx_http_upstream_non_buffered_filter_init; | |
2453 u->input_filter = ngx_http_upstream_non_buffered_filter; | |
2454 u->input_filter_ctx = r; | |
2455 } | |
2456 | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2457 u->read_event_handler = ngx_http_upstream_process_non_buffered_upstream; |
581 | 2458 r->write_event_handler = |
2459 ngx_http_upstream_process_non_buffered_downstream; | |
2460 | |
2461 r->limit_rate = 0; | |
2462 | |
2463 if (u->input_filter_init(u->input_filter_ctx) == NGX_ERROR) { | |
5295
a489c31c9783
Upstream: ngx_http_upstream_finalize_request(NGX_ERROR) on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5294
diff
changeset
|
2464 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
581 | 2465 return; |
2466 } | |
2467 | |
583 | 2468 if (clcf->tcp_nodelay && c->tcp_nodelay == NGX_TCP_NODELAY_UNSET) { |
2469 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "tcp_nodelay"); | |
2470 | |
2471 tcp_nodelay = 1; | |
2472 | |
2473 if (setsockopt(c->fd, IPPROTO_TCP, TCP_NODELAY, | |
2474 (const void *) &tcp_nodelay, sizeof(int)) == -1) | |
2475 { | |
2476 ngx_connection_error(c, ngx_socket_errno, | |
2477 "setsockopt(TCP_NODELAY) failed"); | |
5295
a489c31c9783
Upstream: ngx_http_upstream_finalize_request(NGX_ERROR) on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5294
diff
changeset
|
2478 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
583 | 2479 return; |
2480 } | |
2481 | |
2482 c->tcp_nodelay = NGX_TCP_NODELAY_SET; | |
2483 } | |
2484 | |
2402 | 2485 n = u->buffer.last - u->buffer.pos; |
2486 | |
2487 if (n) { | |
581 | 2488 u->buffer.last = u->buffer.pos; |
2489 | |
2402 | 2490 u->state->response_length += n; |
2491 | |
2492 if (u->input_filter(u->input_filter_ctx, n) == NGX_ERROR) { | |
5295
a489c31c9783
Upstream: ngx_http_upstream_finalize_request(NGX_ERROR) on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5294
diff
changeset
|
2493 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
581 | 2494 return; |
2495 } | |
2496 | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2497 ngx_http_upstream_process_non_buffered_downstream(r); |
581 | 2498 |
2499 } else { | |
2500 u->buffer.pos = u->buffer.start; | |
2501 u->buffer.last = u->buffer.start; | |
2502 | |
2503 if (ngx_http_send_special(r, NGX_HTTP_FLUSH) == NGX_ERROR) { | |
5295
a489c31c9783
Upstream: ngx_http_upstream_finalize_request(NGX_ERROR) on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5294
diff
changeset
|
2504 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
581 | 2505 return; |
2506 } | |
1468
491e5059ea19
read EOF of header only responses in non-buffered proxying
Igor Sysoev <igor@sysoev.ru>
parents:
1397
diff
changeset
|
2507 |
4120
42135dd1f0ea
Upstream: keepalive flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4119
diff
changeset
|
2508 if (u->peer.connection->read->ready || u->length == 0) { |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2509 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
|
2510 } |
581 | 2511 } |
2512 | |
2513 return; | |
2514 } | |
2515 | |
479 | 2516 /* TODO: preallocate event_pipe bufs, look "Content-Length" */ |
2517 | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2518 #if (NGX_HTTP_CACHE) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2519 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2520 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
|
2521 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
|
2522 r->cache->file.fd = NGX_INVALID_FILE; |
479 | 2523 } |
2524 | |
3699
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2525 switch (ngx_http_test_predicates(r, u->conf->no_cache)) { |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2526 |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2527 case NGX_ERROR: |
5295
a489c31c9783
Upstream: ngx_http_upstream_finalize_request(NGX_ERROR) on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5294
diff
changeset
|
2528 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
3699
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2529 return; |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2530 |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2531 case NGX_DECLINED: |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2532 u->cacheable = 0; |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2533 break; |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2534 |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2535 default: /* NGX_OK */ |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2536 |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2537 if (u->cache_status == NGX_HTTP_CACHE_BYPASS) { |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2538 |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2539 r->cache->min_uses = u->conf->cache_min_uses; |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2540 r->cache->body_start = u->conf->buffer_size; |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2541 r->cache->file_cache = u->conf->cache->data; |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2542 |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2543 if (ngx_http_file_cache_create(r) != NGX_OK) { |
5295
a489c31c9783
Upstream: ngx_http_upstream_finalize_request(NGX_ERROR) on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5294
diff
changeset
|
2544 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
3699
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2545 return; |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2546 } |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2547 } |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2548 |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2549 break; |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2550 } |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2551 |
1565 | 2552 if (u->cacheable) { |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2553 time_t now, valid; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2554 |
2663
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
2555 now = ngx_time(); |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
2556 |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
2557 valid = r->cache->valid_sec; |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
2558 |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
2559 if (valid == 0) { |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
2560 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
|
2561 u->headers_in.status_n); |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
2562 if (valid) { |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
2563 r->cache->valid_sec = now + valid; |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
2564 } |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
2565 } |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
2566 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2567 if (valid) { |
5732
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
2568 r->cache->last_modified = u->headers_in.last_modified_time; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2569 r->cache->date = now; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2570 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
|
2571 |
5737
44b9ab7752e3
Cache: ETag now saved into cache header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5735
diff
changeset
|
2572 if (u->headers_in.etag) { |
44b9ab7752e3
Cache: ETag now saved into cache header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5735
diff
changeset
|
2573 r->cache->etag = u->headers_in.etag->value; |
44b9ab7752e3
Cache: ETag now saved into cache header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5735
diff
changeset
|
2574 } |
44b9ab7752e3
Cache: ETag now saved into cache header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5735
diff
changeset
|
2575 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2576 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
|
2577 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2578 } else { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2579 u->cacheable = 0; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2580 } |
479 | 2581 } |
2582 | |
2690 | 2583 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, |
2584 "http cacheable: %d", u->cacheable); | |
2585 | |
3083
ffe8bfb38184
clean cache updating state if a response has uncacheable code or
Igor Sysoev <igor@sysoev.ru>
parents:
3056
diff
changeset
|
2586 if (u->cacheable == 0 && r->cache) { |
3711
ce6ba077c270
several changes in cache cleanup handling:
Igor Sysoev <igor@sysoev.ru>
parents:
3709
diff
changeset
|
2587 ngx_http_file_cache_free(r->cache, u->pipe->temp_file); |
3083
ffe8bfb38184
clean cache updating state if a response has uncacheable code or
Igor Sysoev <igor@sysoev.ru>
parents:
3056
diff
changeset
|
2588 } |
ffe8bfb38184
clean cache updating state if a response has uncacheable code or
Igor Sysoev <igor@sysoev.ru>
parents:
3056
diff
changeset
|
2589 |
479 | 2590 #endif |
2591 | |
581 | 2592 p = u->pipe; |
479 | 2593 |
2594 p->output_filter = (ngx_event_pipe_output_filter_pt) ngx_http_output_filter; | |
2595 p->output_ctx = r; | |
2596 p->tag = u->output.tag; | |
577 | 2597 p->bufs = u->conf->bufs; |
479 | 2598 p->busy_size = u->conf->busy_buffers_size; |
2599 p->upstream = u->peer.connection; | |
583 | 2600 p->downstream = c; |
479 | 2601 p->pool = r->pool; |
583 | 2602 p->log = c->log; |
5883
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
2603 p->limit_rate = u->conf->limit_rate; |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
2604 p->start_sec = ngx_time(); |
577 | 2605 |
1565 | 2606 p->cacheable = u->cacheable || u->store; |
479 | 2607 |
501 | 2608 p->temp_file = ngx_pcalloc(r->pool, sizeof(ngx_temp_file_t)); |
2609 if (p->temp_file == NULL) { | |
5295
a489c31c9783
Upstream: ngx_http_upstream_finalize_request(NGX_ERROR) on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5294
diff
changeset
|
2610 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
479 | 2611 return; |
2612 } | |
2613 | |
2614 p->temp_file->file.fd = NGX_INVALID_FILE; | |
583 | 2615 p->temp_file->file.log = c->log; |
479 | 2616 p->temp_file->path = u->conf->temp_path; |
2617 p->temp_file->pool = r->pool; | |
577 | 2618 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2619 if (p->cacheable) { |
479 | 2620 p->temp_file->persistent = 1; |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
2621 |
479 | 2622 } else { |
667 | 2623 p->temp_file->log_level = NGX_LOG_WARN; |
479 | 2624 p->temp_file->warn = "an upstream response is buffered " |
2625 "to a temporary file"; | |
2626 } | |
2627 | |
2628 p->max_temp_file_size = u->conf->max_temp_file_size; | |
2629 p->temp_file_write_size = u->conf->temp_file_write_size; | |
2630 | |
501 | 2631 p->preread_bufs = ngx_alloc_chain_link(r->pool); |
2632 if (p->preread_bufs == NULL) { | |
5295
a489c31c9783
Upstream: ngx_http_upstream_finalize_request(NGX_ERROR) on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5294
diff
changeset
|
2633 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
479 | 2634 return; |
2635 } | |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
2636 |
581 | 2637 p->preread_bufs->buf = &u->buffer; |
479 | 2638 p->preread_bufs->next = NULL; |
581 | 2639 u->buffer.recycled = 1; |
2640 | |
2641 p->preread_size = u->buffer.last - u->buffer.pos; | |
479 | 2642 |
1565 | 2643 if (u->cacheable) { |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
2644 |
479 | 2645 p->buf_to_file = ngx_calloc_buf(r->pool); |
2646 if (p->buf_to_file == NULL) { | |
5295
a489c31c9783
Upstream: ngx_http_upstream_finalize_request(NGX_ERROR) on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5294
diff
changeset
|
2647 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
479 | 2648 return; |
2649 } | |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
2650 |
4895
508e61393b6c
Event pipe: fixed handling of buf_to_file data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4769
diff
changeset
|
2651 p->buf_to_file->start = u->buffer.start; |
581 | 2652 p->buf_to_file->pos = u->buffer.start; |
2653 p->buf_to_file->last = u->buffer.pos; | |
479 | 2654 p->buf_to_file->temporary = 1; |
2655 } | |
2656 | |
2657 if (ngx_event_flags & NGX_USE_AIO_EVENT) { | |
4499
778ef9c3fd2d
Fixed spelling in single-line comments.
Ruslan Ermilov <ru@nginx.com>
parents:
4474
diff
changeset
|
2658 /* the posted aio operation may corrupt a shadow buffer */ |
479 | 2659 p->single_buf = 1; |
2660 } | |
2661 | |
2662 /* TODO: p->free_bufs = 0 if use ngx_create_chain_of_bufs() */ | |
2663 p->free_bufs = 1; | |
2664 | |
2665 /* | |
581 | 2666 * event_pipe would do u->buffer.last += p->preread_size |
479 | 2667 * as though these bytes were read |
2668 */ | |
581 | 2669 u->buffer.last = u->buffer.pos; |
479 | 2670 |
2671 if (u->conf->cyclic_temp_file) { | |
2672 | |
2673 /* | |
2674 * we need to disable the use of sendfile() if we use cyclic temp file | |
2675 * because the writing a new data may interfere with sendfile() | |
2676 * that uses the same kernel file pages (at least on FreeBSD) | |
2677 */ | |
2678 | |
2679 p->cyclic_temp_file = 1; | |
583 | 2680 c->sendfile = 0; |
479 | 2681 |
2682 } else { | |
2683 p->cyclic_temp_file = 0; | |
2684 } | |
2685 | |
2686 p->read_timeout = u->conf->read_timeout; | |
2687 p->send_timeout = clcf->send_timeout; | |
2688 p->send_lowat = clcf->send_lowat; | |
2689 | |
4119
b66712cde67d
Upstream: pipe length and input_filter_init in buffered mode.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4118
diff
changeset
|
2690 p->length = -1; |
b66712cde67d
Upstream: pipe length and input_filter_init in buffered mode.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4118
diff
changeset
|
2691 |
b66712cde67d
Upstream: pipe length and input_filter_init in buffered mode.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4118
diff
changeset
|
2692 if (u->input_filter_init |
b66712cde67d
Upstream: pipe length and input_filter_init in buffered mode.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4118
diff
changeset
|
2693 && u->input_filter_init(p->input_ctx) != NGX_OK) |
b66712cde67d
Upstream: pipe length and input_filter_init in buffered mode.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4118
diff
changeset
|
2694 { |
5295
a489c31c9783
Upstream: ngx_http_upstream_finalize_request(NGX_ERROR) on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5294
diff
changeset
|
2695 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
4119
b66712cde67d
Upstream: pipe length and input_filter_init in buffered mode.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4118
diff
changeset
|
2696 return; |
b66712cde67d
Upstream: pipe length and input_filter_init in buffered mode.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4118
diff
changeset
|
2697 } |
b66712cde67d
Upstream: pipe length and input_filter_init in buffered mode.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4118
diff
changeset
|
2698 |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2699 u->read_event_handler = ngx_http_upstream_process_upstream; |
509 | 2700 r->write_event_handler = ngx_http_upstream_process_downstream; |
479 | 2701 |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2702 ngx_http_upstream_process_upstream(r, u); |
479 | 2703 } |
2704 | |
2705 | |
487 | 2706 static void |
5072
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2707 ngx_http_upstream_upgrade(ngx_http_request_t *r, ngx_http_upstream_t *u) |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2708 { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2709 int tcp_nodelay; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2710 ngx_connection_t *c; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2711 ngx_http_core_loc_conf_t *clcf; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2712 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2713 c = r->connection; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2714 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2715 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2716 /* TODO: prevent upgrade if not requested or not possible */ |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2717 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2718 r->keepalive = 0; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2719 c->log->action = "proxying upgraded connection"; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2720 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2721 u->read_event_handler = ngx_http_upstream_upgraded_read_upstream; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2722 u->write_event_handler = ngx_http_upstream_upgraded_write_upstream; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2723 r->read_event_handler = ngx_http_upstream_upgraded_read_downstream; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2724 r->write_event_handler = ngx_http_upstream_upgraded_write_downstream; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2725 |
5142
afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5132
diff
changeset
|
2726 if (clcf->tcp_nodelay) { |
5072
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2727 tcp_nodelay = 1; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2728 |
5142
afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5132
diff
changeset
|
2729 if (c->tcp_nodelay == NGX_TCP_NODELAY_UNSET) { |
afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5132
diff
changeset
|
2730 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "tcp_nodelay"); |
afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5132
diff
changeset
|
2731 |
afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5132
diff
changeset
|
2732 if (setsockopt(c->fd, IPPROTO_TCP, TCP_NODELAY, |
afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5132
diff
changeset
|
2733 (const void *) &tcp_nodelay, sizeof(int)) == -1) |
afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5132
diff
changeset
|
2734 { |
afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5132
diff
changeset
|
2735 ngx_connection_error(c, ngx_socket_errno, |
afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5132
diff
changeset
|
2736 "setsockopt(TCP_NODELAY) failed"); |
5295
a489c31c9783
Upstream: ngx_http_upstream_finalize_request(NGX_ERROR) on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5294
diff
changeset
|
2737 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
5142
afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5132
diff
changeset
|
2738 return; |
afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5132
diff
changeset
|
2739 } |
afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5132
diff
changeset
|
2740 |
afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5132
diff
changeset
|
2741 c->tcp_nodelay = NGX_TCP_NODELAY_SET; |
5072
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2742 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2743 |
5142
afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5132
diff
changeset
|
2744 if (u->peer.connection->tcp_nodelay == NGX_TCP_NODELAY_UNSET) { |
afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5132
diff
changeset
|
2745 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, u->peer.connection->log, 0, |
afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5132
diff
changeset
|
2746 "tcp_nodelay"); |
afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5132
diff
changeset
|
2747 |
afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5132
diff
changeset
|
2748 if (setsockopt(u->peer.connection->fd, IPPROTO_TCP, TCP_NODELAY, |
afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5132
diff
changeset
|
2749 (const void *) &tcp_nodelay, sizeof(int)) == -1) |
afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5132
diff
changeset
|
2750 { |
afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5132
diff
changeset
|
2751 ngx_connection_error(u->peer.connection, ngx_socket_errno, |
afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5132
diff
changeset
|
2752 "setsockopt(TCP_NODELAY) failed"); |
5295
a489c31c9783
Upstream: ngx_http_upstream_finalize_request(NGX_ERROR) on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5294
diff
changeset
|
2753 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
5142
afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5132
diff
changeset
|
2754 return; |
afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5132
diff
changeset
|
2755 } |
afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5132
diff
changeset
|
2756 |
afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5132
diff
changeset
|
2757 u->peer.connection->tcp_nodelay = NGX_TCP_NODELAY_SET; |
5072
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2758 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2759 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2760 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2761 if (ngx_http_send_special(r, NGX_HTTP_FLUSH) == NGX_ERROR) { |
5295
a489c31c9783
Upstream: ngx_http_upstream_finalize_request(NGX_ERROR) on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5294
diff
changeset
|
2762 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
5072
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2763 return; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2764 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2765 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2766 if (u->peer.connection->read->ready |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2767 || u->buffer.pos != u->buffer.last) |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2768 { |
5579
7586e7b2dbe9
Upstream: ngx_post_event() instead of upgraded call (ticket #503).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5557
diff
changeset
|
2769 ngx_post_event(c->read, &ngx_posted_events); |
5073
52eb762c68a9
Proxy: fixed do_write handling in previous commit.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5072
diff
changeset
|
2770 ngx_http_upstream_process_upgraded(r, 1, 1); |
5579
7586e7b2dbe9
Upstream: ngx_post_event() instead of upgraded call (ticket #503).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5557
diff
changeset
|
2771 return; |
5072
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2772 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2773 |
5532
17134d29782e
Upstream: reading from a client after connection upgrade.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5500
diff
changeset
|
2774 ngx_http_upstream_process_upgraded(r, 0, 1); |
5072
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2775 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2776 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2777 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2778 static void |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2779 ngx_http_upstream_upgraded_read_downstream(ngx_http_request_t *r) |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2780 { |
5073
52eb762c68a9
Proxy: fixed do_write handling in previous commit.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5072
diff
changeset
|
2781 ngx_http_upstream_process_upgraded(r, 0, 0); |
5072
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2782 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2783 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2784 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2785 static void |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2786 ngx_http_upstream_upgraded_write_downstream(ngx_http_request_t *r) |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2787 { |
5073
52eb762c68a9
Proxy: fixed do_write handling in previous commit.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5072
diff
changeset
|
2788 ngx_http_upstream_process_upgraded(r, 1, 1); |
5072
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2789 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2790 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2791 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2792 static void |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2793 ngx_http_upstream_upgraded_read_upstream(ngx_http_request_t *r, |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2794 ngx_http_upstream_t *u) |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2795 { |
5073
52eb762c68a9
Proxy: fixed do_write handling in previous commit.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5072
diff
changeset
|
2796 ngx_http_upstream_process_upgraded(r, 1, 0); |
5072
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2797 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2798 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2799 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2800 static void |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2801 ngx_http_upstream_upgraded_write_upstream(ngx_http_request_t *r, |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2802 ngx_http_upstream_t *u) |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2803 { |
5073
52eb762c68a9
Proxy: fixed do_write handling in previous commit.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5072
diff
changeset
|
2804 ngx_http_upstream_process_upgraded(r, 0, 1); |
5072
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2805 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2806 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2807 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2808 static void |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2809 ngx_http_upstream_process_upgraded(ngx_http_request_t *r, |
5073
52eb762c68a9
Proxy: fixed do_write handling in previous commit.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5072
diff
changeset
|
2810 ngx_uint_t from_upstream, ngx_uint_t do_write) |
5072
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2811 { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2812 size_t size; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2813 ssize_t n; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2814 ngx_buf_t *b; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2815 ngx_connection_t *c, *downstream, *upstream, *dst, *src; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2816 ngx_http_upstream_t *u; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2817 ngx_http_core_loc_conf_t *clcf; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2818 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2819 c = r->connection; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2820 u = r->upstream; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2821 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2822 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2823 "http upstream process upgraded, fu:%ui", from_upstream); |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2824 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2825 downstream = c; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2826 upstream = u->peer.connection; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2827 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2828 if (downstream->write->timedout) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2829 c->timedout = 1; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2830 ngx_connection_error(c, NGX_ETIMEDOUT, "client timed out"); |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2831 ngx_http_upstream_finalize_request(r, u, NGX_HTTP_REQUEST_TIME_OUT); |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2832 return; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2833 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2834 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2835 if (upstream->read->timedout || upstream->write->timedout) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2836 ngx_connection_error(c, NGX_ETIMEDOUT, "upstream timed out"); |
5296
1ccdda1f37f3
Upstream: NGX_HTTP_GATEWAY_TIME_OUT after upstream timeouts.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5295
diff
changeset
|
2837 ngx_http_upstream_finalize_request(r, u, NGX_HTTP_GATEWAY_TIME_OUT); |
5072
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2838 return; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2839 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2840 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2841 if (from_upstream) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2842 src = upstream; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2843 dst = downstream; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2844 b = &u->buffer; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2845 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2846 } else { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2847 src = downstream; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2848 dst = upstream; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2849 b = &u->from_client; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2850 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2851 if (r->header_in->last > r->header_in->pos) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2852 b = r->header_in; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2853 b->end = b->last; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2854 do_write = 1; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2855 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2856 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2857 if (b->start == NULL) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2858 b->start = ngx_palloc(r->pool, u->conf->buffer_size); |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2859 if (b->start == NULL) { |
5295
a489c31c9783
Upstream: ngx_http_upstream_finalize_request(NGX_ERROR) on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5294
diff
changeset
|
2860 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
5072
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2861 return; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2862 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2863 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2864 b->pos = b->start; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2865 b->last = b->start; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2866 b->end = b->start + u->conf->buffer_size; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2867 b->temporary = 1; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2868 b->tag = u->output.tag; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2869 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2870 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2871 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2872 for ( ;; ) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2873 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2874 if (do_write) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2875 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2876 size = b->last - b->pos; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2877 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2878 if (size && dst->write->ready) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2879 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2880 n = dst->send(dst, b->pos, size); |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2881 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2882 if (n == NGX_ERROR) { |
5295
a489c31c9783
Upstream: ngx_http_upstream_finalize_request(NGX_ERROR) on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5294
diff
changeset
|
2883 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
5072
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2884 return; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2885 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2886 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2887 if (n > 0) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2888 b->pos += n; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2889 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2890 if (b->pos == b->last) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2891 b->pos = b->start; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2892 b->last = b->start; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2893 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2894 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2895 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2896 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2897 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2898 size = b->end - b->last; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2899 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2900 if (size && src->read->ready) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2901 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2902 n = src->recv(src, b->last, size); |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2903 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2904 if (n == NGX_AGAIN || n == 0) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2905 break; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2906 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2907 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2908 if (n > 0) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2909 do_write = 1; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2910 b->last += n; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2911 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2912 continue; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2913 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2914 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2915 if (n == NGX_ERROR) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2916 src->read->eof = 1; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2917 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2918 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2919 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2920 break; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2921 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2922 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2923 if ((upstream->read->eof && u->buffer.pos == u->buffer.last) |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2924 || (downstream->read->eof && u->from_client.pos == u->from_client.last) |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2925 || (downstream->read->eof && upstream->read->eof)) |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2926 { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2927 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2928 "http upstream upgraded done"); |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2929 ngx_http_upstream_finalize_request(r, u, 0); |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2930 return; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2931 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2932 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2933 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2934 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2935 if (ngx_handle_write_event(upstream->write, u->conf->send_lowat) |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2936 != NGX_OK) |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2937 { |
5295
a489c31c9783
Upstream: ngx_http_upstream_finalize_request(NGX_ERROR) on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5294
diff
changeset
|
2938 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
5072
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2939 return; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2940 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2941 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2942 if (upstream->write->active && !upstream->write->ready) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2943 ngx_add_timer(upstream->write, u->conf->send_timeout); |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2944 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2945 } else if (upstream->write->timer_set) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2946 ngx_del_timer(upstream->write); |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2947 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2948 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2949 if (ngx_handle_read_event(upstream->read, 0) != NGX_OK) { |
5295
a489c31c9783
Upstream: ngx_http_upstream_finalize_request(NGX_ERROR) on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5294
diff
changeset
|
2950 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
5072
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2951 return; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2952 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2953 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2954 if (upstream->read->active && !upstream->read->ready) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2955 ngx_add_timer(upstream->read, u->conf->read_timeout); |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2956 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2957 } else if (upstream->read->timer_set) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2958 ngx_del_timer(upstream->read); |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2959 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2960 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2961 if (ngx_handle_write_event(downstream->write, clcf->send_lowat) |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2962 != NGX_OK) |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2963 { |
5295
a489c31c9783
Upstream: ngx_http_upstream_finalize_request(NGX_ERROR) on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5294
diff
changeset
|
2964 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
5072
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2965 return; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2966 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2967 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2968 if (ngx_handle_read_event(downstream->read, 0) != NGX_OK) { |
5295
a489c31c9783
Upstream: ngx_http_upstream_finalize_request(NGX_ERROR) on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5294
diff
changeset
|
2969 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
5072
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2970 return; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2971 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2972 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2973 if (downstream->write->active && !downstream->write->ready) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2974 ngx_add_timer(downstream->write, clcf->send_timeout); |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2975 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2976 } else if (downstream->write->timer_set) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2977 ngx_del_timer(downstream->write); |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2978 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2979 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2980 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2981 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2982 static void |
581 | 2983 ngx_http_upstream_process_non_buffered_downstream(ngx_http_request_t *r) |
2984 { | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2985 ngx_event_t *wev; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2986 ngx_connection_t *c; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2987 ngx_http_upstream_t *u; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2988 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2989 c = r->connection; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2990 u = r->upstream; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2991 wev = c->write; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2992 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2993 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
|
2994 "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
|
2995 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2996 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
|
2997 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2998 if (wev->timedout) { |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2999 c->timedout = 1; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3000 ngx_connection_error(c, NGX_ETIMEDOUT, "client timed out"); |
3963
10fbb8f02a45
finalizing with rc == 0 in unbuffered proxy mode caused nginx to wait
Igor Sysoev <igor@sysoev.ru>
parents:
3944
diff
changeset
|
3001 ngx_http_upstream_finalize_request(r, u, NGX_HTTP_REQUEST_TIME_OUT); |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3002 return; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3003 } |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3004 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3005 ngx_http_upstream_process_non_buffered_request(r, 1); |
581 | 3006 } |
3007 | |
3008 | |
3009 static void | |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
3010 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
|
3011 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
|
3012 { |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
3013 ngx_connection_t *c; |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
3014 |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
3015 c = u->peer.connection; |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3016 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3017 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
|
3018 "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
|
3019 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3020 c->log->action = "reading upstream"; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3021 |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
3022 if (c->read->timedout) { |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3023 ngx_connection_error(c, NGX_ETIMEDOUT, "upstream timed out"); |
5296
1ccdda1f37f3
Upstream: NGX_HTTP_GATEWAY_TIME_OUT after upstream timeouts.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5295
diff
changeset
|
3024 ngx_http_upstream_finalize_request(r, u, NGX_HTTP_GATEWAY_TIME_OUT); |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3025 return; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3026 } |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3027 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3028 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
|
3029 } |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3030 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3031 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3032 static void |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3033 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
|
3034 ngx_uint_t do_write) |
581 | 3035 { |
3036 size_t size; | |
3037 ssize_t n; | |
3038 ngx_buf_t *b; | |
583 | 3039 ngx_int_t rc; |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3040 ngx_connection_t *downstream, *upstream; |
581 | 3041 ngx_http_upstream_t *u; |
3042 ngx_http_core_loc_conf_t *clcf; | |
3043 | |
756
d904b5cb3bba
fix building introduced by previous commit
Igor Sysoev <igor@sysoev.ru>
parents:
755
diff
changeset
|
3044 u = r->upstream; |
884 | 3045 downstream = r->connection; |
3046 upstream = u->peer.connection; | |
581 | 3047 |
3048 b = &u->buffer; | |
3049 | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3050 do_write = do_write || u->length == 0; |
581 | 3051 |
3052 for ( ;; ) { | |
3053 | |
3054 if (do_write) { | |
3055 | |
3056 if (u->out_bufs || u->busy_bufs) { | |
583 | 3057 rc = ngx_http_output_filter(r, u->out_bufs); |
3058 | |
3059 if (rc == NGX_ERROR) { | |
5295
a489c31c9783
Upstream: ngx_http_upstream_finalize_request(NGX_ERROR) on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5294
diff
changeset
|
3060 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
581 | 3061 return; |
3062 } | |
3063 | |
4114
5db098f97e0e
API change: ngx_chain_update_chains() now requires pool.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3976
diff
changeset
|
3064 ngx_chain_update_chains(r->pool, &u->free_bufs, &u->busy_bufs, |
581 | 3065 &u->out_bufs, u->output.tag); |
3066 } | |
3067 | |
3068 if (u->busy_bufs == NULL) { | |
3069 | |
3070 if (u->length == 0 | |
5301
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3071 || (upstream->read->eof && u->length == -1)) |
581 | 3072 { |
3073 ngx_http_upstream_finalize_request(r, u, 0); | |
3074 return; | |
3075 } | |
3076 | |
5301
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3077 if (upstream->read->eof) { |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3078 ngx_log_error(NGX_LOG_ERR, upstream->log, 0, |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3079 "upstream prematurely closed connection"); |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3080 |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3081 ngx_http_upstream_finalize_request(r, u, |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3082 NGX_HTTP_BAD_GATEWAY); |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3083 return; |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3084 } |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3085 |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3086 if (upstream->read->error) { |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3087 ngx_http_upstream_finalize_request(r, u, |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3088 NGX_HTTP_BAD_GATEWAY); |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3089 return; |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3090 } |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3091 |
581 | 3092 b->pos = b->start; |
3093 b->last = b->start; | |
3094 } | |
3095 } | |
3096 | |
3097 size = b->end - b->last; | |
3098 | |
884 | 3099 if (size && upstream->read->ready) { |
3100 | |
3101 n = upstream->recv(upstream, b->last, size); | |
581 | 3102 |
3103 if (n == NGX_AGAIN) { | |
3104 break; | |
3105 } | |
3106 | |
3107 if (n > 0) { | |
2402 | 3108 u->state->response_length += n; |
3109 | |
581 | 3110 if (u->input_filter(u->input_filter_ctx, n) == NGX_ERROR) { |
5295
a489c31c9783
Upstream: ngx_http_upstream_finalize_request(NGX_ERROR) on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5294
diff
changeset
|
3111 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
581 | 3112 return; |
3113 } | |
3114 } | |
3115 | |
3116 do_write = 1; | |
3117 | |
3118 continue; | |
3119 } | |
3120 | |
3121 break; | |
3122 } | |
3123 | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3124 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
|
3125 |
884 | 3126 if (downstream->data == r) { |
3127 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
|
3128 != NGX_OK) |
583 | 3129 { |
5295
a489c31c9783
Upstream: ngx_http_upstream_finalize_request(NGX_ERROR) on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5294
diff
changeset
|
3130 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
583 | 3131 return; |
3132 } | |
581 | 3133 } |
3134 | |
1063
e2a6ecc5a3ae
a non-active client connection must not closed after send timeout
Igor Sysoev <igor@sysoev.ru>
parents:
1031
diff
changeset
|
3135 if (downstream->write->active && !downstream->write->ready) { |
884 | 3136 ngx_add_timer(downstream->write, clcf->send_timeout); |
3137 | |
3138 } else if (downstream->write->timer_set) { | |
3139 ngx_del_timer(downstream->write); | |
581 | 3140 } |
3141 | |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
3142 if (ngx_handle_read_event(upstream->read, 0) != NGX_OK) { |
5295
a489c31c9783
Upstream: ngx_http_upstream_finalize_request(NGX_ERROR) on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5294
diff
changeset
|
3143 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
581 | 3144 return; |
3145 } | |
3146 | |
1063
e2a6ecc5a3ae
a non-active client connection must not closed after send timeout
Igor Sysoev <igor@sysoev.ru>
parents:
1031
diff
changeset
|
3147 if (upstream->read->active && !upstream->read->ready) { |
884 | 3148 ngx_add_timer(upstream->read, u->conf->read_timeout); |
3149 | |
3150 } else if (upstream->read->timer_set) { | |
3151 ngx_del_timer(upstream->read); | |
581 | 3152 } |
3153 } | |
3154 | |
3155 | |
3156 static ngx_int_t | |
3157 ngx_http_upstream_non_buffered_filter_init(void *data) | |
3158 { | |
3159 return NGX_OK; | |
3160 } | |
3161 | |
3162 | |
3163 static ngx_int_t | |
3164 ngx_http_upstream_non_buffered_filter(void *data, ssize_t bytes) | |
3165 { | |
3166 ngx_http_request_t *r = data; | |
3167 | |
3168 ngx_buf_t *b; | |
3169 ngx_chain_t *cl, **ll; | |
3170 ngx_http_upstream_t *u; | |
3171 | |
3172 u = r->upstream; | |
3173 | |
3174 for (cl = u->out_bufs, ll = &u->out_bufs; cl; cl = cl->next) { | |
3175 ll = &cl->next; | |
3176 } | |
3177 | |
3178 cl = ngx_chain_get_free_buf(r->pool, &u->free_bufs); | |
3179 if (cl == NULL) { | |
3180 return NGX_ERROR; | |
3181 } | |
3182 | |
3183 *ll = cl; | |
3184 | |
3185 cl->buf->flush = 1; | |
3186 cl->buf->memory = 1; | |
3187 | |
3188 b = &u->buffer; | |
3189 | |
3190 cl->buf->pos = b->last; | |
3191 b->last += bytes; | |
3192 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
|
3193 cl->buf->tag = u->output.tag; |
581 | 3194 |
4118
dbddec65fdab
Upstream: r->upstream->length type change to off_t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4117
diff
changeset
|
3195 if (u->length == -1) { |
581 | 3196 return NGX_OK; |
3197 } | |
3198 | |
3199 u->length -= bytes; | |
3200 | |
3201 return NGX_OK; | |
3202 } | |
3203 | |
3204 | |
3205 static void | |
509 | 3206 ngx_http_upstream_process_downstream(ngx_http_request_t *r) |
3207 { | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3208 ngx_event_t *wev; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3209 ngx_connection_t *c; |
509 | 3210 ngx_event_pipe_t *p; |
479 | 3211 ngx_http_upstream_t *u; |
3212 | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3213 c = r->connection; |
479 | 3214 u = r->upstream; |
581 | 3215 p = u->pipe; |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3216 wev = c->write; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3217 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3218 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
|
3219 "http upstream process downstream"); |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3220 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3221 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
|
3222 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3223 if (wev->timedout) { |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3224 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3225 if (wev->delayed) { |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3226 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3227 wev->timedout = 0; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3228 wev->delayed = 0; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3229 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3230 if (!wev->ready) { |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3231 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
|
3232 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3233 if (ngx_handle_write_event(wev, p->send_lowat) != NGX_OK) { |
5295
a489c31c9783
Upstream: ngx_http_upstream_finalize_request(NGX_ERROR) on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5294
diff
changeset
|
3234 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3235 } |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3236 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3237 return; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3238 } |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3239 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3240 if (ngx_event_pipe(p, wev->write) == NGX_ABORT) { |
5297
0ae9a2958886
Upstream: NGX_ERROR after pipe errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5296
diff
changeset
|
3241 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3242 return; |
527 | 3243 } |
479 | 3244 |
3245 } else { | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3246 p->downstream_error = 1; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3247 c->timedout = 1; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3248 ngx_connection_error(c, NGX_ETIMEDOUT, "client timed out"); |
479 | 3249 } |
3250 | |
3251 } else { | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3252 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3253 if (wev->delayed) { |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3254 |
527 | 3255 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, |
3256 "http downstream delayed"); | |
3257 | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3258 if (ngx_handle_write_event(wev, p->send_lowat) != NGX_OK) { |
5295
a489c31c9783
Upstream: ngx_http_upstream_finalize_request(NGX_ERROR) on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5294
diff
changeset
|
3259 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
527 | 3260 } |
3261 | |
3262 return; | |
3263 } | |
3264 | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3265 if (ngx_event_pipe(p, 1) == NGX_ABORT) { |
5297
0ae9a2958886
Upstream: NGX_ERROR after pipe errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5296
diff
changeset
|
3266 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
479 | 3267 return; |
3268 } | |
3269 } | |
577 | 3270 |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3271 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
|
3272 } |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3273 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3274 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3275 static void |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
3276 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
|
3277 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
|
3278 { |
5883
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3279 ngx_event_t *rev; |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3280 ngx_event_pipe_t *p; |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
3281 ngx_connection_t *c; |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
3282 |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
3283 c = u->peer.connection; |
5883
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3284 p = u->pipe; |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3285 rev = c->read; |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3286 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3287 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
|
3288 "http upstream process upstream"); |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3289 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3290 c->log->action = "reading upstream"; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3291 |
5883
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3292 if (rev->timedout) { |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3293 |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3294 if (rev->delayed) { |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3295 |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3296 rev->timedout = 0; |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3297 rev->delayed = 0; |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3298 |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3299 if (!rev->ready) { |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3300 ngx_add_timer(rev, p->read_timeout); |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3301 |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3302 if (ngx_handle_read_event(rev, 0) != NGX_OK) { |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3303 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3304 } |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3305 |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3306 return; |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3307 } |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3308 |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3309 if (ngx_event_pipe(p, 0) == NGX_ABORT) { |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3310 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3311 return; |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3312 } |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3313 |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3314 } else { |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3315 p->upstream_error = 1; |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3316 ngx_connection_error(c, NGX_ETIMEDOUT, "upstream timed out"); |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3317 } |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3318 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3319 } else { |
5883
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3320 |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3321 if (rev->delayed) { |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3322 |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3323 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3324 "http upstream delayed"); |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3325 |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3326 if (ngx_handle_read_event(rev, 0) != NGX_OK) { |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3327 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3328 } |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3329 |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3330 return; |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3331 } |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3332 |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3333 if (ngx_event_pipe(p, 0) == NGX_ABORT) { |
5297
0ae9a2958886
Upstream: NGX_ERROR after pipe errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5296
diff
changeset
|
3334 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3335 return; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3336 } |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3337 } |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3338 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3339 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
|
3340 } |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3341 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3342 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3343 static void |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3344 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
|
3345 { |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3346 ngx_temp_file_t *tf; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3347 ngx_event_pipe_t *p; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3348 ngx_http_upstream_t *u; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3349 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3350 u = r->upstream; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3351 p = u->pipe; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3352 |
479 | 3353 if (u->peer.connection) { |
3354 | |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3355 if (u->store) { |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3356 |
2463 | 3357 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
|
3358 |
5298
a7b2db9119e0
Upstream: replaced u->pipe->temp_file with p->temp_file.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5297
diff
changeset
|
3359 tf = p->temp_file; |
4469
24c0dca04eb9
Fix for proxy_store leaving temporary files for subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4464
diff
changeset
|
3360 |
2445
3c6af1fb7586
proxy/fastcgi_store did not delete incomplete files
Igor Sysoev <igor@sysoev.ru>
parents:
2441
diff
changeset
|
3361 if (u->headers_in.status_n == NGX_HTTP_OK |
5299
b779728b180c
Upstream: fixed store/cache of unfinished responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5298
diff
changeset
|
3362 && (p->upstream_done || p->length == -1) |
2445
3c6af1fb7586
proxy/fastcgi_store did not delete incomplete files
Igor Sysoev <igor@sysoev.ru>
parents:
2441
diff
changeset
|
3363 && (u->headers_in.content_length_n == -1 |
5298
a7b2db9119e0
Upstream: replaced u->pipe->temp_file with p->temp_file.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5297
diff
changeset
|
3364 || u->headers_in.content_length_n == tf->offset)) |
2445
3c6af1fb7586
proxy/fastcgi_store did not delete incomplete files
Igor Sysoev <igor@sysoev.ru>
parents:
2441
diff
changeset
|
3365 { |
3c6af1fb7586
proxy/fastcgi_store did not delete incomplete files
Igor Sysoev <igor@sysoev.ru>
parents:
2441
diff
changeset
|
3366 ngx_http_upstream_store(r, u); |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3367 } |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3368 } |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3369 } |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3370 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3371 #if (NGX_HTTP_CACHE) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3372 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3373 if (u->cacheable) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3374 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3375 if (p->upstream_done) { |
5298
a7b2db9119e0
Upstream: replaced u->pipe->temp_file with p->temp_file.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5297
diff
changeset
|
3376 ngx_http_file_cache_update(r, p->temp_file); |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3377 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3378 } else if (p->upstream_eof) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3379 |
5298
a7b2db9119e0
Upstream: replaced u->pipe->temp_file with p->temp_file.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5297
diff
changeset
|
3380 tf = p->temp_file; |
4298
186f02886bed
Upstream: don't cache unfinished responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4197
diff
changeset
|
3381 |
5299
b779728b180c
Upstream: fixed store/cache of unfinished responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5298
diff
changeset
|
3382 if (p->length == -1 |
b779728b180c
Upstream: fixed store/cache of unfinished responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5298
diff
changeset
|
3383 && (u->headers_in.content_length_n == -1 |
b779728b180c
Upstream: fixed store/cache of unfinished responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5298
diff
changeset
|
3384 || u->headers_in.content_length_n |
b779728b180c
Upstream: fixed store/cache of unfinished responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5298
diff
changeset
|
3385 == tf->offset - (off_t) r->cache->body_start)) |
4298
186f02886bed
Upstream: don't cache unfinished responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4197
diff
changeset
|
3386 { |
186f02886bed
Upstream: don't cache unfinished responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4197
diff
changeset
|
3387 ngx_http_file_cache_update(r, tf); |
186f02886bed
Upstream: don't cache unfinished responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4197
diff
changeset
|
3388 |
186f02886bed
Upstream: don't cache unfinished responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4197
diff
changeset
|
3389 } else { |
186f02886bed
Upstream: don't cache unfinished responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4197
diff
changeset
|
3390 ngx_http_file_cache_free(r->cache, tf); |
186f02886bed
Upstream: don't cache unfinished responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4197
diff
changeset
|
3391 } |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3392 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3393 } else if (p->upstream_error) { |
5298
a7b2db9119e0
Upstream: replaced u->pipe->temp_file with p->temp_file.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5297
diff
changeset
|
3394 ngx_http_file_cache_free(r->cache, p->temp_file); |
479 | 3395 } |
3396 } | |
3397 | |
3398 #endif | |
3399 | |
3400 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
|
3401 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
483 | 3402 "http upstream exit: %p", p->out); |
5301
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3403 |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3404 if (p->upstream_done |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3405 || (p->upstream_eof && p->length == -1)) |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3406 { |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3407 ngx_http_upstream_finalize_request(r, u, 0); |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3408 return; |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3409 } |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3410 |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3411 if (p->upstream_eof) { |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3412 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3413 "upstream prematurely closed connection"); |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3414 } |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3415 |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3416 ngx_http_upstream_finalize_request(r, u, NGX_HTTP_BAD_GATEWAY); |
479 | 3417 return; |
3418 } | |
3419 } | |
3420 | |
3421 if (p->downstream_error) { | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3422 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
483 | 3423 "http upstream downstream error"); |
479 | 3424 |
2757
9cc973b46af1
get a full response if the response is cacheable or storable even
Igor Sysoev <igor@sysoev.ru>
parents:
2708
diff
changeset
|
3425 if (!u->cacheable && !u->store && u->peer.connection) { |
5297
0ae9a2958886
Upstream: NGX_ERROR after pipe errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5296
diff
changeset
|
3426 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
479 | 3427 } |
3428 } | |
3429 } | |
3430 | |
3431 | |
487 | 3432 static void |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3433 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
|
3434 { |
1947
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
3435 size_t root; |
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
3436 time_t lm; |
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
3437 ngx_str_t path; |
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
3438 ngx_temp_file_t *tf; |
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
3439 ngx_ext_rename_file_t ext; |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3440 |
1777 | 3441 tf = u->pipe->temp_file; |
3442 | |
3443 if (tf->file.fd == NGX_INVALID_FILE) { | |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3444 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3445 /* create file for empty 200 response */ |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3446 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3447 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
|
3448 if (tf == NULL) { |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3449 return; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3450 } |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3451 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3452 tf->file.fd = NGX_INVALID_FILE; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3453 tf->file.log = r->connection->log; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3454 tf->path = u->conf->temp_path; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3455 tf->pool = r->pool; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3456 tf->persistent = 1; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3457 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3458 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
|
3459 tf->persistent, tf->clean, tf->access) |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3460 != NGX_OK) |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3461 { |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3462 return; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3463 } |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3464 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3465 u->pipe->temp_file = tf; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3466 } |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3467 |
1947
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
3468 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
|
3469 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
|
3470 ext.time = -1; |
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
3471 ext.create_path = 1; |
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
3472 ext.delete_file = 1; |
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
3473 ext.log = r->connection->log; |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3474 |
1705 | 3475 if (u->headers_in.last_modified) { |
3476 | |
1947
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
3477 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
|
3478 u->headers_in.last_modified->value.len); |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3479 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3480 if (lm != NGX_ERROR) { |
1947
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
3481 ext.time = lm; |
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
3482 ext.fd = tf->file.fd; |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3483 } |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3484 } |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3485 |
1295
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
3486 if (u->conf->store_lengths == NULL) { |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
3487 |
5770
9de5820bb3e0
Upstream: ngx_http_upstream_store() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5757
diff
changeset
|
3488 if (ngx_http_map_uri_to_path(r, &path, &root, 0) == NULL) { |
9de5820bb3e0
Upstream: ngx_http_upstream_store() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5757
diff
changeset
|
3489 return; |
9de5820bb3e0
Upstream: ngx_http_upstream_store() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5757
diff
changeset
|
3490 } |
1295
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
3491 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
3492 } else { |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
3493 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
|
3494 u->conf->store_values->elts) |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
3495 == NULL) |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
3496 { |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
3497 return; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
3498 } |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
3499 } |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3500 |
3032
524ba56ba9f7
fix copy destination name length, introduced in r3025
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
3501 path.len--; |
524ba56ba9f7
fix copy destination name length, introduced in r3025
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
3502 |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3503 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
|
3504 "upstream stores \"%s\" to \"%s\"", |
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
3505 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
|
3506 |
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
3507 (void) ngx_ext_rename_file(&tf->file.name, &path, &ext); |
5770
9de5820bb3e0
Upstream: ngx_http_upstream_store() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5757
diff
changeset
|
3508 |
9de5820bb3e0
Upstream: ngx_http_upstream_store() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5757
diff
changeset
|
3509 u->store = 0; |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3510 } |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3511 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3512 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3513 static void |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
3514 ngx_http_upstream_dummy_handler(ngx_http_request_t *r, ngx_http_upstream_t *u) |
479 | 3515 { |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
3516 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
479 | 3517 "http upstream dummy handler"); |
3518 } | |
3519 | |
3520 | |
487 | 3521 static void |
3522 ngx_http_upstream_next(ngx_http_request_t *r, ngx_http_upstream_t *u, | |
3523 ngx_uint_t ft_type) | |
479 | 3524 { |
5832
d09b689911ac
Upstream: limited next_upstream time and tries (ticket #544).
Roman Arutyunyan <arut@nginx.com>
parents:
5827
diff
changeset
|
3525 ngx_msec_t timeout; |
884 | 3526 ngx_uint_t status, state; |
479 | 3527 |
3528 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
884 | 3529 "http next upstream, %xi", ft_type); |
479 | 3530 |
5132
9bcf89ca78d2
Upstream: only call peer.free() if peer.get() selected a peer.
Ruslan Ermilov <ru@nginx.com>
parents:
5121
diff
changeset
|
3531 if (u->peer.sockaddr) { |
9bcf89ca78d2
Upstream: only call peer.free() if peer.get() selected a peer.
Ruslan Ermilov <ru@nginx.com>
parents:
5121
diff
changeset
|
3532 |
5231
05c53652e7b4
Upstream: http_403 support in proxy_next_upstream (and friends).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5217
diff
changeset
|
3533 if (ft_type == NGX_HTTP_UPSTREAM_FT_HTTP_403 |
05c53652e7b4
Upstream: http_403 support in proxy_next_upstream (and friends).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5217
diff
changeset
|
3534 || ft_type == NGX_HTTP_UPSTREAM_FT_HTTP_404) |
05c53652e7b4
Upstream: http_403 support in proxy_next_upstream (and friends).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5217
diff
changeset
|
3535 { |
5132
9bcf89ca78d2
Upstream: only call peer.free() if peer.get() selected a peer.
Ruslan Ermilov <ru@nginx.com>
parents:
5121
diff
changeset
|
3536 state = NGX_PEER_NEXT; |
5231
05c53652e7b4
Upstream: http_403 support in proxy_next_upstream (and friends).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5217
diff
changeset
|
3537 |
5132
9bcf89ca78d2
Upstream: only call peer.free() if peer.get() selected a peer.
Ruslan Ermilov <ru@nginx.com>
parents:
5121
diff
changeset
|
3538 } else { |
9bcf89ca78d2
Upstream: only call peer.free() if peer.get() selected a peer.
Ruslan Ermilov <ru@nginx.com>
parents:
5121
diff
changeset
|
3539 state = NGX_PEER_FAILED; |
9bcf89ca78d2
Upstream: only call peer.free() if peer.get() selected a peer.
Ruslan Ermilov <ru@nginx.com>
parents:
5121
diff
changeset
|
3540 } |
9bcf89ca78d2
Upstream: only call peer.free() if peer.get() selected a peer.
Ruslan Ermilov <ru@nginx.com>
parents:
5121
diff
changeset
|
3541 |
1378 | 3542 u->peer.free(&u->peer, u->peer.data, state); |
5132
9bcf89ca78d2
Upstream: only call peer.free() if peer.get() selected a peer.
Ruslan Ermilov <ru@nginx.com>
parents:
5121
diff
changeset
|
3543 u->peer.sockaddr = NULL; |
1378 | 3544 } |
525 | 3545 |
479 | 3546 if (ft_type == NGX_HTTP_UPSTREAM_FT_TIMEOUT) { |
3547 ngx_log_error(NGX_LOG_ERR, r->connection->log, NGX_ETIMEDOUT, | |
3548 "upstream timed out"); | |
3549 } | |
577 | 3550 |
479 | 3551 if (u->peer.cached && ft_type == NGX_HTTP_UPSTREAM_FT_ERROR) { |
3552 status = 0; | |
3553 | |
4115
70a45a504905
Workaround for cpu hog on errors with cached connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4114
diff
changeset
|
3554 /* TODO: inform balancer instead */ |
70a45a504905
Workaround for cpu hog on errors with cached connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4114
diff
changeset
|
3555 |
70a45a504905
Workaround for cpu hog on errors with cached connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4114
diff
changeset
|
3556 u->peer.tries++; |
70a45a504905
Workaround for cpu hog on errors with cached connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4114
diff
changeset
|
3557 |
479 | 3558 } else { |
5757
c5ec6944de98
Style: add whitespace between control statement and parentheses.
Piotr Sikora <piotr@cloudflare.com>
parents:
5746
diff
changeset
|
3559 switch (ft_type) { |
479 | 3560 |
3561 case NGX_HTTP_UPSTREAM_FT_TIMEOUT: | |
3562 status = NGX_HTTP_GATEWAY_TIME_OUT; | |
3563 break; | |
3564 | |
3565 case NGX_HTTP_UPSTREAM_FT_HTTP_500: | |
3566 status = NGX_HTTP_INTERNAL_SERVER_ERROR; | |
3567 break; | |
3568 | |
5231
05c53652e7b4
Upstream: http_403 support in proxy_next_upstream (and friends).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5217
diff
changeset
|
3569 case NGX_HTTP_UPSTREAM_FT_HTTP_403: |
05c53652e7b4
Upstream: http_403 support in proxy_next_upstream (and friends).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5217
diff
changeset
|
3570 status = NGX_HTTP_FORBIDDEN; |
05c53652e7b4
Upstream: http_403 support in proxy_next_upstream (and friends).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5217
diff
changeset
|
3571 break; |
05c53652e7b4
Upstream: http_403 support in proxy_next_upstream (and friends).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5217
diff
changeset
|
3572 |
479 | 3573 case NGX_HTTP_UPSTREAM_FT_HTTP_404: |
3574 status = NGX_HTTP_NOT_FOUND; | |
3575 break; | |
3576 | |
3577 /* | |
3578 * NGX_HTTP_UPSTREAM_FT_BUSY_LOCK and NGX_HTTP_UPSTREAM_FT_MAX_WAITING | |
3579 * never reach here | |
3580 */ | |
3581 | |
3582 default: | |
3583 status = NGX_HTTP_BAD_GATEWAY; | |
3584 } | |
3585 } | |
3586 | |
583 | 3587 if (r->connection->error) { |
479 | 3588 ngx_http_upstream_finalize_request(r, u, |
3589 NGX_HTTP_CLIENT_CLOSED_REQUEST); | |
3590 return; | |
3591 } | |
3592 | |
3593 if (status) { | |
3594 u->state->status = status; | |
5832
d09b689911ac
Upstream: limited next_upstream time and tries (ticket #544).
Roman Arutyunyan <arut@nginx.com>
parents:
5827
diff
changeset
|
3595 timeout = u->conf->next_upstream_timeout; |
d09b689911ac
Upstream: limited next_upstream time and tries (ticket #544).
Roman Arutyunyan <arut@nginx.com>
parents:
5827
diff
changeset
|
3596 |
d09b689911ac
Upstream: limited next_upstream time and tries (ticket #544).
Roman Arutyunyan <arut@nginx.com>
parents:
5827
diff
changeset
|
3597 if (u->peer.tries == 0 |
d09b689911ac
Upstream: limited next_upstream time and tries (ticket #544).
Roman Arutyunyan <arut@nginx.com>
parents:
5827
diff
changeset
|
3598 || !(u->conf->next_upstream & ft_type) |
d09b689911ac
Upstream: limited next_upstream time and tries (ticket #544).
Roman Arutyunyan <arut@nginx.com>
parents:
5827
diff
changeset
|
3599 || (timeout && ngx_current_msec - u->peer.start_time >= timeout)) |
d09b689911ac
Upstream: limited next_upstream time and tries (ticket #544).
Roman Arutyunyan <arut@nginx.com>
parents:
5827
diff
changeset
|
3600 { |
479 | 3601 #if (NGX_HTTP_CACHE) |
3602 | |
2952 | 3603 if (u->cache_status == NGX_HTTP_CACHE_EXPIRED |
3604 && (u->conf->cache_use_stale & ft_type)) | |
3605 { | |
2805
60551422e150
reinit proxy/fastcgi header parser before ngx_http_upstream_cache_send()
Igor Sysoev <igor@sysoev.ru>
parents:
2804
diff
changeset
|
3606 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
|
3607 |
60551422e150
reinit proxy/fastcgi header parser before ngx_http_upstream_cache_send()
Igor Sysoev <igor@sysoev.ru>
parents:
2804
diff
changeset
|
3608 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
|
3609 |
60551422e150
reinit proxy/fastcgi header parser before ngx_http_upstream_cache_send()
Igor Sysoev <igor@sysoev.ru>
parents:
2804
diff
changeset
|
3610 if (rc == NGX_OK) { |
2952 | 3611 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
|
3612 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
|
3613 } |
60551422e150
reinit proxy/fastcgi header parser before ngx_http_upstream_cache_send()
Igor Sysoev <igor@sysoev.ru>
parents:
2804
diff
changeset
|
3614 |
60551422e150
reinit proxy/fastcgi header parser before ngx_http_upstream_cache_send()
Igor Sysoev <igor@sysoev.ru>
parents:
2804
diff
changeset
|
3615 ngx_http_upstream_finalize_request(r, u, rc); |
479 | 3616 return; |
3617 } | |
3618 #endif | |
3619 | |
3620 ngx_http_upstream_finalize_request(r, u, status); | |
3621 return; | |
3622 } | |
3623 } | |
3624 | |
3625 if (u->peer.connection) { | |
3626 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
3627 "close http upstream connection: %d", | |
3628 u->peer.connection->fd); | |
577 | 3629 #if (NGX_HTTP_SSL) |
884 | 3630 |
577 | 3631 if (u->peer.connection->ssl) { |
884 | 3632 u->peer.connection->ssl->no_wait_shutdown = 1; |
3633 u->peer.connection->ssl->no_send_shutdown = 1; | |
3634 | |
3635 (void) ngx_ssl_shutdown(u->peer.connection); | |
577 | 3636 } |
3637 #endif | |
884 | 3638 |
4138
70e1ee2307f9
Fix of separate pool for upstream connections (r4117).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4124
diff
changeset
|
3639 if (u->peer.connection->pool) { |
70e1ee2307f9
Fix of separate pool for upstream connections (r4117).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4124
diff
changeset
|
3640 ngx_destroy_pool(u->peer.connection->pool); |
70e1ee2307f9
Fix of separate pool for upstream connections (r4117).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4124
diff
changeset
|
3641 } |
70e1ee2307f9
Fix of separate pool for upstream connections (r4117).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4124
diff
changeset
|
3642 |
479 | 3643 ngx_close_connection(u->peer.connection); |
4143
114e3a7c3b8d
Upstream: clearing of u->peer.connection on close.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4138
diff
changeset
|
3644 u->peer.connection = NULL; |
479 | 3645 } |
3646 | |
3647 ngx_http_upstream_connect(r, u); | |
3648 } | |
3649 | |
3650 | |
487 | 3651 static void |
569 | 3652 ngx_http_upstream_cleanup(void *data) |
3653 { | |
3654 ngx_http_request_t *r = data; | |
3655 | |
3656 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
3657 "cleanup http upstream request: \"%V\"", &r->uri); | |
3658 | |
5167
85ee9d858dcb
Upstream: removed surplus ngx_resolve_name_done() call.
Valentin Bartenev <vbart@nginx.com>
parents:
5142
diff
changeset
|
3659 ngx_http_upstream_finalize_request(r, r->upstream, NGX_DONE); |
569 | 3660 } |
3661 | |
3662 | |
3663 static void | |
487 | 3664 ngx_http_upstream_finalize_request(ngx_http_request_t *r, |
3665 ngx_http_upstream_t *u, ngx_int_t rc) | |
479 | 3666 { |
5304
d3eab5e2df5f
Upstream: no last buffer on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5303
diff
changeset
|
3667 ngx_uint_t flush; |
889
a9a7e4b1a72b
the previous fix does not actually fix overflow
Igor Sysoev <igor@sysoev.ru>
parents:
888
diff
changeset
|
3668 ngx_time_t *tp; |
563 | 3669 |
483 | 3670 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
3671 "finalize http upstream request: %i", rc); | |
479 | 3672 |
2413 | 3673 if (u->cleanup) { |
3674 *u->cleanup = NULL; | |
3418
a076e1823737
delete u->cleanup mark, this fixes large values in $upstream_response_time,
Igor Sysoev <igor@sysoev.ru>
parents:
3401
diff
changeset
|
3675 u->cleanup = NULL; |
2413 | 3676 } |
569 | 3677 |
3169
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
3678 if (u->resolved && u->resolved->ctx) { |
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
3679 ngx_resolve_name_done(u->resolved->ctx); |
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
3680 u->resolved->ctx = NULL; |
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
3681 } |
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
3682 |
1658 | 3683 if (u->state && u->state->response_sec) { |
563 | 3684 tp = ngx_timeofday(); |
889
a9a7e4b1a72b
the previous fix does not actually fix overflow
Igor Sysoev <igor@sysoev.ru>
parents:
888
diff
changeset
|
3685 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
|
3686 u->state->response_msec = tp->msec - u->state->response_msec; |
2402 | 3687 |
5169
f6bbe77794aa
Upstream: fixed $upstream_response_length without buffering.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5167
diff
changeset
|
3688 if (u->pipe && u->pipe->read_length) { |
2402 | 3689 u->state->response_length = u->pipe->read_length; |
3690 } | |
563 | 3691 } |
3692 | |
479 | 3693 u->finalize_request(r, rc); |
3694 | |
5132
9bcf89ca78d2
Upstream: only call peer.free() if peer.get() selected a peer.
Ruslan Ermilov <ru@nginx.com>
parents:
5121
diff
changeset
|
3695 if (u->peer.free && u->peer.sockaddr) { |
1658 | 3696 u->peer.free(&u->peer, u->peer.data, 0); |
5132
9bcf89ca78d2
Upstream: only call peer.free() if peer.get() selected a peer.
Ruslan Ermilov <ru@nginx.com>
parents:
5121
diff
changeset
|
3697 u->peer.sockaddr = NULL; |
1658 | 3698 } |
884 | 3699 |
479 | 3700 if (u->peer.connection) { |
884 | 3701 |
577 | 3702 #if (NGX_HTTP_SSL) |
3703 | |
3704 /* TODO: do not shutdown persistent connection */ | |
3705 | |
3706 if (u->peer.connection->ssl) { | |
884 | 3707 |
3708 /* | |
3709 * We send the "close notify" shutdown alert to the upstream only | |
3710 * and do not wait its "close notify" shutdown alert. | |
3711 * It is acceptable according to the TLS standard. | |
3712 */ | |
3713 | |
3714 u->peer.connection->ssl->no_wait_shutdown = 1; | |
3715 | |
3716 (void) ngx_ssl_shutdown(u->peer.connection); | |
577 | 3717 } |
3718 #endif | |
884 | 3719 |
3720 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
3721 "close http upstream connection: %d", | |
3722 u->peer.connection->fd); | |
3723 | |
4138
70e1ee2307f9
Fix of separate pool for upstream connections (r4117).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4124
diff
changeset
|
3724 if (u->peer.connection->pool) { |
70e1ee2307f9
Fix of separate pool for upstream connections (r4117).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4124
diff
changeset
|
3725 ngx_destroy_pool(u->peer.connection->pool); |
70e1ee2307f9
Fix of separate pool for upstream connections (r4117).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4124
diff
changeset
|
3726 } |
70e1ee2307f9
Fix of separate pool for upstream connections (r4117).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4124
diff
changeset
|
3727 |
479 | 3728 ngx_close_connection(u->peer.connection); |
3729 } | |
3730 | |
483 | 3731 u->peer.connection = NULL; |
3732 | |
581 | 3733 if (u->pipe && u->pipe->temp_file) { |
479 | 3734 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
3735 "http upstream temp fd: %d", | |
581 | 3736 u->pipe->temp_file->file.fd); |
479 | 3737 } |
3738 | |
4469
24c0dca04eb9
Fix for proxy_store leaving temporary files for subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4464
diff
changeset
|
3739 if (u->store && u->pipe && u->pipe->temp_file |
24c0dca04eb9
Fix for proxy_store leaving temporary files for subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4464
diff
changeset
|
3740 && u->pipe->temp_file->file.fd != NGX_INVALID_FILE) |
24c0dca04eb9
Fix for proxy_store leaving temporary files for subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4464
diff
changeset
|
3741 { |
24c0dca04eb9
Fix for proxy_store leaving temporary files for subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4464
diff
changeset
|
3742 if (ngx_delete_file(u->pipe->temp_file->file.name.data) |
24c0dca04eb9
Fix for proxy_store leaving temporary files for subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4464
diff
changeset
|
3743 == NGX_FILE_ERROR) |
24c0dca04eb9
Fix for proxy_store leaving temporary files for subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4464
diff
changeset
|
3744 { |
24c0dca04eb9
Fix for proxy_store leaving temporary files for subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4464
diff
changeset
|
3745 ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno, |
24c0dca04eb9
Fix for proxy_store leaving temporary files for subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4464
diff
changeset
|
3746 ngx_delete_file_n " \"%s\" failed", |
24c0dca04eb9
Fix for proxy_store leaving temporary files for subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4464
diff
changeset
|
3747 u->pipe->temp_file->file.name.data); |
24c0dca04eb9
Fix for proxy_store leaving temporary files for subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4464
diff
changeset
|
3748 } |
24c0dca04eb9
Fix for proxy_store leaving temporary files for subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4464
diff
changeset
|
3749 } |
24c0dca04eb9
Fix for proxy_store leaving temporary files for subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4464
diff
changeset
|
3750 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3751 #if (NGX_HTTP_CACHE) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3752 |
3940
22f3e9197096
revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents:
3934
diff
changeset
|
3753 if (r->cache) { |
22f3e9197096
revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents:
3934
diff
changeset
|
3754 |
22f3e9197096
revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents:
3934
diff
changeset
|
3755 if (u->cacheable) { |
22f3e9197096
revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents:
3934
diff
changeset
|
3756 |
22f3e9197096
revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents:
3934
diff
changeset
|
3757 if (rc == NGX_HTTP_BAD_GATEWAY || rc == NGX_HTTP_GATEWAY_TIME_OUT) { |
22f3e9197096
revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents:
3934
diff
changeset
|
3758 time_t valid; |
22f3e9197096
revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents:
3934
diff
changeset
|
3759 |
22f3e9197096
revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents:
3934
diff
changeset
|
3760 valid = ngx_http_file_cache_valid(u->conf->cache_valid, rc); |
22f3e9197096
revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents:
3934
diff
changeset
|
3761 |
22f3e9197096
revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents:
3934
diff
changeset
|
3762 if (valid) { |
22f3e9197096
revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents:
3934
diff
changeset
|
3763 r->cache->valid_sec = ngx_time() + valid; |
22f3e9197096
revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents:
3934
diff
changeset
|
3764 r->cache->error = rc; |
22f3e9197096
revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents:
3934
diff
changeset
|
3765 } |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3766 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3767 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3768 |
3711
ce6ba077c270
several changes in cache cleanup handling:
Igor Sysoev <igor@sysoev.ru>
parents:
3709
diff
changeset
|
3769 ngx_http_file_cache_free(r->cache, u->pipe->temp_file); |
479 | 3770 } |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3771 |
479 | 3772 #endif |
3773 | |
5392
f1caf7b8ae1d
Upstream: subrequest_in_memory fix.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5373
diff
changeset
|
3774 if (r->subrequest_in_memory |
f1caf7b8ae1d
Upstream: subrequest_in_memory fix.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5373
diff
changeset
|
3775 && u->headers_in.status_n >= NGX_HTTP_SPECIAL_RESPONSE) |
f1caf7b8ae1d
Upstream: subrequest_in_memory fix.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5373
diff
changeset
|
3776 { |
f1caf7b8ae1d
Upstream: subrequest_in_memory fix.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5373
diff
changeset
|
3777 u->buffer.last = u->buffer.pos; |
f1caf7b8ae1d
Upstream: subrequest_in_memory fix.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5373
diff
changeset
|
3778 } |
f1caf7b8ae1d
Upstream: subrequest_in_memory fix.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5373
diff
changeset
|
3779 |
515 | 3780 if (rc == NGX_DECLINED) { |
3781 return; | |
3782 } | |
3783 | |
483 | 3784 r->connection->log->action = "sending to client"; |
3785 | |
5303
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
3786 if (!u->header_sent |
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
3787 || rc == NGX_HTTP_REQUEST_TIME_OUT |
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
3788 || rc == NGX_HTTP_CLIENT_CLOSED_REQUEST) |
4151
3549db8ceaf2
Cache: fix for sending of stale responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4143
diff
changeset
|
3789 { |
5303
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
3790 ngx_http_finalize_request(r, rc); |
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
3791 return; |
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
3792 } |
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
3793 |
5304
d3eab5e2df5f
Upstream: no last buffer on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5303
diff
changeset
|
3794 flush = 0; |
d3eab5e2df5f
Upstream: no last buffer on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5303
diff
changeset
|
3795 |
d3eab5e2df5f
Upstream: no last buffer on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5303
diff
changeset
|
3796 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) { |
d3eab5e2df5f
Upstream: no last buffer on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5303
diff
changeset
|
3797 rc = NGX_ERROR; |
d3eab5e2df5f
Upstream: no last buffer on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5303
diff
changeset
|
3798 flush = 1; |
5303
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
3799 } |
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
3800 |
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
3801 if (r->header_only) { |
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
3802 ngx_http_finalize_request(r, rc); |
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
3803 return; |
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
3804 } |
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
3805 |
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
3806 if (rc == 0) { |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
3807 rc = ngx_http_send_special(r, NGX_HTTP_LAST); |
5304
d3eab5e2df5f
Upstream: no last buffer on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5303
diff
changeset
|
3808 |
d3eab5e2df5f
Upstream: no last buffer on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5303
diff
changeset
|
3809 } else if (flush) { |
d3eab5e2df5f
Upstream: no last buffer on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5303
diff
changeset
|
3810 r->keepalive = 0; |
d3eab5e2df5f
Upstream: no last buffer on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5303
diff
changeset
|
3811 rc = ngx_http_send_special(r, NGX_HTTP_FLUSH); |
479 | 3812 } |
3813 | |
3814 ngx_http_finalize_request(r, rc); | |
3815 } | |
3816 | |
3817 | |
509 | 3818 static ngx_int_t |
3819 ngx_http_upstream_process_header_line(ngx_http_request_t *r, ngx_table_elt_t *h, | |
3820 ngx_uint_t offset) | |
577 | 3821 { |
509 | 3822 ngx_table_elt_t **ph; |
577 | 3823 |
509 | 3824 ph = (ngx_table_elt_t **) ((char *) &r->upstream->headers_in + offset); |
3825 | |
3826 if (*ph == NULL) { | |
3827 *ph = h; | |
3828 } | |
3829 | |
3830 return NGX_OK; | |
3831 } | |
3832 | |
3833 | |
3834 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
|
3835 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
|
3836 ngx_uint_t offset) |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3837 { |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3838 return NGX_OK; |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3839 } |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3840 |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3841 |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3842 static ngx_int_t |
4117
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
3843 ngx_http_upstream_process_content_length(ngx_http_request_t *r, |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
3844 ngx_table_elt_t *h, ngx_uint_t offset) |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
3845 { |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
3846 ngx_http_upstream_t *u; |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
3847 |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
3848 u = r->upstream; |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
3849 |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
3850 u->headers_in.content_length = h; |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
3851 u->headers_in.content_length_n = ngx_atoof(h->value.data, h->value.len); |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
3852 |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
3853 return NGX_OK; |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
3854 } |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
3855 |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
3856 |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
3857 static ngx_int_t |
5732
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
3858 ngx_http_upstream_process_last_modified(ngx_http_request_t *r, |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
3859 ngx_table_elt_t *h, ngx_uint_t offset) |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
3860 { |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
3861 ngx_http_upstream_t *u; |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
3862 |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
3863 u = r->upstream; |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
3864 |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
3865 u->headers_in.last_modified = h; |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
3866 |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
3867 #if (NGX_HTTP_CACHE) |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
3868 |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
3869 if (u->cacheable) { |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
3870 u->headers_in.last_modified_time = ngx_http_parse_time(h->value.data, |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
3871 h->value.len); |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
3872 } |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
3873 |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
3874 #endif |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
3875 |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
3876 return NGX_OK; |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
3877 } |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
3878 |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
3879 |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
3880 static ngx_int_t |
3669
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
3881 ngx_http_upstream_process_set_cookie(ngx_http_request_t *r, ngx_table_elt_t *h, |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
3882 ngx_uint_t offset) |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
3883 { |
5677
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
3884 ngx_array_t *pa; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
3885 ngx_table_elt_t **ph; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
3886 ngx_http_upstream_t *u; |
3669
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
3887 |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
3888 u = r->upstream; |
5677
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
3889 pa = &u->headers_in.cookies; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
3890 |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
3891 if (pa->elts == NULL) { |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
3892 if (ngx_array_init(pa, r->pool, 1, sizeof(ngx_table_elt_t *)) != NGX_OK) |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
3893 { |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
3894 return NGX_ERROR; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
3895 } |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
3896 } |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
3897 |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
3898 ph = ngx_array_push(pa); |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
3899 if (ph == NULL) { |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
3900 return NGX_ERROR; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
3901 } |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
3902 |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
3903 *ph = h; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
3904 |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
3905 #if (NGX_HTTP_CACHE) |
3669
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
3906 if (!(u->conf->ignore_headers & NGX_HTTP_UPSTREAM_IGN_SET_COOKIE)) { |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
3907 u->cacheable = 0; |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
3908 } |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
3909 #endif |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
3910 |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
3911 return NGX_OK; |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
3912 } |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
3913 |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
3914 |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
3915 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
|
3916 ngx_http_upstream_process_cache_control(ngx_http_request_t *r, |
509 | 3917 ngx_table_elt_t *h, ngx_uint_t offset) |
3918 { | |
2786
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
3919 ngx_array_t *pa; |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
3920 ngx_table_elt_t **ph; |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
3921 ngx_http_upstream_t *u; |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
3922 |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
3923 u = r->upstream; |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
3924 pa = &u->headers_in.cache_control; |
509 | 3925 |
3926 if (pa->elts == NULL) { | |
3927 if (ngx_array_init(pa, r->pool, 2, sizeof(ngx_table_elt_t *)) != NGX_OK) | |
3928 { | |
3929 return NGX_ERROR; | |
3930 } | |
3931 } | |
3932 | |
3933 ph = ngx_array_push(pa); | |
3934 if (ph == NULL) { | |
3935 return NGX_ERROR; | |
3936 } | |
3937 | |
3938 *ph = h; | |
3939 | |
2708
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
3940 #if (NGX_HTTP_CACHE) |
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
3941 { |
5911
88d55e5934f7
Cache: add support for Cache-Control's s-maxage response directive.
Piotr Sikora <piotr@cloudflare.com>
parents:
5905
diff
changeset
|
3942 u_char *p, *start, *last; |
2708
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
3943 ngx_int_t n; |
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
3944 |
2786
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
3945 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
|
3946 return NGX_OK; |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
3947 } |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
3948 |
2669
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3949 if (r->cache == NULL) { |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3950 return NGX_OK; |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3951 } |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3952 |
5500
6a3ab6fdd70f
Upstream: Cache-Control preferred over Expires.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5489
diff
changeset
|
3953 if (r->cache->valid_sec != 0 && u->headers_in.x_accel_expires != NULL) { |
2669
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3954 return NGX_OK; |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3955 } |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3956 |
5911
88d55e5934f7
Cache: add support for Cache-Control's s-maxage response directive.
Piotr Sikora <piotr@cloudflare.com>
parents:
5905
diff
changeset
|
3957 start = h->value.data; |
88d55e5934f7
Cache: add support for Cache-Control's s-maxage response directive.
Piotr Sikora <piotr@cloudflare.com>
parents:
5905
diff
changeset
|
3958 last = start + h->value.len; |
88d55e5934f7
Cache: add support for Cache-Control's s-maxage response directive.
Piotr Sikora <piotr@cloudflare.com>
parents:
5905
diff
changeset
|
3959 |
88d55e5934f7
Cache: add support for Cache-Control's s-maxage response directive.
Piotr Sikora <piotr@cloudflare.com>
parents:
5905
diff
changeset
|
3960 if (ngx_strlcasestrn(start, last, (u_char *) "no-cache", 8 - 1) != NULL |
88d55e5934f7
Cache: add support for Cache-Control's s-maxage response directive.
Piotr Sikora <piotr@cloudflare.com>
parents:
5905
diff
changeset
|
3961 || ngx_strlcasestrn(start, last, (u_char *) "no-store", 8 - 1) != NULL |
88d55e5934f7
Cache: add support for Cache-Control's s-maxage response directive.
Piotr Sikora <piotr@cloudflare.com>
parents:
5905
diff
changeset
|
3962 || ngx_strlcasestrn(start, last, (u_char *) "private", 7 - 1) != NULL) |
2669
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3963 { |
2786
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
3964 u->cacheable = 0; |
2669
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3965 return NGX_OK; |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3966 } |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3967 |
5911
88d55e5934f7
Cache: add support for Cache-Control's s-maxage response directive.
Piotr Sikora <piotr@cloudflare.com>
parents:
5905
diff
changeset
|
3968 p = ngx_strlcasestrn(start, last, (u_char *) "s-maxage=", 9 - 1); |
88d55e5934f7
Cache: add support for Cache-Control's s-maxage response directive.
Piotr Sikora <piotr@cloudflare.com>
parents:
5905
diff
changeset
|
3969 offset = 9; |
88d55e5934f7
Cache: add support for Cache-Control's s-maxage response directive.
Piotr Sikora <piotr@cloudflare.com>
parents:
5905
diff
changeset
|
3970 |
88d55e5934f7
Cache: add support for Cache-Control's s-maxage response directive.
Piotr Sikora <piotr@cloudflare.com>
parents:
5905
diff
changeset
|
3971 if (p == NULL) { |
88d55e5934f7
Cache: add support for Cache-Control's s-maxage response directive.
Piotr Sikora <piotr@cloudflare.com>
parents:
5905
diff
changeset
|
3972 p = ngx_strlcasestrn(start, last, (u_char *) "max-age=", 8 - 1); |
88d55e5934f7
Cache: add support for Cache-Control's s-maxage response directive.
Piotr Sikora <piotr@cloudflare.com>
parents:
5905
diff
changeset
|
3973 offset = 8; |
88d55e5934f7
Cache: add support for Cache-Control's s-maxage response directive.
Piotr Sikora <piotr@cloudflare.com>
parents:
5905
diff
changeset
|
3974 } |
2669
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3975 |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3976 if (p == NULL) { |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3977 return NGX_OK; |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3978 } |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3979 |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3980 n = 0; |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3981 |
5911
88d55e5934f7
Cache: add support for Cache-Control's s-maxage response directive.
Piotr Sikora <piotr@cloudflare.com>
parents:
5905
diff
changeset
|
3982 for (p += offset; p < last; p++) { |
3198
48bfb7dc981b
test comma separator in "Cache-Control"
Igor Sysoev <igor@sysoev.ru>
parents:
3195
diff
changeset
|
3983 if (*p == ',' || *p == ';' || *p == ' ') { |
2669
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3984 break; |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3985 } |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3986 |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3987 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
|
3988 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
|
3989 continue; |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3990 } |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3991 |
2786
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
3992 u->cacheable = 0; |
2669
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3993 return NGX_OK; |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3994 } |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3995 |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3996 if (n == 0) { |
2786
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
3997 u->cacheable = 0; |
2669
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3998 return NGX_OK; |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
3999 } |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4000 |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4001 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
|
4002 } |
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
4003 #endif |
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
4004 |
509 | 4005 return NGX_OK; |
4006 } | |
4007 | |
4008 | |
4009 static ngx_int_t | |
2666 | 4010 ngx_http_upstream_process_expires(ngx_http_request_t *r, ngx_table_elt_t *h, |
4011 ngx_uint_t offset) | |
4012 { | |
2786
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4013 ngx_http_upstream_t *u; |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4014 |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4015 u = r->upstream; |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4016 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
|
4017 |
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
4018 #if (NGX_HTTP_CACHE) |
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
4019 { |
2666 | 4020 time_t expires; |
4021 | |
2786
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4022 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
|
4023 return NGX_OK; |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4024 } |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4025 |
2666 | 4026 if (r->cache == NULL) { |
4027 return NGX_OK; | |
4028 } | |
4029 | |
4030 if (r->cache->valid_sec != 0) { | |
4031 return NGX_OK; | |
4032 } | |
4033 | |
4034 expires = ngx_http_parse_time(h->value.data, h->value.len); | |
4035 | |
4036 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
|
4037 u->cacheable = 0; |
2666 | 4038 return NGX_OK; |
4039 } | |
4040 | |
4041 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
|
4042 } |
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
4043 #endif |
2666 | 4044 |
4045 return NGX_OK; | |
4046 } | |
4047 | |
4048 | |
4049 static ngx_int_t | |
2663
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4050 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
|
4051 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
|
4052 { |
2786
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4053 ngx_http_upstream_t *u; |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4054 |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4055 u = r->upstream; |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4056 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
|
4057 |
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
4058 #if (NGX_HTTP_CACHE) |
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
4059 { |
2663
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4060 u_char *p; |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4061 size_t len; |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4062 ngx_int_t n; |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4063 |
2786
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4064 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
|
4065 return NGX_OK; |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4066 } |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4067 |
2663
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4068 if (r->cache == NULL) { |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4069 return NGX_OK; |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4070 } |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4071 |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4072 len = h->value.len; |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4073 p = h->value.data; |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4074 |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4075 if (p[0] != '@') { |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4076 n = ngx_atoi(p, len); |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4077 |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4078 switch (n) { |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4079 case 0: |
2786
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4080 u->cacheable = 0; |
4546
4988fa232629
For the sake of case/switch code readability, 'fall through'
Maxim Konovalov <maxim@nginx.com>
parents:
4499
diff
changeset
|
4081 /* fall through */ |
4988fa232629
For the sake of case/switch code readability, 'fall through'
Maxim Konovalov <maxim@nginx.com>
parents:
4499
diff
changeset
|
4082 |
2663
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4083 case NGX_ERROR: |
2667 | 4084 return NGX_OK; |
2663
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4085 |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4086 default: |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4087 r->cache->valid_sec = ngx_time() + n; |
2667 | 4088 return NGX_OK; |
2663
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4089 } |
2667 | 4090 } |
4091 | |
4092 p++; | |
4093 len--; | |
4094 | |
4095 n = ngx_atoi(p, len); | |
4096 | |
4097 if (n != NGX_ERROR) { | |
4098 r->cache->valid_sec = n; | |
2663
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4099 } |
2708
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
4100 } |
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
4101 #endif |
2663
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4102 |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4103 return NGX_OK; |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4104 } |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4105 |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4106 |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4107 static ngx_int_t |
527 | 4108 ngx_http_upstream_process_limit_rate(ngx_http_request_t *r, ngx_table_elt_t *h, |
4109 ngx_uint_t offset) | |
577 | 4110 { |
4197
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4111 ngx_int_t n; |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4112 ngx_http_upstream_t *u; |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4113 |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4114 u = r->upstream; |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4115 u->headers_in.x_accel_limit_rate = h; |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4116 |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4117 if (u->conf->ignore_headers & NGX_HTTP_UPSTREAM_IGN_XA_LIMIT_RATE) { |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4118 return NGX_OK; |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4119 } |
527 | 4120 |
4121 n = ngx_atoi(h->value.data, h->value.len); | |
4122 | |
4123 if (n != NGX_ERROR) { | |
4124 r->limit_rate = (size_t) n; | |
4125 } | |
4126 | |
4127 return NGX_OK; | |
4128 } | |
4129 | |
4130 | |
4131 static ngx_int_t | |
649 | 4132 ngx_http_upstream_process_buffering(ngx_http_request_t *r, ngx_table_elt_t *h, |
4133 ngx_uint_t offset) | |
4134 { | |
4197
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4135 u_char c0, c1, c2; |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4136 ngx_http_upstream_t *u; |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4137 |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4138 u = r->upstream; |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4139 |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4140 if (u->conf->ignore_headers & NGX_HTTP_UPSTREAM_IGN_XA_BUFFERING) { |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4141 return NGX_OK; |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4142 } |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4143 |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4144 if (u->conf->change_buffering) { |
649 | 4145 |
4146 if (h->value.len == 2) { | |
4147 c0 = ngx_tolower(h->value.data[0]); | |
4148 c1 = ngx_tolower(h->value.data[1]); | |
4149 | |
4150 if (c0 == 'n' && c1 == 'o') { | |
4197
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4151 u->buffering = 0; |
649 | 4152 } |
4153 | |
4154 } else if (h->value.len == 3) { | |
4155 c0 = ngx_tolower(h->value.data[0]); | |
4156 c1 = ngx_tolower(h->value.data[1]); | |
4157 c2 = ngx_tolower(h->value.data[2]); | |
4158 | |
4159 if (c0 == 'y' && c1 == 'e' && c2 == 's') { | |
4197
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4160 u->buffering = 1; |
649 | 4161 } |
4162 } | |
4163 } | |
4164 | |
4165 return NGX_OK; | |
4166 } | |
4167 | |
4168 | |
4169 static ngx_int_t | |
657 | 4170 ngx_http_upstream_process_charset(ngx_http_request_t *r, ngx_table_elt_t *h, |
4171 ngx_uint_t offset) | |
4172 { | |
4197
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4173 if (r->upstream->conf->ignore_headers & NGX_HTTP_UPSTREAM_IGN_XA_CHARSET) { |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4174 return NGX_OK; |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4175 } |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4176 |
657 | 4177 r->headers_out.override_charset = &h->value; |
4178 | |
4179 return NGX_OK; | |
4180 } | |
4181 | |
4182 | |
4183 static ngx_int_t | |
4124
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4184 ngx_http_upstream_process_connection(ngx_http_request_t *r, ngx_table_elt_t *h, |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4185 ngx_uint_t offset) |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4186 { |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4187 r->upstream->headers_in.connection = h; |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4188 |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4189 if (ngx_strlcasestrn(h->value.data, h->value.data + h->value.len, |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4190 (u_char *) "close", 5 - 1) |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4191 != NULL) |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4192 { |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4193 r->upstream->headers_in.connection_close = 1; |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4194 } |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4195 |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4196 return NGX_OK; |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4197 } |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4198 |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4199 |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4200 static ngx_int_t |
4123
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4201 ngx_http_upstream_process_transfer_encoding(ngx_http_request_t *r, |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4202 ngx_table_elt_t *h, ngx_uint_t offset) |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4203 { |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4204 r->upstream->headers_in.transfer_encoding = h; |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4205 |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4206 if (ngx_strlcasestrn(h->value.data, h->value.data + h->value.len, |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4207 (u_char *) "chunked", 7 - 1) |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4208 != NULL) |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4209 { |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4210 r->upstream->headers_in.chunked = 1; |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4211 } |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4212 |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4213 return NGX_OK; |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4214 } |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4215 |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4216 |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4217 static ngx_int_t |
5877
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4218 ngx_http_upstream_process_vary(ngx_http_request_t *r, |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4219 ngx_table_elt_t *h, ngx_uint_t offset) |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4220 { |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4221 ngx_http_upstream_t *u; |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4222 |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4223 u = r->upstream; |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4224 u->headers_in.vary = h; |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4225 |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4226 #if (NGX_HTTP_CACHE) |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4227 |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4228 if (u->conf->ignore_headers & NGX_HTTP_UPSTREAM_IGN_VARY) { |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4229 return NGX_OK; |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4230 } |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4231 |
5878
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5877
diff
changeset
|
4232 if (r->cache == NULL) { |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5877
diff
changeset
|
4233 return NGX_OK; |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5877
diff
changeset
|
4234 } |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5877
diff
changeset
|
4235 |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5877
diff
changeset
|
4236 if (h->value.len > NGX_HTTP_CACHE_VARY_LEN |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5877
diff
changeset
|
4237 || (h->value.len == 1 && h->value.data[0] == '*')) |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5877
diff
changeset
|
4238 { |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5877
diff
changeset
|
4239 u->cacheable = 0; |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5877
diff
changeset
|
4240 } |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5877
diff
changeset
|
4241 |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5877
diff
changeset
|
4242 r->cache->vary = h->value; |
5877
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4243 |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4244 #endif |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4245 |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4246 return NGX_OK; |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4247 } |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4248 |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4249 |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4250 static ngx_int_t |
509 | 4251 ngx_http_upstream_copy_header_line(ngx_http_request_t *r, ngx_table_elt_t *h, |
4252 ngx_uint_t offset) | |
4253 { | |
573 | 4254 ngx_table_elt_t *ho, **ph; |
509 | 4255 |
4256 ho = ngx_list_push(&r->headers_out.headers); | |
4257 if (ho == NULL) { | |
4258 return NGX_ERROR; | |
4259 } | |
4260 | |
4261 *ho = *h; | |
4262 | |
573 | 4263 if (offset) { |
4264 ph = (ngx_table_elt_t **) ((char *) &r->headers_out + offset); | |
4265 *ph = ho; | |
4266 } | |
4267 | |
509 | 4268 return NGX_OK; |
4269 } | |
4270 | |
4271 | |
4272 static ngx_int_t | |
4273 ngx_http_upstream_copy_multi_header_lines(ngx_http_request_t *r, | |
4274 ngx_table_elt_t *h, ngx_uint_t offset) | |
4275 { | |
4276 ngx_array_t *pa; | |
4277 ngx_table_elt_t *ho, **ph; | |
4278 | |
4279 pa = (ngx_array_t *) ((char *) &r->headers_out + offset); | |
4280 | |
4281 if (pa->elts == NULL) { | |
4282 if (ngx_array_init(pa, r->pool, 2, sizeof(ngx_table_elt_t *)) != NGX_OK) | |
4283 { | |
4284 return NGX_ERROR; | |
4285 } | |
4286 } | |
4287 | |
4288 ph = ngx_array_push(pa); | |
4289 if (ph == NULL) { | |
4290 return NGX_ERROR; | |
4291 } | |
4292 | |
4293 ho = ngx_list_push(&r->headers_out.headers); | |
4294 if (ho == NULL) { | |
4295 return NGX_ERROR; | |
4296 } | |
4297 | |
4298 *ho = *h; | |
4299 *ph = ho; | |
4300 | |
4301 return NGX_OK; | |
4302 } | |
4303 | |
4304 | |
4305 static ngx_int_t | |
4306 ngx_http_upstream_copy_content_type(ngx_http_request_t *r, ngx_table_elt_t *h, | |
4307 ngx_uint_t offset) | |
4308 { | |
657 | 4309 u_char *p, *last; |
4310 | |
4311 r->headers_out.content_type_len = h->value.len; | |
509 | 4312 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
|
4313 r->headers_out.content_type_lowcase = NULL; |
509 | 4314 |
657 | 4315 for (p = h->value.data; *p; p++) { |
4316 | |
4317 if (*p != ';') { | |
4318 continue; | |
4319 } | |
4320 | |
4321 last = p; | |
4322 | |
4323 while (*++p == ' ') { /* void */ } | |
4324 | |
1968 | 4325 if (*p == '\0') { |
4326 return NGX_OK; | |
4327 } | |
4328 | |
1107
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1098
diff
changeset
|
4329 if (ngx_strncasecmp(p, (u_char *) "charset=", 8) != 0) { |
657 | 4330 continue; |
4331 } | |
4332 | |
4333 p += 8; | |
4334 | |
4335 r->headers_out.content_type_len = last - h->value.data; | |
4336 | |
2244 | 4337 if (*p == '"') { |
4338 p++; | |
4339 } | |
4340 | |
4341 last = h->value.data + h->value.len; | |
4342 | |
4343 if (*(last - 1) == '"') { | |
4344 last--; | |
4345 } | |
4346 | |
4347 r->headers_out.charset.len = last - p; | |
657 | 4348 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
|
4349 |
c6c42497106c
fix segfault if upstream sends trailing ";" in "charset="
Igor Sysoev <igor@sysoev.ru>
parents:
1109
diff
changeset
|
4350 return NGX_OK; |
657 | 4351 } |
4352 | |
509 | 4353 return NGX_OK; |
4354 } | |
4355 | |
4356 | |
4357 static ngx_int_t | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4358 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
|
4359 ngx_uint_t offset) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4360 { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4361 ngx_table_elt_t *ho; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4362 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4363 ho = ngx_list_push(&r->headers_out.headers); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4364 if (ho == NULL) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4365 return NGX_ERROR; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4366 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4367 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4368 *ho = *h; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4369 |
3004
4121acaf7a04
fix handling "Last-Modified" and "Accept-Ranges" for upstream responses
Igor Sysoev <igor@sysoev.ru>
parents:
3003
diff
changeset
|
4370 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
|
4371 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4372 #if (NGX_HTTP_CACHE) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4373 |
2952 | 4374 if (r->upstream->cacheable) { |
5732
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
4375 r->headers_out.last_modified_time = |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
4376 r->upstream->headers_in.last_modified_time; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4377 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4378 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4379 #endif |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4380 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4381 return NGX_OK; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4382 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4383 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4384 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4385 static ngx_int_t |
509 | 4386 ngx_http_upstream_rewrite_location(ngx_http_request_t *r, ngx_table_elt_t *h, |
4387 ngx_uint_t offset) | |
4388 { | |
4389 ngx_int_t rc; | |
4390 ngx_table_elt_t *ho; | |
4391 | |
4392 ho = ngx_list_push(&r->headers_out.headers); | |
4393 if (ho == NULL) { | |
4394 return NGX_ERROR; | |
4395 } | |
4396 | |
4397 *ho = *h; | |
4398 | |
4399 if (r->upstream->rewrite_redirect) { | |
4400 rc = r->upstream->rewrite_redirect(r, ho, 0); | |
4401 | |
529 | 4402 if (rc == NGX_DECLINED) { |
4403 return NGX_OK; | |
4404 } | |
4405 | |
509 | 4406 if (rc == NGX_OK) { |
4407 r->headers_out.location = ho; | |
4408 | |
4409 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
4410 "rewritten location: \"%V\"", &ho->value); | |
4411 } | |
4412 | |
4413 return rc; | |
4414 } | |
4415 | |
1653
ea681a6a0c61
set r->headers_out.location for non-local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
4416 if (ho->value.data[0] != '/') { |
ea681a6a0c61
set r->headers_out.location for non-local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
4417 r->headers_out.location = ho; |
ea681a6a0c61
set r->headers_out.location for non-local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
4418 } |
ea681a6a0c61
set r->headers_out.location for non-local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
4419 |
509 | 4420 /* |
4421 * we do not set r->headers_out.location here to avoid the handling | |
4422 * the local redirects without a host name by ngx_http_header_filter() | |
4423 */ | |
4424 | |
4425 return NGX_OK; | |
4426 } | |
4427 | |
4428 | |
4429 static ngx_int_t | |
4430 ngx_http_upstream_rewrite_refresh(ngx_http_request_t *r, ngx_table_elt_t *h, | |
4431 ngx_uint_t offset) | |
4432 { | |
4433 u_char *p; | |
4434 ngx_int_t rc; | |
4435 ngx_table_elt_t *ho; | |
4436 | |
4437 ho = ngx_list_push(&r->headers_out.headers); | |
4438 if (ho == NULL) { | |
4439 return NGX_ERROR; | |
4440 } | |
4441 | |
4442 *ho = *h; | |
4443 | |
4444 if (r->upstream->rewrite_redirect) { | |
4445 | |
1549 | 4446 p = ngx_strcasestrn(ho->value.data, "url=", 4 - 1); |
509 | 4447 |
4448 if (p) { | |
4449 rc = r->upstream->rewrite_redirect(r, ho, p + 4 - ho->value.data); | |
4450 | |
4451 } else { | |
4452 return NGX_OK; | |
4453 } | |
4454 | |
529 | 4455 if (rc == NGX_DECLINED) { |
4456 return NGX_OK; | |
4457 } | |
4458 | |
509 | 4459 if (rc == NGX_OK) { |
1654 | 4460 r->headers_out.refresh = ho; |
4461 | |
509 | 4462 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
4463 "rewritten refresh: \"%V\"", &ho->value); | |
4464 } | |
4465 | |
4466 return rc; | |
4467 } | |
4468 | |
1654 | 4469 r->headers_out.refresh = ho; |
4470 | |
509 | 4471 return NGX_OK; |
4472 } | |
4473 | |
4474 | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4475 static ngx_int_t |
4464
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
4476 ngx_http_upstream_rewrite_set_cookie(ngx_http_request_t *r, ngx_table_elt_t *h, |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
4477 ngx_uint_t offset) |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
4478 { |
4650
b38fea6f9a15
Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents:
4572
diff
changeset
|
4479 ngx_int_t rc; |
4464
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
4480 ngx_table_elt_t *ho; |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
4481 |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
4482 ho = ngx_list_push(&r->headers_out.headers); |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
4483 if (ho == NULL) { |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
4484 return NGX_ERROR; |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
4485 } |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
4486 |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
4487 *ho = *h; |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
4488 |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
4489 if (r->upstream->rewrite_cookie) { |
4650
b38fea6f9a15
Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents:
4572
diff
changeset
|
4490 rc = r->upstream->rewrite_cookie(r, ho); |
b38fea6f9a15
Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents:
4572
diff
changeset
|
4491 |
b38fea6f9a15
Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents:
4572
diff
changeset
|
4492 if (rc == NGX_DECLINED) { |
b38fea6f9a15
Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents:
4572
diff
changeset
|
4493 return NGX_OK; |
b38fea6f9a15
Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents:
4572
diff
changeset
|
4494 } |
b38fea6f9a15
Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents:
4572
diff
changeset
|
4495 |
b38fea6f9a15
Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents:
4572
diff
changeset
|
4496 #if (NGX_DEBUG) |
b38fea6f9a15
Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents:
4572
diff
changeset
|
4497 if (rc == NGX_OK) { |
b38fea6f9a15
Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents:
4572
diff
changeset
|
4498 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
b38fea6f9a15
Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents:
4572
diff
changeset
|
4499 "rewritten cookie: \"%V\"", &ho->value); |
b38fea6f9a15
Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents:
4572
diff
changeset
|
4500 } |
b38fea6f9a15
Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents:
4572
diff
changeset
|
4501 #endif |
b38fea6f9a15
Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents:
4572
diff
changeset
|
4502 |
b38fea6f9a15
Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents:
4572
diff
changeset
|
4503 return rc; |
4464
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
4504 } |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
4505 |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
4506 return NGX_OK; |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
4507 } |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
4508 |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
4509 |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
4510 static ngx_int_t |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4511 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
|
4512 ngx_table_elt_t *h, ngx_uint_t offset) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4513 { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4514 ngx_table_elt_t *ho; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4515 |
5874
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
4516 if (r->upstream->conf->force_ranges) { |
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
4517 return NGX_OK; |
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
4518 } |
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
4519 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4520 #if (NGX_HTTP_CACHE) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4521 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4522 if (r->cached) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4523 r->allow_ranges = 1; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4524 return NGX_OK; |
5621
345e4fd4bb64
Range filter: single_range flag in request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5581
diff
changeset
|
4525 } |
345e4fd4bb64
Range filter: single_range flag in request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5581
diff
changeset
|
4526 |
345e4fd4bb64
Range filter: single_range flag in request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5581
diff
changeset
|
4527 if (r->upstream->cacheable) { |
345e4fd4bb64
Range filter: single_range flag in request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5581
diff
changeset
|
4528 r->allow_ranges = 1; |
345e4fd4bb64
Range filter: single_range flag in request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5581
diff
changeset
|
4529 r->single_range = 1; |
345e4fd4bb64
Range filter: single_range flag in request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5581
diff
changeset
|
4530 return NGX_OK; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4531 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4532 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4533 #endif |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4534 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4535 ho = ngx_list_push(&r->headers_out.headers); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4536 if (ho == NULL) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4537 return NGX_ERROR; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4538 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4539 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4540 *ho = *h; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4541 |
3004
4121acaf7a04
fix handling "Last-Modified" and "Accept-Ranges" for upstream responses
Igor Sysoev <igor@sysoev.ru>
parents:
3003
diff
changeset
|
4542 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
|
4543 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4544 return NGX_OK; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4545 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4546 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4547 |
509 | 4548 #if (NGX_HTTP_GZIP) |
4549 | |
4550 static ngx_int_t | |
4551 ngx_http_upstream_copy_content_encoding(ngx_http_request_t *r, | |
4552 ngx_table_elt_t *h, ngx_uint_t offset) | |
4553 { | |
4554 ngx_table_elt_t *ho; | |
4555 | |
4556 ho = ngx_list_push(&r->headers_out.headers); | |
4557 if (ho == NULL) { | |
4558 return NGX_ERROR; | |
4559 } | |
4560 | |
4561 *ho = *h; | |
4562 | |
4563 r->headers_out.content_encoding = ho; | |
4564 | |
4565 return NGX_OK; | |
4566 } | |
4567 | |
4568 #endif | |
4569 | |
4570 | |
487 | 4571 static ngx_int_t |
573 | 4572 ngx_http_upstream_add_variables(ngx_conf_t *cf) |
479 | 4573 { |
880 | 4574 ngx_http_variable_t *var, *v; |
479 | 4575 |
573 | 4576 for (v = ngx_http_upstream_vars; v->name.len; v++) { |
4577 var = ngx_http_add_variable(cf, &v->name, v->flags); | |
4578 if (var == NULL) { | |
4579 return NGX_ERROR; | |
4580 } | |
4581 | |
637 | 4582 var->get_handler = v->get_handler; |
573 | 4583 var->data = v->data; |
4584 } | |
4585 | |
479 | 4586 return NGX_OK; |
4587 } | |
509 | 4588 |
4589 | |
573 | 4590 static ngx_int_t |
1181 | 4591 ngx_http_upstream_addr_variable(ngx_http_request_t *r, |
4592 ngx_http_variable_value_t *v, uintptr_t data) | |
4593 { | |
4594 u_char *p; | |
4595 size_t len; | |
4596 ngx_uint_t i; | |
4597 ngx_http_upstream_state_t *state; | |
4598 | |
4599 v->valid = 1; | |
1565 | 4600 v->no_cacheable = 0; |
1181 | 4601 v->not_found = 0; |
4602 | |
4603 if (r->upstream_states == NULL || r->upstream_states->nelts == 0) { | |
4604 v->not_found = 1; | |
4605 return NGX_OK; | |
4606 } | |
4607 | |
4608 len = 0; | |
4609 state = r->upstream_states->elts; | |
4610 | |
4611 for (i = 0; i < r->upstream_states->nelts; i++) { | |
4612 if (state[i].peer) { | |
4613 len += state[i].peer->len + 2; | |
4614 | |
4615 } else { | |
4616 len += 3; | |
4617 } | |
4618 } | |
4619 | |
2049 | 4620 p = ngx_pnalloc(r->pool, len); |
1181 | 4621 if (p == NULL) { |
4622 return NGX_ERROR; | |
4623 } | |
4624 | |
4625 v->data = p; | |
4626 | |
4627 i = 0; | |
4628 | |
4629 for ( ;; ) { | |
4630 if (state[i].peer) { | |
4631 p = ngx_cpymem(p, state[i].peer->data, state[i].peer->len); | |
4632 } | |
4633 | |
4634 if (++i == r->upstream_states->nelts) { | |
4635 break; | |
4636 } | |
4637 | |
4638 if (state[i].peer) { | |
4639 *p++ = ','; | |
4640 *p++ = ' '; | |
4641 | |
4642 } else { | |
4643 *p++ = ' '; | |
4644 *p++ = ':'; | |
4645 *p++ = ' '; | |
4646 | |
4647 if (++i == r->upstream_states->nelts) { | |
4648 break; | |
4649 } | |
4650 | |
4651 continue; | |
4652 } | |
4653 } | |
4654 | |
4655 v->len = p - v->data; | |
4656 | |
4657 return NGX_OK; | |
4658 } | |
4659 | |
4660 | |
4661 static ngx_int_t | |
573 | 4662 ngx_http_upstream_status_variable(ngx_http_request_t *r, |
4663 ngx_http_variable_value_t *v, uintptr_t data) | |
4664 { | |
4665 u_char *p; | |
4666 size_t len; | |
4667 ngx_uint_t i; | |
4668 ngx_http_upstream_state_t *state; | |
4669 | |
4670 v->valid = 1; | |
1565 | 4671 v->no_cacheable = 0; |
573 | 4672 v->not_found = 0; |
4673 | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
4674 if (r->upstream_states == NULL || r->upstream_states->nelts == 0) { |
573 | 4675 v->not_found = 1; |
4676 return NGX_OK; | |
4677 } | |
4678 | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
4679 len = r->upstream_states->nelts * (3 + 2); |
573 | 4680 |
2049 | 4681 p = ngx_pnalloc(r->pool, len); |
573 | 4682 if (p == NULL) { |
4683 return NGX_ERROR; | |
4684 } | |
4685 | |
4686 v->data = p; | |
4687 | |
4688 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
|
4689 state = r->upstream_states->elts; |
573 | 4690 |
4691 for ( ;; ) { | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
4692 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
|
4693 p = ngx_sprintf(p, "%ui", state[i].status); |
573 | 4694 |
4695 } else { | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
4696 *p++ = '-'; |
573 | 4697 } |
4698 | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
4699 if (++i == r->upstream_states->nelts) { |
573 | 4700 break; |
4701 } | |
4702 | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
4703 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
|
4704 *p++ = ','; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
4705 *p++ = ' '; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
4706 |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
4707 } else { |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
4708 *p++ = ' '; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
4709 *p++ = ':'; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
4710 *p++ = ' '; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
4711 |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
4712 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
|
4713 break; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
4714 } |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
4715 |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
4716 continue; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
4717 } |
573 | 4718 } |
4719 | |
4720 v->len = p - v->data; | |
4721 | |
4722 return NGX_OK; | |
4723 } | |
4724 | |
4725 | |
4726 static ngx_int_t | |
4727 ngx_http_upstream_response_time_variable(ngx_http_request_t *r, | |
4728 ngx_http_variable_value_t *v, uintptr_t data) | |
4729 { | |
4730 u_char *p; | |
4731 size_t len; | |
4732 ngx_uint_t i; | |
889
a9a7e4b1a72b
the previous fix does not actually fix overflow
Igor Sysoev <igor@sysoev.ru>
parents:
888
diff
changeset
|
4733 ngx_msec_int_t ms; |
573 | 4734 ngx_http_upstream_state_t *state; |
4735 | |
4736 v->valid = 1; | |
1565 | 4737 v->no_cacheable = 0; |
573 | 4738 v->not_found = 0; |
4739 | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
4740 if (r->upstream_states == NULL || r->upstream_states->nelts == 0) { |
573 | 4741 v->not_found = 1; |
4742 return NGX_OK; | |
4743 } | |
4744 | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
4745 len = r->upstream_states->nelts * (NGX_TIME_T_LEN + 4 + 2); |
573 | 4746 |
2049 | 4747 p = ngx_pnalloc(r->pool, len); |
573 | 4748 if (p == NULL) { |
4749 return NGX_ERROR; | |
4750 } | |
4751 | |
4752 v->data = p; | |
4753 | |
4754 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
|
4755 state = r->upstream_states->elts; |
573 | 4756 |
4757 for ( ;; ) { | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
4758 if (state[i].status) { |
1640 | 4759 ms = (ngx_msec_int_t) |
4760 (state[i].response_sec * 1000 + state[i].response_msec); | |
3515 | 4761 ms = ngx_max(ms, 0); |
5368
cd46297325bd
Upstream: fixed $upstream_response_time format specifiers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5353
diff
changeset
|
4762 p = ngx_sprintf(p, "%T.%03M", (time_t) 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
|
4763 |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
4764 } else { |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
4765 *p++ = '-'; |
573 | 4766 } |
4767 | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
4768 if (++i == r->upstream_states->nelts) { |
573 | 4769 break; |
4770 } | |
4771 | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
4772 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
|
4773 *p++ = ','; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
4774 *p++ = ' '; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
4775 |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
4776 } else { |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
4777 *p++ = ' '; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
4778 *p++ = ':'; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
4779 *p++ = ' '; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
4780 |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
4781 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
|
4782 break; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
4783 } |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
4784 |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
4785 continue; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
4786 } |
573 | 4787 } |
4788 | |
4789 v->len = p - v->data; | |
4790 | |
4791 return NGX_OK; | |
4792 } | |
4793 | |
4794 | |
2402 | 4795 static ngx_int_t |
4796 ngx_http_upstream_response_length_variable(ngx_http_request_t *r, | |
4797 ngx_http_variable_value_t *v, uintptr_t data) | |
4798 { | |
4799 u_char *p; | |
4800 size_t len; | |
4801 ngx_uint_t i; | |
4802 ngx_http_upstream_state_t *state; | |
4803 | |
4804 v->valid = 1; | |
4805 v->no_cacheable = 0; | |
4806 v->not_found = 0; | |
4807 | |
4808 if (r->upstream_states == NULL || r->upstream_states->nelts == 0) { | |
4809 v->not_found = 1; | |
4810 return NGX_OK; | |
4811 } | |
4812 | |
4813 len = r->upstream_states->nelts * (NGX_OFF_T_LEN + 2); | |
4814 | |
4815 p = ngx_pnalloc(r->pool, len); | |
4816 if (p == NULL) { | |
4817 return NGX_ERROR; | |
4818 } | |
4819 | |
4820 v->data = p; | |
4821 | |
4822 i = 0; | |
4823 state = r->upstream_states->elts; | |
4824 | |
4825 for ( ;; ) { | |
4826 p = ngx_sprintf(p, "%O", state[i].response_length); | |
4827 | |
4828 if (++i == r->upstream_states->nelts) { | |
4829 break; | |
4830 } | |
4831 | |
4832 if (state[i].peer) { | |
4833 *p++ = ','; | |
4834 *p++ = ' '; | |
4835 | |
4836 } else { | |
4837 *p++ = ' '; | |
4838 *p++ = ':'; | |
4839 *p++ = ' '; | |
4840 | |
4841 if (++i == r->upstream_states->nelts) { | |
4842 break; | |
4843 } | |
4844 | |
4845 continue; | |
4846 } | |
4847 } | |
4848 | |
4849 v->len = p - v->data; | |
4850 | |
4851 return NGX_OK; | |
4852 } | |
4853 | |
4854 | |
1162 | 4855 ngx_int_t |
4856 ngx_http_upstream_header_variable(ngx_http_request_t *r, | |
4857 ngx_http_variable_value_t *v, uintptr_t data) | |
4858 { | |
4859 if (r->upstream == NULL) { | |
4860 v->not_found = 1; | |
4861 return NGX_OK; | |
4862 } | |
4863 | |
4864 return ngx_http_variable_unknown_header(v, (ngx_str_t *) data, | |
4865 &r->upstream->headers_in.headers.part, | |
4866 sizeof("upstream_http_") - 1); | |
4867 } | |
4868 | |
4869 | |
5677
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4870 ngx_int_t |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4871 ngx_http_upstream_cookie_variable(ngx_http_request_t *r, |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4872 ngx_http_variable_value_t *v, uintptr_t data) |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4873 { |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4874 ngx_str_t *name = (ngx_str_t *) data; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4875 |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4876 ngx_str_t cookie, s; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4877 |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4878 if (r->upstream == NULL) { |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4879 v->not_found = 1; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4880 return NGX_OK; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4881 } |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4882 |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4883 s.len = name->len - (sizeof("upstream_cookie_") - 1); |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4884 s.data = name->data + sizeof("upstream_cookie_") - 1; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4885 |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4886 if (ngx_http_parse_set_cookie_lines(&r->upstream->headers_in.cookies, |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4887 &s, &cookie) |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4888 == NGX_DECLINED) |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4889 { |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4890 v->not_found = 1; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4891 return NGX_OK; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4892 } |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4893 |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4894 v->len = cookie.len; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4895 v->valid = 1; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4896 v->no_cacheable = 0; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4897 v->not_found = 0; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4898 v->data = cookie.data; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4899 |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4900 return NGX_OK; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4901 } |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4902 |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4903 |
2952 | 4904 #if (NGX_HTTP_CACHE) |
4905 | |
4906 ngx_int_t | |
4907 ngx_http_upstream_cache_status(ngx_http_request_t *r, | |
4908 ngx_http_variable_value_t *v, uintptr_t data) | |
4909 { | |
4910 ngx_uint_t n; | |
4911 | |
4912 if (r->upstream == NULL || r->upstream->cache_status == 0) { | |
4913 v->not_found = 1; | |
4914 return NGX_OK; | |
4915 } | |
4916 | |
4917 n = r->upstream->cache_status - 1; | |
4918 | |
4919 v->valid = 1; | |
4920 v->no_cacheable = 0; | |
4921 v->not_found = 0; | |
4922 v->len = ngx_http_cache_status[n].len; | |
4923 v->data = ngx_http_cache_status[n].data; | |
4924 | |
4925 return NGX_OK; | |
4926 } | |
4927 | |
5441
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
4928 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
4929 static ngx_int_t |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
4930 ngx_http_upstream_cache_last_modified(ngx_http_request_t *r, |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
4931 ngx_http_variable_value_t *v, uintptr_t data) |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
4932 { |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
4933 u_char *p; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
4934 |
5453
b7b8e2fa7ebd
Fixed null pointer dereference with $upstream_cache_last_modified.
Ruslan Ermilov <ru@nginx.com>
parents:
5441
diff
changeset
|
4935 if (r->upstream == NULL |
b7b8e2fa7ebd
Fixed null pointer dereference with $upstream_cache_last_modified.
Ruslan Ermilov <ru@nginx.com>
parents:
5441
diff
changeset
|
4936 || !r->upstream->conf->cache_revalidate |
5441
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
4937 || r->upstream->cache_status != NGX_HTTP_CACHE_EXPIRED |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
4938 || r->cache->last_modified == -1) |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
4939 { |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
4940 v->not_found = 1; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
4941 return NGX_OK; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
4942 } |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
4943 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
4944 p = ngx_pnalloc(r->pool, sizeof("Mon, 28 Sep 1970 06:00:00 GMT") - 1); |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
4945 if (p == NULL) { |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
4946 return NGX_ERROR; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
4947 } |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
4948 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
4949 v->len = ngx_http_time(p, r->cache->last_modified) - p; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
4950 v->valid = 1; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
4951 v->no_cacheable = 0; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
4952 v->not_found = 0; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
4953 v->data = p; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
4954 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
4955 return NGX_OK; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
4956 } |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
4957 |
5738
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
4958 |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
4959 static ngx_int_t |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
4960 ngx_http_upstream_cache_etag(ngx_http_request_t *r, |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
4961 ngx_http_variable_value_t *v, uintptr_t data) |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
4962 { |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
4963 if (r->upstream == NULL |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
4964 || !r->upstream->conf->cache_revalidate |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
4965 || r->upstream->cache_status != NGX_HTTP_CACHE_EXPIRED |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
4966 || r->cache->etag.len == 0) |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
4967 { |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
4968 v->not_found = 1; |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
4969 return NGX_OK; |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
4970 } |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
4971 |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
4972 v->valid = 1; |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
4973 v->no_cacheable = 0; |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
4974 v->not_found = 0; |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
4975 v->len = r->cache->etag.len; |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
4976 v->data = r->cache->etag.data; |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
4977 |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
4978 return NGX_OK; |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
4979 } |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
4980 |
2952 | 4981 #endif |
4982 | |
4983 | |
651 | 4984 static char * |
4985 ngx_http_upstream(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy) | |
4986 { | |
884 | 4987 char *rv; |
4988 void *mconf; | |
4989 ngx_str_t *value; | |
4990 ngx_url_t u; | |
4991 ngx_uint_t m; | |
4992 ngx_conf_t pcf; | |
4993 ngx_http_module_t *module; | |
4994 ngx_http_conf_ctx_t *ctx, *http_ctx; | |
4995 ngx_http_upstream_srv_conf_t *uscf; | |
4996 | |
4997 ngx_memzero(&u, sizeof(ngx_url_t)); | |
4998 | |
4999 value = cf->args->elts; | |
5000 u.host = value[1]; | |
5001 u.no_resolve = 1; | |
5005
c9059bd5445b
Fixed "proxy_pass" with IP address and no port (ticket #276).
Ruslan Ermilov <ru@nginx.com>
parents:
4990
diff
changeset
|
5002 u.no_port = 1; |
884 | 5003 |
5004 uscf = ngx_http_upstream_add(cf, &u, NGX_HTTP_UPSTREAM_CREATE | |
5005 |NGX_HTTP_UPSTREAM_WEIGHT | |
5006 |NGX_HTTP_UPSTREAM_MAX_FAILS | |
5007 |NGX_HTTP_UPSTREAM_FAIL_TIMEOUT | |
5008 |NGX_HTTP_UPSTREAM_DOWN | |
5009 |NGX_HTTP_UPSTREAM_BACKUP); | |
5010 if (uscf == NULL) { | |
5011 return NGX_CONF_ERROR; | |
5012 } | |
5013 | |
651 | 5014 |
5015 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)); | |
5016 if (ctx == NULL) { | |
5017 return NGX_CONF_ERROR; | |
5018 } | |
5019 | |
884 | 5020 http_ctx = cf->ctx; |
5021 ctx->main_conf = http_ctx->main_conf; | |
651 | 5022 |
5023 /* the upstream{}'s srv_conf */ | |
5024 | |
5025 ctx->srv_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module); | |
5026 if (ctx->srv_conf == NULL) { | |
5027 return NGX_CONF_ERROR; | |
5028 } | |
5029 | |
5030 ctx->srv_conf[ngx_http_upstream_module.ctx_index] = uscf; | |
5031 | |
884 | 5032 uscf->srv_conf = ctx->srv_conf; |
5033 | |
651 | 5034 |
5035 /* the upstream{}'s loc_conf */ | |
5036 | |
5037 ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module); | |
5038 if (ctx->loc_conf == NULL) { | |
5039 return NGX_CONF_ERROR; | |
5040 } | |
5041 | |
5042 for (m = 0; ngx_modules[m]; m++) { | |
5043 if (ngx_modules[m]->type != NGX_HTTP_MODULE) { | |
5044 continue; | |
5045 } | |
5046 | |
5047 module = ngx_modules[m]->ctx; | |
5048 | |
884 | 5049 if (module->create_srv_conf) { |
5050 mconf = module->create_srv_conf(cf); | |
5051 if (mconf == NULL) { | |
5052 return NGX_CONF_ERROR; | |
5053 } | |
5054 | |
5055 ctx->srv_conf[ngx_modules[m]->ctx_index] = mconf; | |
5056 } | |
5057 | |
651 | 5058 if (module->create_loc_conf) { |
5059 mconf = module->create_loc_conf(cf); | |
5060 if (mconf == NULL) { | |
5061 return NGX_CONF_ERROR; | |
5062 } | |
5063 | |
5064 ctx->loc_conf[ngx_modules[m]->ctx_index] = mconf; | |
5065 } | |
5066 } | |
5067 | |
5728
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5068 uscf->servers = ngx_array_create(cf->pool, 4, |
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5069 sizeof(ngx_http_upstream_server_t)); |
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5070 if (uscf->servers == NULL) { |
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5071 return NGX_CONF_ERROR; |
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5072 } |
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5073 |
651 | 5074 |
5075 /* parse inside upstream{} */ | |
5076 | |
5077 pcf = *cf; | |
5078 cf->ctx = ctx; | |
5079 cf->cmd_type = NGX_HTTP_UPS_CONF; | |
5080 | |
5081 rv = ngx_conf_parse(cf, NULL); | |
5082 | |
5083 *cf = pcf; | |
5084 | |
5085 if (rv != NGX_CONF_OK) { | |
5086 return rv; | |
5087 } | |
5088 | |
5728
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5089 if (uscf->servers->nelts == 0) { |
651 | 5090 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
5091 "no servers are inside upstream"); | |
5092 return NGX_CONF_ERROR; | |
5093 } | |
5094 | |
5095 return rv; | |
5096 } | |
5097 | |
5098 | |
5099 static char * | |
5100 ngx_http_upstream_server(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
5101 { | |
5102 ngx_http_upstream_srv_conf_t *uscf = conf; | |
5103 | |
884 | 5104 time_t fail_timeout; |
5105 ngx_str_t *value, s; | |
5106 ngx_url_t u; | |
5107 ngx_int_t weight, max_fails; | |
5108 ngx_uint_t i; | |
5109 ngx_http_upstream_server_t *us; | |
651 | 5110 |
884 | 5111 us = ngx_array_push(uscf->servers); |
5112 if (us == NULL) { | |
651 | 5113 return NGX_CONF_ERROR; |
5114 } | |
5115 | |
884 | 5116 ngx_memzero(us, sizeof(ngx_http_upstream_server_t)); |
5117 | |
651 | 5118 value = cf->args->elts; |
5119 | |
663 | 5120 weight = 1; |
884 | 5121 max_fails = 1; |
5122 fail_timeout = 10; | |
5123 | |
5124 for (i = 2; i < cf->args->nelts; i++) { | |
5125 | |
5126 if (ngx_strncmp(value[i].data, "weight=", 7) == 0) { | |
5127 | |
5128 if (!(uscf->flags & NGX_HTTP_UPSTREAM_WEIGHT)) { | |
5818
fe8bafab5b49
Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents:
5774
diff
changeset
|
5129 goto not_supported; |
884 | 5130 } |
5131 | |
5132 weight = ngx_atoi(&value[i].data[7], value[i].len - 7); | |
663 | 5133 |
5134 if (weight == NGX_ERROR || weight == 0) { | |
5135 goto invalid; | |
5136 } | |
5137 | |
884 | 5138 continue; |
5139 } | |
5140 | |
5141 if (ngx_strncmp(value[i].data, "max_fails=", 10) == 0) { | |
5142 | |
5143 if (!(uscf->flags & NGX_HTTP_UPSTREAM_MAX_FAILS)) { | |
5818
fe8bafab5b49
Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents:
5774
diff
changeset
|
5144 goto not_supported; |
884 | 5145 } |
5146 | |
5147 max_fails = ngx_atoi(&value[i].data[10], value[i].len - 10); | |
5148 | |
5149 if (max_fails == NGX_ERROR) { | |
5150 goto invalid; | |
5151 } | |
5152 | |
5153 continue; | |
663 | 5154 } |
884 | 5155 |
5156 if (ngx_strncmp(value[i].data, "fail_timeout=", 13) == 0) { | |
5157 | |
5158 if (!(uscf->flags & NGX_HTTP_UPSTREAM_FAIL_TIMEOUT)) { | |
5818
fe8bafab5b49
Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents:
5774
diff
changeset
|
5159 goto not_supported; |
884 | 5160 } |
5161 | |
5162 s.len = value[i].len - 13; | |
5163 s.data = &value[i].data[13]; | |
5164 | |
5165 fail_timeout = ngx_parse_time(&s, 1); | |
5166 | |
4474 | 5167 if (fail_timeout == (time_t) NGX_ERROR) { |
884 | 5168 goto invalid; |
5169 } | |
5170 | |
5171 continue; | |
5172 } | |
5173 | |
5410
16b68c724438
Upstream: fixed "down" and "backup" parsing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5392
diff
changeset
|
5174 if (ngx_strcmp(value[i].data, "backup") == 0) { |
1378 | 5175 |
5176 if (!(uscf->flags & NGX_HTTP_UPSTREAM_BACKUP)) { | |
5818
fe8bafab5b49
Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents:
5774
diff
changeset
|
5177 goto not_supported; |
1378 | 5178 } |
5179 | |
5180 us->backup = 1; | |
5181 | |
5182 continue; | |
5183 } | |
5184 | |
5410
16b68c724438
Upstream: fixed "down" and "backup" parsing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5392
diff
changeset
|
5185 if (ngx_strcmp(value[i].data, "down") == 0) { |
884 | 5186 |
5187 if (!(uscf->flags & NGX_HTTP_UPSTREAM_DOWN)) { | |
5818
fe8bafab5b49
Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents:
5774
diff
changeset
|
5188 goto not_supported; |
884 | 5189 } |
5190 | |
5191 us->down = 1; | |
5192 | |
5193 continue; | |
5194 } | |
5195 | |
5196 goto invalid; | |
663 | 5197 } |
5198 | |
5728
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5199 ngx_memzero(&u, sizeof(ngx_url_t)); |
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5200 |
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5201 u.url = value[1]; |
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5202 u.default_port = 80; |
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5203 |
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5204 if (ngx_parse_url(cf->pool, &u) != NGX_OK) { |
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5205 if (u.err) { |
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5206 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5207 "%s in upstream \"%V\"", u.err, &u.url); |
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5208 } |
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5209 |
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5210 return NGX_CONF_ERROR; |
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5211 } |
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5212 |
5717
efc84a5723b3
Upstream: generic hash module.
Roman Arutyunyan <arut@nginx.com>
parents:
5682
diff
changeset
|
5213 us->name = u.url; |
884 | 5214 us->addrs = u.addrs; |
5215 us->naddrs = u.naddrs; | |
5216 us->weight = weight; | |
5217 us->max_fails = max_fails; | |
5218 us->fail_timeout = fail_timeout; | |
651 | 5219 |
5220 return NGX_CONF_OK; | |
663 | 5221 |
5222 invalid: | |
5223 | |
884 | 5224 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
5225 "invalid parameter \"%V\"", &value[i]); | |
663 | 5226 |
5227 return NGX_CONF_ERROR; | |
5818
fe8bafab5b49
Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents:
5774
diff
changeset
|
5228 |
fe8bafab5b49
Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents:
5774
diff
changeset
|
5229 not_supported: |
fe8bafab5b49
Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents:
5774
diff
changeset
|
5230 |
fe8bafab5b49
Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents:
5774
diff
changeset
|
5231 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
fe8bafab5b49
Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents:
5774
diff
changeset
|
5232 "balancing method does not support parameter \"%V\"", |
fe8bafab5b49
Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents:
5774
diff
changeset
|
5233 &value[i]); |
fe8bafab5b49
Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents:
5774
diff
changeset
|
5234 |
fe8bafab5b49
Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents:
5774
diff
changeset
|
5235 return NGX_CONF_ERROR; |
651 | 5236 } |
5237 | |
5238 | |
5239 ngx_http_upstream_srv_conf_t * | |
884 | 5240 ngx_http_upstream_add(ngx_conf_t *cf, ngx_url_t *u, ngx_uint_t flags) |
651 | 5241 { |
5242 ngx_uint_t i; | |
884 | 5243 ngx_http_upstream_server_t *us; |
651 | 5244 ngx_http_upstream_srv_conf_t *uscf, **uscfp; |
5245 ngx_http_upstream_main_conf_t *umcf; | |
5246 | |
884 | 5247 if (!(flags & NGX_HTTP_UPSTREAM_CREATE)) { |
5248 | |
1559
fe11e2a3946d
use pool instead of ngx_conf_t
Igor Sysoev <igor@sysoev.ru>
parents:
1558
diff
changeset
|
5249 if (ngx_parse_url(cf->pool, u) != NGX_OK) { |
651 | 5250 if (u->err) { |
5251 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
5252 "%s in upstream \"%V\"", u->err, &u->url); | |
5253 } | |
5254 | |
5255 return NULL; | |
5256 } | |
5257 } | |
5258 | |
5259 umcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_upstream_module); | |
5260 | |
5261 uscfp = umcf->upstreams.elts; | |
5262 | |
5263 for (i = 0; i < umcf->upstreams.nelts; i++) { | |
906 | 5264 |
5265 if (uscfp[i]->host.len != u->host.len | |
884 | 5266 || ngx_strncasecmp(uscfp[i]->host.data, u->host.data, u->host.len) |
5267 != 0) | |
5268 { | |
651 | 5269 continue; |
5270 } | |
5271 | |
884 | 5272 if ((flags & NGX_HTTP_UPSTREAM_CREATE) |
5273 && (uscfp[i]->flags & NGX_HTTP_UPSTREAM_CREATE)) | |
651 | 5274 { |
884 | 5275 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
5276 "duplicate upstream \"%V\"", &u->host); | |
5277 return NULL; | |
651 | 5278 } |
884 | 5279 |
5005
c9059bd5445b
Fixed "proxy_pass" with IP address and no port (ticket #276).
Ruslan Ermilov <ru@nginx.com>
parents:
4990
diff
changeset
|
5280 if ((uscfp[i]->flags & NGX_HTTP_UPSTREAM_CREATE) && !u->no_port) { |
884 | 5281 ngx_conf_log_error(NGX_LOG_WARN, cf, 0, |
906 | 5282 "upstream \"%V\" may not have port %d", |
5283 &u->host, u->port); | |
5284 return NULL; | |
5285 } | |
5286 | |
5005
c9059bd5445b
Fixed "proxy_pass" with IP address and no port (ticket #276).
Ruslan Ermilov <ru@nginx.com>
parents:
4990
diff
changeset
|
5287 if ((flags & NGX_HTTP_UPSTREAM_CREATE) && !uscfp[i]->no_port) { |
906 | 5288 ngx_log_error(NGX_LOG_WARN, cf->log, 0, |
5289 "upstream \"%V\" may not have port %d in %s:%ui", | |
5290 &u->host, uscfp[i]->port, | |
1489
56f1ea5baabb
u_char* is enough to keep file name
Igor Sysoev <igor@sysoev.ru>
parents:
1469
diff
changeset
|
5291 uscfp[i]->file_name, uscfp[i]->line); |
906 | 5292 return NULL; |
5293 } | |
5294 | |
5005
c9059bd5445b
Fixed "proxy_pass" with IP address and no port (ticket #276).
Ruslan Ermilov <ru@nginx.com>
parents:
4990
diff
changeset
|
5295 if (uscfp[i]->port && u->port |
c9059bd5445b
Fixed "proxy_pass" with IP address and no port (ticket #276).
Ruslan Ermilov <ru@nginx.com>
parents:
4990
diff
changeset
|
5296 && uscfp[i]->port != u->port) |
c9059bd5445b
Fixed "proxy_pass" with IP address and no port (ticket #276).
Ruslan Ermilov <ru@nginx.com>
parents:
4990
diff
changeset
|
5297 { |
906 | 5298 continue; |
884 | 5299 } |
5300 | |
1340 | 5301 if (uscfp[i]->default_port && u->default_port |
5302 && uscfp[i]->default_port != u->default_port) | |
5303 { | |
5304 continue; | |
5305 } | |
5306 | |
4152
65c1c241d70e
Better handling of late upstream creation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4151
diff
changeset
|
5307 if (flags & NGX_HTTP_UPSTREAM_CREATE) { |
65c1c241d70e
Better handling of late upstream creation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4151
diff
changeset
|
5308 uscfp[i]->flags = flags; |
65c1c241d70e
Better handling of late upstream creation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4151
diff
changeset
|
5309 } |
65c1c241d70e
Better handling of late upstream creation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4151
diff
changeset
|
5310 |
884 | 5311 return uscfp[i]; |
651 | 5312 } |
5313 | |
5314 uscf = ngx_pcalloc(cf->pool, sizeof(ngx_http_upstream_srv_conf_t)); | |
5315 if (uscf == NULL) { | |
5316 return NULL; | |
5317 } | |
5318 | |
884 | 5319 uscf->flags = flags; |
651 | 5320 uscf->host = u->host; |
1489
56f1ea5baabb
u_char* is enough to keep file name
Igor Sysoev <igor@sysoev.ru>
parents:
1469
diff
changeset
|
5321 uscf->file_name = cf->conf_file->file.name.data; |
651 | 5322 uscf->line = cf->conf_file->line; |
906 | 5323 uscf->port = u->port; |
5324 uscf->default_port = u->default_port; | |
5005
c9059bd5445b
Fixed "proxy_pass" with IP address and no port (ticket #276).
Ruslan Ermilov <ru@nginx.com>
parents:
4990
diff
changeset
|
5325 uscf->no_port = u->no_port; |
884 | 5326 |
5327 if (u->naddrs == 1) { | |
5328 uscf->servers = ngx_array_create(cf->pool, 1, | |
5329 sizeof(ngx_http_upstream_server_t)); | |
5330 if (uscf->servers == NULL) { | |
4765
c48902a053d6
ngx_http_upstream_add() should return NULL if an error occurs.
Ruslan Ermilov <ru@nginx.com>
parents:
4650
diff
changeset
|
5331 return NULL; |
884 | 5332 } |
5333 | |
5334 us = ngx_array_push(uscf->servers); | |
5335 if (us == NULL) { | |
4765
c48902a053d6
ngx_http_upstream_add() should return NULL if an error occurs.
Ruslan Ermilov <ru@nginx.com>
parents:
4650
diff
changeset
|
5336 return NULL; |
884 | 5337 } |
5338 | |
5339 ngx_memzero(us, sizeof(ngx_http_upstream_server_t)); | |
5340 | |
5341 us->addrs = u->addrs; | |
4766
284cb8fb0741
Slight optimization in ngx_http_upstream_add(): replaced an expression
Ruslan Ermilov <ru@nginx.com>
parents:
4765
diff
changeset
|
5342 us->naddrs = 1; |
884 | 5343 } |
651 | 5344 |
5345 uscfp = ngx_array_push(&umcf->upstreams); | |
5346 if (uscfp == NULL) { | |
5347 return NULL; | |
5348 } | |
5349 | |
5350 *uscfp = uscf; | |
5351 | |
5352 return uscf; | |
5353 } | |
5354 | |
5355 | |
3271
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3198
diff
changeset
|
5356 char * |
3399 | 5357 ngx_http_upstream_bind_set_slot(ngx_conf_t *cf, ngx_command_t *cmd, |
3271
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3198
diff
changeset
|
5358 void *conf) |
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3198
diff
changeset
|
5359 { |
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3198
diff
changeset
|
5360 char *p = conf; |
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3198
diff
changeset
|
5361 |
5008
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5362 ngx_int_t rc; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5363 ngx_str_t *value; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5364 ngx_http_complex_value_t cv; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5365 ngx_http_upstream_local_t **plocal, *local; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5366 ngx_http_compile_complex_value_t ccv; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5367 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5368 plocal = (ngx_http_upstream_local_t **) (p + cmd->offset); |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5369 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5370 if (*plocal != NGX_CONF_UNSET_PTR) { |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5371 return "is duplicate"; |
3271
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3198
diff
changeset
|
5372 } |
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3198
diff
changeset
|
5373 |
3272
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3271
diff
changeset
|
5374 value = cf->args->elts; |
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3271
diff
changeset
|
5375 |
5008
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5376 if (ngx_strcmp(value[1].data, "off") == 0) { |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5377 *plocal = NULL; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5378 return NGX_CONF_OK; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5379 } |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5380 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5381 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t)); |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5382 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5383 ccv.cf = cf; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5384 ccv.value = &value[1]; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5385 ccv.complex_value = &cv; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5386 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5387 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) { |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5388 return NGX_CONF_ERROR; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5389 } |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5390 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5391 local = ngx_pcalloc(cf->pool, sizeof(ngx_http_upstream_local_t)); |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5392 if (local == NULL) { |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5393 return NGX_CONF_ERROR; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5394 } |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5395 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5396 *plocal = local; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5397 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5398 if (cv.lengths) { |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5399 local->value = ngx_palloc(cf->pool, sizeof(ngx_http_complex_value_t)); |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5400 if (local->value == NULL) { |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5401 return NGX_CONF_ERROR; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5402 } |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5403 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5404 *local->value = cv; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5405 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5406 return NGX_CONF_OK; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5407 } |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5408 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5409 local->addr = ngx_palloc(cf->pool, sizeof(ngx_addr_t)); |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5410 if (local->addr == NULL) { |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5411 return NGX_CONF_ERROR; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5412 } |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5413 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5414 rc = ngx_parse_addr(cf->pool, local->addr, value[1].data, value[1].len); |
3272
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3271
diff
changeset
|
5415 |
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3271
diff
changeset
|
5416 switch (rc) { |
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3271
diff
changeset
|
5417 case NGX_OK: |
5008
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5418 local->addr->name = value[1]; |
3272
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3271
diff
changeset
|
5419 return NGX_CONF_OK; |
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3271
diff
changeset
|
5420 |
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3271
diff
changeset
|
5421 case NGX_DECLINED: |
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3271
diff
changeset
|
5422 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3271
diff
changeset
|
5423 "invalid address \"%V\"", &value[1]); |
4546
4988fa232629
For the sake of case/switch code readability, 'fall through'
Maxim Konovalov <maxim@nginx.com>
parents:
4499
diff
changeset
|
5424 /* fall through */ |
4988fa232629
For the sake of case/switch code readability, 'fall through'
Maxim Konovalov <maxim@nginx.com>
parents:
4499
diff
changeset
|
5425 |
3272
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3271
diff
changeset
|
5426 default: |
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3271
diff
changeset
|
5427 return NGX_CONF_ERROR; |
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3271
diff
changeset
|
5428 } |
3271
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3198
diff
changeset
|
5429 } |
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3198
diff
changeset
|
5430 |
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3198
diff
changeset
|
5431 |
5008
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5432 static ngx_addr_t * |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5433 ngx_http_upstream_get_local(ngx_http_request_t *r, |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5434 ngx_http_upstream_local_t *local) |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5435 { |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5436 ngx_int_t rc; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5437 ngx_str_t val; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5438 ngx_addr_t *addr; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5439 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5440 if (local == NULL) { |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5441 return NULL; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5442 } |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5443 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5444 if (local->value == NULL) { |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5445 return local->addr; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5446 } |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5447 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5448 if (ngx_http_complex_value(r, local->value, &val) != NGX_OK) { |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5449 return NULL; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5450 } |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5451 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5452 if (val.len == 0) { |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5453 return NULL; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5454 } |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5455 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5456 addr = ngx_palloc(r->pool, sizeof(ngx_addr_t)); |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5457 if (addr == NULL) { |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5458 return NULL; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5459 } |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5460 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5461 rc = ngx_parse_addr(r->pool, addr, val.data, val.len); |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5462 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5463 switch (rc) { |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5464 case NGX_OK: |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5465 addr->name = val; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5466 return addr; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5467 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5468 case NGX_DECLINED: |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5469 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5470 "invalid local address \"%V\"", &val); |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5471 /* fall through */ |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5472 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5473 default: |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5474 return NULL; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5475 } |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5476 } |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5477 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5478 |
4328
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5479 char * |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5480 ngx_http_upstream_param_set_slot(ngx_conf_t *cf, ngx_command_t *cmd, |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5481 void *conf) |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5482 { |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5483 char *p = conf; |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5484 |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5485 ngx_str_t *value; |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5486 ngx_array_t **a; |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5487 ngx_http_upstream_param_t *param; |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5488 |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5489 a = (ngx_array_t **) (p + cmd->offset); |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5490 |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5491 if (*a == NULL) { |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5492 *a = ngx_array_create(cf->pool, 4, sizeof(ngx_http_upstream_param_t)); |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5493 if (*a == NULL) { |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5494 return NGX_CONF_ERROR; |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5495 } |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5496 } |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5497 |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5498 param = ngx_array_push(*a); |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5499 if (param == NULL) { |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5500 return NGX_CONF_ERROR; |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5501 } |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5502 |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5503 value = cf->args->elts; |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5504 |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5505 param->key = value[1]; |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5506 param->value = value[2]; |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5507 param->skip_empty = 0; |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5508 |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5509 if (cf->args->nelts == 4) { |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5510 if (ngx_strcmp(value[3].data, "if_not_empty") != 0) { |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5511 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5512 "invalid parameter \"%V\"", &value[3]); |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5513 return NGX_CONF_ERROR; |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5514 } |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5515 |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5516 param->skip_empty = 1; |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5517 } |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5518 |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5519 return NGX_CONF_OK; |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5520 } |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5521 |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5522 |
1701
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5523 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
|
5524 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
|
5525 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
|
5526 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
|
5527 { |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5528 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
|
5529 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
|
5530 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
|
5531 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
|
5532 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5533 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
|
5534 && 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
|
5535 { |
4769
f88555d76886
Upstream: hide_headers/pass_headers inheritance fix.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4766
diff
changeset
|
5536 conf->hide_headers = prev->hide_headers; |
f88555d76886
Upstream: hide_headers/pass_headers inheritance fix.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4766
diff
changeset
|
5537 conf->pass_headers = prev->pass_headers; |
f88555d76886
Upstream: hide_headers/pass_headers inheritance fix.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4766
diff
changeset
|
5538 |
1701
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5539 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
|
5540 |
2929
37b7cd336fdf
inherit proxy_set_header, proxy_hide_header, and fastcgi_hide_header
Igor Sysoev <igor@sysoev.ru>
parents:
2927
diff
changeset
|
5541 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
|
5542 #if (NGX_HTTP_CACHE) |
fe484c0be7c0
fix building --without-http-cache, broken in r2930
Igor Sysoev <igor@sysoev.ru>
parents:
2929
diff
changeset
|
5543 && ((conf->cache == NULL) == (prev->cache == NULL)) |
fe484c0be7c0
fix building --without-http-cache, broken in r2930
Igor Sysoev <igor@sysoev.ru>
parents:
2929
diff
changeset
|
5544 #endif |
fe484c0be7c0
fix building --without-http-cache, broken in r2930
Igor Sysoev <igor@sysoev.ru>
parents:
2929
diff
changeset
|
5545 ) |
2929
37b7cd336fdf
inherit proxy_set_header, proxy_hide_header, and fastcgi_hide_header
Igor Sysoev <igor@sysoev.ru>
parents:
2927
diff
changeset
|
5546 { |
1701
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5547 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
|
5548 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5549 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5550 } else { |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5551 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
|
5552 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
|
5553 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5554 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5555 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
|
5556 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
|
5557 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5558 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5559 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5560 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
|
5561 != NGX_OK) |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5562 { |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5563 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
|
5564 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5565 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5566 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
|
5567 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
|
5568 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
|
5569 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
|
5570 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5571 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5572 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
|
5573 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
|
5574 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
|
5575 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5576 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5577 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
|
5578 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5579 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
|
5580 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5581 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
|
5582 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5583 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
|
5584 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5585 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
|
5586 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
|
5587 goto exist; |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5588 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5589 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5590 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5591 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
|
5592 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
|
5593 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
|
5594 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5595 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5596 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
|
5597 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
|
5598 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
|
5599 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5600 exist: |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5601 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5602 continue; |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5603 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5604 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5605 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5606 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
|
5607 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5608 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
|
5609 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
|
5610 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5611 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
|
5612 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
|
5613 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5614 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
|
5615 continue; |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5616 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5617 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5618 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
|
5619 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
|
5620 break; |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5621 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5622 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5623 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5624 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5625 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5626 hash->hash = &conf->hide_headers_hash; |
1706
9242e21d2f8d
style fix: remove trailing spaces
Igor Sysoev <igor@sysoev.ru>
parents:
1705
diff
changeset
|
5627 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
|
5628 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
|
5629 hash->temp_pool = NULL; |
1706
9242e21d2f8d
style fix: remove trailing spaces
Igor Sysoev <igor@sysoev.ru>
parents:
1705
diff
changeset
|
5630 |
1701
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5631 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
|
5632 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5633 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5634 |
509 | 5635 static void * |
5636 ngx_http_upstream_create_main_conf(ngx_conf_t *cf) | |
5637 { | |
5638 ngx_http_upstream_main_conf_t *umcf; | |
5639 | |
5640 umcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_upstream_main_conf_t)); | |
5641 if (umcf == NULL) { | |
5642 return NULL; | |
5643 } | |
5644 | |
651 | 5645 if (ngx_array_init(&umcf->upstreams, cf->pool, 4, |
5646 sizeof(ngx_http_upstream_srv_conf_t *)) | |
5647 != NGX_OK) | |
5648 { | |
2912
c7d57b539248
return NULL instead of NGX_CONF_ERROR on a create conf failure
Igor Sysoev <igor@sysoev.ru>
parents:
2882
diff
changeset
|
5649 return NULL; |
651 | 5650 } |
5651 | |
509 | 5652 return umcf; |
5653 } | |
5654 | |
5655 | |
5656 static char * | |
651 | 5657 ngx_http_upstream_init_main_conf(ngx_conf_t *cf, void *conf) |
509 | 5658 { |
5659 ngx_http_upstream_main_conf_t *umcf = conf; | |
5660 | |
651 | 5661 ngx_uint_t i; |
5662 ngx_array_t headers_in; | |
5663 ngx_hash_key_t *hk; | |
5664 ngx_hash_init_t hash; | |
884 | 5665 ngx_http_upstream_init_pt init; |
651 | 5666 ngx_http_upstream_header_t *header; |
5667 ngx_http_upstream_srv_conf_t **uscfp; | |
5668 | |
5669 uscfp = umcf->upstreams.elts; | |
5670 | |
5671 for (i = 0; i < umcf->upstreams.nelts; i++) { | |
884 | 5672 |
5673 init = uscfp[i]->peer.init_upstream ? uscfp[i]->peer.init_upstream: | |
5674 ngx_http_upstream_init_round_robin; | |
5675 | |
5676 if (init(cf, uscfp[i]) != NGX_OK) { | |
651 | 5677 return NGX_CONF_ERROR; |
5678 } | |
5679 } | |
649 | 5680 |
663 | 5681 |
884 | 5682 /* upstream_headers_in_hash */ |
5683 | |
649 | 5684 if (ngx_array_init(&headers_in, cf->temp_pool, 32, sizeof(ngx_hash_key_t)) |
5685 != NGX_OK) | |
509 | 5686 { |
5687 return NGX_CONF_ERROR; | |
5688 } | |
5689 | |
649 | 5690 for (header = ngx_http_upstream_headers_in; header->name.len; header++) { |
5691 hk = ngx_array_push(&headers_in); | |
5692 if (hk == NULL) { | |
5693 return NGX_CONF_ERROR; | |
5694 } | |
5695 | |
5696 hk->key = header->name; | |
5697 hk->key_hash = ngx_hash_key_lc(header->name.data, header->name.len); | |
5698 hk->value = header; | |
5699 } | |
5700 | |
5701 hash.hash = &umcf->headers_in_hash; | |
5702 hash.key = ngx_hash_key_lc; | |
5703 hash.max_size = 512; | |
751
bae59a740c40
align hash bucket size to cache line
Igor Sysoev <igor@sysoev.ru>
parents:
750
diff
changeset
|
5704 hash.bucket_size = ngx_align(64, ngx_cacheline_size); |
649 | 5705 hash.name = "upstream_headers_in_hash"; |
5706 hash.pool = cf->pool; | |
5707 hash.temp_pool = NULL; | |
5708 | |
5709 if (ngx_hash_init(&hash, headers_in.elts, headers_in.nelts) != NGX_OK) { | |
5710 return NGX_CONF_ERROR; | |
5711 } | |
509 | 5712 |
5713 return NGX_CONF_OK; | |
5714 } |