Mercurial > hg > nginx
annotate src/http/ngx_http_upstream.c @ 6313:be3aed17689c
Style.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Wed, 02 Dec 2015 01:06:54 +0300 |
parents | b1858fc47e3b |
children | f44de0d12143 |
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); |
5951
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
16 static ngx_int_t ngx_http_upstream_cache_get(ngx_http_request_t *r, |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
17 ngx_http_upstream_t *u, ngx_http_file_cache_t **cache); |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
18 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
|
19 ngx_http_upstream_t *u); |
2952 | 20 static ngx_int_t ngx_http_upstream_cache_status(ngx_http_request_t *r, |
21 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
|
22 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
|
23 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
|
24 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
|
25 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
|
26 #endif |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
27 |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
28 static void ngx_http_upstream_init_request(ngx_http_request_t *r); |
1658 | 29 static void ngx_http_upstream_resolve_handler(ngx_resolver_ctx_t *ctx); |
509 | 30 static void ngx_http_upstream_rd_check_broken_connection(ngx_http_request_t *r); |
31 static void ngx_http_upstream_wr_check_broken_connection(ngx_http_request_t *r); | |
32 static void ngx_http_upstream_check_broken_connection(ngx_http_request_t *r, | |
33 ngx_event_t *ev); | |
479 | 34 static void ngx_http_upstream_connect(ngx_http_request_t *r, |
487 | 35 ngx_http_upstream_t *u); |
509 | 36 static ngx_int_t ngx_http_upstream_reinit(ngx_http_request_t *r, |
487 | 37 ngx_http_upstream_t *u); |
479 | 38 static void ngx_http_upstream_send_request(ngx_http_request_t *r, |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
39 ngx_http_upstream_t *u, ngx_uint_t do_write); |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
40 static ngx_int_t ngx_http_upstream_send_request_body(ngx_http_request_t *r, |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
41 ngx_http_upstream_t *u, ngx_uint_t do_write); |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
42 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
|
43 ngx_http_upstream_t *u); |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
44 static void ngx_http_upstream_read_request_handler(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
|
45 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
|
46 ngx_http_upstream_t *u); |
2268
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
47 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
|
48 ngx_http_upstream_t *u); |
2267
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
49 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
|
50 ngx_http_upstream_t *u); |
1153
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
51 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
|
52 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
|
53 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
|
54 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
|
55 ngx_http_upstream_t *u); |
479 | 56 static void ngx_http_upstream_send_response(ngx_http_request_t *r, |
487 | 57 ngx_http_upstream_t *u); |
5072
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
58 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
|
59 ngx_http_upstream_t *u); |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
60 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
|
61 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
|
62 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
|
63 ngx_http_upstream_t *u); |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
64 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
|
65 ngx_http_upstream_t *u); |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
66 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
|
67 ngx_uint_t from_upstream, ngx_uint_t do_write); |
581 | 68 static void |
69 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
|
70 static void |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
71 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
|
72 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
|
73 static void |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
74 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
|
75 ngx_uint_t do_write); |
581 | 76 static ngx_int_t ngx_http_upstream_non_buffered_filter_init(void *data); |
77 static ngx_int_t ngx_http_upstream_non_buffered_filter(void *data, | |
78 ssize_t bytes); | |
509 | 79 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
|
80 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
|
81 ngx_http_upstream_t *u); |
5995
5f179f344096
Upstream: upstream argument in ngx_http_upstream_process_request().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5994
diff
changeset
|
82 static void ngx_http_upstream_process_request(ngx_http_request_t *r, |
5f179f344096
Upstream: upstream argument in ngx_http_upstream_process_request().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5994
diff
changeset
|
83 ngx_http_upstream_t *u); |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
84 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
|
85 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
|
86 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
|
87 ngx_http_upstream_t *u); |
479 | 88 static void ngx_http_upstream_next(ngx_http_request_t *r, |
487 | 89 ngx_http_upstream_t *u, ngx_uint_t ft_type); |
569 | 90 static void ngx_http_upstream_cleanup(void *data); |
479 | 91 static void ngx_http_upstream_finalize_request(ngx_http_request_t *r, |
487 | 92 ngx_http_upstream_t *u, ngx_int_t rc); |
479 | 93 |
509 | 94 static ngx_int_t ngx_http_upstream_process_header_line(ngx_http_request_t *r, |
95 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
|
96 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
|
97 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
|
98 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
|
99 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
|
100 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
|
101 ngx_table_elt_t *h, ngx_uint_t offset); |
509 | 102 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
|
103 ngx_http_upstream_process_cache_control(ngx_http_request_t *r, |
509 | 104 ngx_table_elt_t *h, ngx_uint_t offset); |
105 static ngx_int_t ngx_http_upstream_ignore_header_line(ngx_http_request_t *r, | |
106 ngx_table_elt_t *h, ngx_uint_t offset); | |
2666 | 107 static ngx_int_t ngx_http_upstream_process_expires(ngx_http_request_t *r, |
108 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
|
109 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
|
110 ngx_table_elt_t *h, ngx_uint_t offset); |
527 | 111 static ngx_int_t ngx_http_upstream_process_limit_rate(ngx_http_request_t *r, |
112 ngx_table_elt_t *h, ngx_uint_t offset); | |
649 | 113 static ngx_int_t ngx_http_upstream_process_buffering(ngx_http_request_t *r, |
509 | 114 ngx_table_elt_t *h, ngx_uint_t offset); |
657 | 115 static ngx_int_t ngx_http_upstream_process_charset(ngx_http_request_t *r, |
116 ngx_table_elt_t *h, ngx_uint_t offset); | |
4124
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
117 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
|
118 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
|
119 static ngx_int_t |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
120 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
|
121 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
|
122 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
|
123 ngx_table_elt_t *h, ngx_uint_t offset); |
649 | 124 static ngx_int_t ngx_http_upstream_copy_header_line(ngx_http_request_t *r, |
509 | 125 ngx_table_elt_t *h, ngx_uint_t offset); |
126 static ngx_int_t | |
127 ngx_http_upstream_copy_multi_header_lines(ngx_http_request_t *r, | |
128 ngx_table_elt_t *h, ngx_uint_t offset); | |
129 static ngx_int_t ngx_http_upstream_copy_content_type(ngx_http_request_t *r, | |
130 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
|
131 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
|
132 ngx_table_elt_t *h, ngx_uint_t offset); |
509 | 133 static ngx_int_t ngx_http_upstream_rewrite_location(ngx_http_request_t *r, |
134 ngx_table_elt_t *h, ngx_uint_t offset); | |
135 static ngx_int_t ngx_http_upstream_rewrite_refresh(ngx_http_request_t *r, | |
136 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
|
137 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
|
138 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
|
139 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
|
140 ngx_table_elt_t *h, ngx_uint_t offset); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
141 |
509 | 142 #if (NGX_HTTP_GZIP) |
143 static ngx_int_t ngx_http_upstream_copy_content_encoding(ngx_http_request_t *r, | |
144 ngx_table_elt_t *h, ngx_uint_t offset); | |
145 #endif | |
146 | |
573 | 147 static ngx_int_t ngx_http_upstream_add_variables(ngx_conf_t *cf); |
1181 | 148 static ngx_int_t ngx_http_upstream_addr_variable(ngx_http_request_t *r, |
149 ngx_http_variable_value_t *v, uintptr_t data); | |
573 | 150 static ngx_int_t ngx_http_upstream_status_variable(ngx_http_request_t *r, |
151 ngx_http_variable_value_t *v, uintptr_t data); | |
152 static ngx_int_t ngx_http_upstream_response_time_variable(ngx_http_request_t *r, | |
153 ngx_http_variable_value_t *v, uintptr_t data); | |
2402 | 154 static ngx_int_t ngx_http_upstream_response_length_variable( |
155 ngx_http_request_t *r, ngx_http_variable_value_t *v, uintptr_t data); | |
573 | 156 |
651 | 157 static char *ngx_http_upstream(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy); |
158 static char *ngx_http_upstream_server(ngx_conf_t *cf, ngx_command_t *cmd, | |
159 void *conf); | |
160 | |
5008
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
161 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
|
162 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
|
163 |
509 | 164 static void *ngx_http_upstream_create_main_conf(ngx_conf_t *cf); |
651 | 165 static char *ngx_http_upstream_init_main_conf(ngx_conf_t *cf, void *conf); |
509 | 166 |
577 | 167 #if (NGX_HTTP_SSL) |
591 | 168 static void ngx_http_upstream_ssl_init_connection(ngx_http_request_t *, |
169 ngx_http_upstream_t *u, ngx_connection_t *c); | |
577 | 170 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
|
171 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
|
172 ngx_http_upstream_t *u, ngx_connection_t *c); |
577 | 173 #endif |
174 | |
509 | 175 |
176 ngx_http_upstream_header_t ngx_http_upstream_headers_in[] = { | |
177 | |
178 { ngx_string("Status"), | |
179 ngx_http_upstream_process_header_line, | |
180 offsetof(ngx_http_upstream_headers_in_t, status), | |
649 | 181 ngx_http_upstream_copy_header_line, 0, 0 }, |
509 | 182 |
183 { ngx_string("Content-Type"), | |
184 ngx_http_upstream_process_header_line, | |
185 offsetof(ngx_http_upstream_headers_in_t, content_type), | |
673 | 186 ngx_http_upstream_copy_content_type, 0, 1 }, |
509 | 187 |
188 { ngx_string("Content-Length"), | |
5731
02674312be45
Upstream: removed unused offset to content_length.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5730
diff
changeset
|
189 ngx_http_upstream_process_content_length, 0, |
4117
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
190 ngx_http_upstream_ignore_header_line, 0, 0 }, |
509 | 191 |
192 { ngx_string("Date"), | |
193 ngx_http_upstream_process_header_line, | |
194 offsetof(ngx_http_upstream_headers_in_t, date), | |
649 | 195 ngx_http_upstream_copy_header_line, |
196 offsetof(ngx_http_headers_out_t, date), 0 }, | |
509 | 197 |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
198 { ngx_string("Last-Modified"), |
5732
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
199 ngx_http_upstream_process_last_modified, 0, |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
200 ngx_http_upstream_copy_last_modified, 0, 0 }, |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
201 |
3037 | 202 { ngx_string("ETag"), |
203 ngx_http_upstream_process_header_line, | |
204 offsetof(ngx_http_upstream_headers_in_t, etag), | |
205 ngx_http_upstream_copy_header_line, | |
206 offsetof(ngx_http_headers_out_t, etag), 0 }, | |
207 | |
509 | 208 { ngx_string("Server"), |
209 ngx_http_upstream_process_header_line, | |
210 offsetof(ngx_http_upstream_headers_in_t, server), | |
649 | 211 ngx_http_upstream_copy_header_line, |
212 offsetof(ngx_http_headers_out_t, server), 0 }, | |
509 | 213 |
529 | 214 { ngx_string("WWW-Authenticate"), |
215 ngx_http_upstream_process_header_line, | |
216 offsetof(ngx_http_upstream_headers_in_t, www_authenticate), | |
217 ngx_http_upstream_copy_header_line, 0, 0 }, | |
218 | |
509 | 219 { ngx_string("Location"), |
2140
dce5ddef5af9
if upstream sent a location header without status use 302
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
220 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
|
221 offsetof(ngx_http_upstream_headers_in_t, location), |
515 | 222 ngx_http_upstream_rewrite_location, 0, 0 }, |
509 | 223 |
224 { ngx_string("Refresh"), | |
225 ngx_http_upstream_ignore_header_line, 0, | |
515 | 226 ngx_http_upstream_rewrite_refresh, 0, 0 }, |
227 | |
228 { ngx_string("Set-Cookie"), | |
5677
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
229 ngx_http_upstream_process_set_cookie, |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
230 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
|
231 ngx_http_upstream_rewrite_set_cookie, 0, 1 }, |
531 | 232 |
233 { ngx_string("Content-Disposition"), | |
234 ngx_http_upstream_ignore_header_line, 0, | |
235 ngx_http_upstream_copy_header_line, 0, 1 }, | |
509 | 236 |
237 { 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
|
238 ngx_http_upstream_process_cache_control, 0, |
509 | 239 ngx_http_upstream_copy_multi_header_lines, |
515 | 240 offsetof(ngx_http_headers_out_t, cache_control), 1 }, |
509 | 241 |
573 | 242 { ngx_string("Expires"), |
2666 | 243 ngx_http_upstream_process_expires, 0, |
573 | 244 ngx_http_upstream_copy_header_line, |
245 offsetof(ngx_http_headers_out_t, expires), 1 }, | |
246 | |
577 | 247 { ngx_string("Accept-Ranges"), |
248 ngx_http_upstream_process_header_line, | |
249 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
|
250 ngx_http_upstream_copy_allow_ranges, |
577 | 251 offsetof(ngx_http_headers_out_t, accept_ranges), 1 }, |
252 | |
509 | 253 { ngx_string("Connection"), |
4124
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
254 ngx_http_upstream_process_connection, 0, |
515 | 255 ngx_http_upstream_ignore_header_line, 0, 0 }, |
509 | 256 |
641 | 257 { ngx_string("Keep-Alive"), |
258 ngx_http_upstream_ignore_header_line, 0, | |
259 ngx_http_upstream_ignore_header_line, 0, 0 }, | |
260 | |
5877
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
261 { ngx_string("Vary"), |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
262 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
|
263 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
|
264 |
509 | 265 { ngx_string("X-Powered-By"), |
266 ngx_http_upstream_ignore_header_line, 0, | |
649 | 267 ngx_http_upstream_copy_header_line, 0, 0 }, |
509 | 268 |
269 { ngx_string("X-Accel-Expires"), | |
2664 | 270 ngx_http_upstream_process_accel_expires, 0, |
649 | 271 ngx_http_upstream_copy_header_line, 0, 0 }, |
515 | 272 |
273 { ngx_string("X-Accel-Redirect"), | |
274 ngx_http_upstream_process_header_line, | |
275 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
|
276 ngx_http_upstream_copy_header_line, 0, 0 }, |
509 | 277 |
527 | 278 { ngx_string("X-Accel-Limit-Rate"), |
279 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
|
280 ngx_http_upstream_copy_header_line, 0, 0 }, |
527 | 281 |
649 | 282 { ngx_string("X-Accel-Buffering"), |
283 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
|
284 ngx_http_upstream_copy_header_line, 0, 0 }, |
649 | 285 |
657 | 286 { ngx_string("X-Accel-Charset"), |
287 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
|
288 ngx_http_upstream_copy_header_line, 0, 0 }, |
657 | 289 |
4123
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
290 { ngx_string("Transfer-Encoding"), |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
291 ngx_http_upstream_process_transfer_encoding, 0, |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
292 ngx_http_upstream_ignore_header_line, 0, 0 }, |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
293 |
509 | 294 #if (NGX_HTTP_GZIP) |
295 { ngx_string("Content-Encoding"), | |
296 ngx_http_upstream_process_header_line, | |
297 offsetof(ngx_http_upstream_headers_in_t, content_encoding), | |
515 | 298 ngx_http_upstream_copy_content_encoding, 0, 0 }, |
509 | 299 #endif |
300 | |
515 | 301 { ngx_null_string, NULL, 0, NULL, 0, 0 } |
509 | 302 }; |
479 | 303 |
304 | |
651 | 305 static ngx_command_t ngx_http_upstream_commands[] = { |
306 | |
307 { ngx_string("upstream"), | |
308 NGX_HTTP_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_TAKE1, | |
309 ngx_http_upstream, | |
310 0, | |
311 0, | |
312 NULL }, | |
313 | |
314 { ngx_string("server"), | |
884 | 315 NGX_HTTP_UPS_CONF|NGX_CONF_1MORE, |
651 | 316 ngx_http_upstream_server, |
317 NGX_HTTP_SRV_CONF_OFFSET, | |
318 0, | |
319 NULL }, | |
320 | |
321 ngx_null_command | |
322 }; | |
323 | |
324 | |
325 static ngx_http_module_t ngx_http_upstream_module_ctx = { | |
573 | 326 ngx_http_upstream_add_variables, /* preconfiguration */ |
509 | 327 NULL, /* postconfiguration */ |
328 | |
329 ngx_http_upstream_create_main_conf, /* create main configuration */ | |
651 | 330 ngx_http_upstream_init_main_conf, /* init main configuration */ |
479 | 331 |
332 NULL, /* create server configuration */ | |
333 NULL, /* merge server configuration */ | |
334 | |
335 NULL, /* create location configuration */ | |
336 NULL /* merge location configuration */ | |
337 }; | |
577 | 338 |
479 | 339 |
340 ngx_module_t ngx_http_upstream_module = { | |
509 | 341 NGX_MODULE_V1, |
479 | 342 &ngx_http_upstream_module_ctx, /* module context */ |
651 | 343 ngx_http_upstream_commands, /* module directives */ |
479 | 344 NGX_HTTP_MODULE, /* module type */ |
541 | 345 NULL, /* init master */ |
479 | 346 NULL, /* init module */ |
541 | 347 NULL, /* init process */ |
348 NULL, /* init thread */ | |
349 NULL, /* exit thread */ | |
350 NULL, /* exit process */ | |
351 NULL, /* exit master */ | |
352 NGX_MODULE_V1_PADDING | |
479 | 353 }; |
354 | |
355 | |
573 | 356 static ngx_http_variable_t ngx_http_upstream_vars[] = { |
357 | |
1181 | 358 { 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
|
359 ngx_http_upstream_addr_variable, 0, |
3898
bd1222fb0192
allow to use $upstream_... variables in SSI
Igor Sysoev <igor@sysoev.ru>
parents:
3879
diff
changeset
|
360 NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
1181 | 361 |
637 | 362 { 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
|
363 ngx_http_upstream_status_variable, 0, |
3898
bd1222fb0192
allow to use $upstream_... variables in SSI
Igor Sysoev <igor@sysoev.ru>
parents:
3879
diff
changeset
|
364 NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
573 | 365 |
6147
74b6ef56ea56
Upstream: $upstream_connect_time.
Ruslan Ermilov <ru@nginx.com>
parents:
6146
diff
changeset
|
366 { ngx_string("upstream_connect_time"), NULL, |
74b6ef56ea56
Upstream: $upstream_connect_time.
Ruslan Ermilov <ru@nginx.com>
parents:
6146
diff
changeset
|
367 ngx_http_upstream_response_time_variable, 2, |
74b6ef56ea56
Upstream: $upstream_connect_time.
Ruslan Ermilov <ru@nginx.com>
parents:
6146
diff
changeset
|
368 NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
74b6ef56ea56
Upstream: $upstream_connect_time.
Ruslan Ermilov <ru@nginx.com>
parents:
6146
diff
changeset
|
369 |
5964
0a198a517eaf
Upstream: $upstream_header_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
5960
diff
changeset
|
370 { ngx_string("upstream_header_time"), NULL, |
0a198a517eaf
Upstream: $upstream_header_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
5960
diff
changeset
|
371 ngx_http_upstream_response_time_variable, 1, |
0a198a517eaf
Upstream: $upstream_header_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
5960
diff
changeset
|
372 NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
0a198a517eaf
Upstream: $upstream_header_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
5960
diff
changeset
|
373 |
637 | 374 { 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
|
375 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
|
376 NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
573 | 377 |
2402 | 378 { ngx_string("upstream_response_length"), NULL, |
379 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
|
380 NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
2402 | 381 |
2957
b4f39842523b
fix building --without-http-cache, broken in r2953
Igor Sysoev <igor@sysoev.ru>
parents:
2953
diff
changeset
|
382 #if (NGX_HTTP_CACHE) |
b4f39842523b
fix building --without-http-cache, broken in r2953
Igor Sysoev <igor@sysoev.ru>
parents:
2953
diff
changeset
|
383 |
2952 | 384 { ngx_string("upstream_cache_status"), NULL, |
385 ngx_http_upstream_cache_status, 0, | |
3898
bd1222fb0192
allow to use $upstream_... variables in SSI
Igor Sysoev <igor@sysoev.ru>
parents:
3879
diff
changeset
|
386 NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
2952 | 387 |
5441
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
388 { ngx_string("upstream_cache_last_modified"), NULL, |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
389 ngx_http_upstream_cache_last_modified, 0, |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
390 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
|
391 |
5738
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
392 { ngx_string("upstream_cache_etag"), NULL, |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
393 ngx_http_upstream_cache_etag, 0, |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
394 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
|
395 |
2957
b4f39842523b
fix building --without-http-cache, broken in r2953
Igor Sysoev <igor@sysoev.ru>
parents:
2953
diff
changeset
|
396 #endif |
b4f39842523b
fix building --without-http-cache, broken in r2953
Igor Sysoev <igor@sysoev.ru>
parents:
2953
diff
changeset
|
397 |
637 | 398 { ngx_null_string, NULL, NULL, 0, 0, 0 } |
573 | 399 }; |
400 | |
401 | |
2268
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
402 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
|
403 { 500, NGX_HTTP_UPSTREAM_FT_HTTP_500 }, |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
404 { 502, NGX_HTTP_UPSTREAM_FT_HTTP_502 }, |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
405 { 503, NGX_HTTP_UPSTREAM_FT_HTTP_503 }, |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
406 { 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
|
407 { 403, NGX_HTTP_UPSTREAM_FT_HTTP_403 }, |
2268
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
408 { 404, NGX_HTTP_UPSTREAM_FT_HTTP_404 }, |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
409 { 0, 0 } |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
410 }; |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
411 |
2875
6e1941b321b7
proxy_cache_methods and fastcgi_cache_methods
Igor Sysoev <igor@sysoev.ru>
parents:
2874
diff
changeset
|
412 |
6e1941b321b7
proxy_cache_methods and fastcgi_cache_methods
Igor Sysoev <igor@sysoev.ru>
parents:
2874
diff
changeset
|
413 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
|
414 { ngx_string("GET"), NGX_HTTP_GET}, |
6e1941b321b7
proxy_cache_methods and fastcgi_cache_methods
Igor Sysoev <igor@sysoev.ru>
parents:
2874
diff
changeset
|
415 { ngx_string("HEAD"), NGX_HTTP_HEAD }, |
6e1941b321b7
proxy_cache_methods and fastcgi_cache_methods
Igor Sysoev <igor@sysoev.ru>
parents:
2874
diff
changeset
|
416 { ngx_string("POST"), NGX_HTTP_POST }, |
6e1941b321b7
proxy_cache_methods and fastcgi_cache_methods
Igor Sysoev <igor@sysoev.ru>
parents:
2874
diff
changeset
|
417 { ngx_null_string, 0 } |
6e1941b321b7
proxy_cache_methods and fastcgi_cache_methods
Igor Sysoev <igor@sysoev.ru>
parents:
2874
diff
changeset
|
418 }; |
6e1941b321b7
proxy_cache_methods and fastcgi_cache_methods
Igor Sysoev <igor@sysoev.ru>
parents:
2874
diff
changeset
|
419 |
6e1941b321b7
proxy_cache_methods and fastcgi_cache_methods
Igor Sysoev <igor@sysoev.ru>
parents:
2874
diff
changeset
|
420 |
3667
12bd9e26fadb
use shared ngx_http_upstream_ignore_headers_masks[]
Igor Sysoev <igor@sysoev.ru>
parents:
3527
diff
changeset
|
421 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
|
422 { 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
|
423 { 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
|
424 { 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
|
425 { 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
|
426 { 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
|
427 { 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
|
428 { 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
|
429 { 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
|
430 { 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
|
431 { ngx_null_string, 0 } |
12bd9e26fadb
use shared ngx_http_upstream_ignore_headers_masks[]
Igor Sysoev <igor@sysoev.ru>
parents:
3527
diff
changeset
|
432 }; |
12bd9e26fadb
use shared ngx_http_upstream_ignore_headers_masks[]
Igor Sysoev <igor@sysoev.ru>
parents:
3527
diff
changeset
|
433 |
12bd9e26fadb
use shared ngx_http_upstream_ignore_headers_masks[]
Igor Sysoev <igor@sysoev.ru>
parents:
3527
diff
changeset
|
434 |
3006
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
435 ngx_int_t |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
436 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
|
437 { |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
438 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
|
439 |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
440 u = r->upstream; |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
441 |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
442 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
|
443 r->main->count++; |
3006
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
444 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
|
445 } |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
446 |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
447 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
|
448 if (u == NULL) { |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
449 return NGX_ERROR; |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
450 } |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
451 |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
452 r->upstream = u; |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
453 |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
454 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
|
455 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
|
456 |
3056
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
457 #if (NGX_HTTP_CACHE) |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
458 r->cache = NULL; |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
459 #endif |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
460 |
4117
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
461 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
|
462 u->headers_in.last_modified_time = -1; |
4117
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
463 |
3006
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
464 return NGX_OK; |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
465 } |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
466 |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
467 |
487 | 468 void |
469 ngx_http_upstream_init(ngx_http_request_t *r) | |
479 | 470 { |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
471 ngx_connection_t *c; |
479 | 472 |
473 c = r->connection; | |
474 | |
475 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
476 "http init upstream, client timer: %d", c->read->timer_set); | |
477 | |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
6242
diff
changeset
|
478 #if (NGX_HTTP_V2) |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
6242
diff
changeset
|
479 if (r->stream) { |
5121
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
5113
diff
changeset
|
480 ngx_http_upstream_init_request(r); |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
5113
diff
changeset
|
481 return; |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
5113
diff
changeset
|
482 } |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
5113
diff
changeset
|
483 #endif |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
5113
diff
changeset
|
484 |
479 | 485 if (c->read->timer_set) { |
486 ngx_del_timer(c->read); | |
487 } | |
488 | |
489 if (ngx_event_flags & NGX_USE_CLEAR_EVENT) { | |
490 | |
491 if (!c->write->active) { | |
531 | 492 if (ngx_add_event(c->write, NGX_WRITE_EVENT, NGX_CLEAR_EVENT) |
493 == NGX_ERROR) | |
479 | 494 { |
495 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | |
496 return; | |
497 } | |
498 } | |
499 } | |
500 | |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
501 ngx_http_upstream_init_request(r); |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
502 } |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
503 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
504 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
505 static void |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
506 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
|
507 { |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
508 ngx_str_t *host; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
509 ngx_uint_t i; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
510 ngx_resolver_ctx_t *ctx, temp; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
511 ngx_http_cleanup_t *cln; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
512 ngx_http_upstream_t *u; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
513 ngx_http_core_loc_conf_t *clcf; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
514 ngx_http_upstream_srv_conf_t *uscf, **uscfp; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
515 ngx_http_upstream_main_conf_t *umcf; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
516 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
517 if (r->aio) { |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
518 return; |
537 | 519 } |
509 | 520 |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
521 u = r->upstream; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
522 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
523 #if (NGX_HTTP_CACHE) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
524 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
525 if (u->conf->cache) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
526 ngx_int_t rc; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
527 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
528 rc = ngx_http_upstream_cache(r, u); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
529 |
3055
92b6cfaa3c27
fix sending a cached file using AIO
Igor Sysoev <igor@sysoev.ru>
parents:
3053
diff
changeset
|
530 if (rc == NGX_BUSY) { |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
531 r->write_event_handler = ngx_http_upstream_init_request; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
532 return; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
533 } |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
534 |
3055
92b6cfaa3c27
fix sending a cached file using AIO
Igor Sysoev <igor@sysoev.ru>
parents:
3053
diff
changeset
|
535 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
|
536 |
5827
54e9b83d00f0
Upstream: avoided directly terminating the connection.
FengGu <flygoast@126.com>
parents:
5818
diff
changeset
|
537 if (rc == NGX_ERROR) { |
54e9b83d00f0
Upstream: avoided directly terminating the connection.
FengGu <flygoast@126.com>
parents:
5818
diff
changeset
|
538 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
|
539 return; |
54e9b83d00f0
Upstream: avoided directly terminating the connection.
FengGu <flygoast@126.com>
parents:
5818
diff
changeset
|
540 } |
54e9b83d00f0
Upstream: avoided directly terminating the connection.
FengGu <flygoast@126.com>
parents:
5818
diff
changeset
|
541 |
6242
0e3a45ec2a3a
Upstream: fixed cache send error handling.
Roman Arutyunyan <arut@nginx.com>
parents:
6180
diff
changeset
|
542 if (rc == NGX_OK) { |
0e3a45ec2a3a
Upstream: fixed cache send error handling.
Roman Arutyunyan <arut@nginx.com>
parents:
6180
diff
changeset
|
543 rc = ngx_http_upstream_cache_send(r, u); |
0e3a45ec2a3a
Upstream: fixed cache send error handling.
Roman Arutyunyan <arut@nginx.com>
parents:
6180
diff
changeset
|
544 |
0e3a45ec2a3a
Upstream: fixed cache send error handling.
Roman Arutyunyan <arut@nginx.com>
parents:
6180
diff
changeset
|
545 if (rc == NGX_DONE) { |
0e3a45ec2a3a
Upstream: fixed cache send error handling.
Roman Arutyunyan <arut@nginx.com>
parents:
6180
diff
changeset
|
546 return; |
0e3a45ec2a3a
Upstream: fixed cache send error handling.
Roman Arutyunyan <arut@nginx.com>
parents:
6180
diff
changeset
|
547 } |
0e3a45ec2a3a
Upstream: fixed cache send error handling.
Roman Arutyunyan <arut@nginx.com>
parents:
6180
diff
changeset
|
548 |
0e3a45ec2a3a
Upstream: fixed cache send error handling.
Roman Arutyunyan <arut@nginx.com>
parents:
6180
diff
changeset
|
549 if (rc == NGX_HTTP_UPSTREAM_INVALID_HEADER) { |
0e3a45ec2a3a
Upstream: fixed cache send error handling.
Roman Arutyunyan <arut@nginx.com>
parents:
6180
diff
changeset
|
550 rc = NGX_DECLINED; |
0e3a45ec2a3a
Upstream: fixed cache send error handling.
Roman Arutyunyan <arut@nginx.com>
parents:
6180
diff
changeset
|
551 r->cached = 0; |
0e3a45ec2a3a
Upstream: fixed cache send error handling.
Roman Arutyunyan <arut@nginx.com>
parents:
6180
diff
changeset
|
552 } |
0e3a45ec2a3a
Upstream: fixed cache send error handling.
Roman Arutyunyan <arut@nginx.com>
parents:
6180
diff
changeset
|
553 } |
0e3a45ec2a3a
Upstream: fixed cache send error handling.
Roman Arutyunyan <arut@nginx.com>
parents:
6180
diff
changeset
|
554 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
555 if (rc != NGX_DECLINED) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
556 ngx_http_finalize_request(r, rc); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
557 return; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
558 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
559 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
560 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
561 #endif |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
562 |
5947
d9025ea1f5a5
Upstream: simplified proxy_store and friends configuration code.
Valentin Bartenev <vbart@nginx.com>
parents:
5935
diff
changeset
|
563 u->store = u->conf->store; |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
564 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
565 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
|
566 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
|
567 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
|
568 } |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
569 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
570 if (r->request_body) { |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
571 u->request_bufs = r->request_body->bufs; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
572 } |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
573 |
537 | 574 if (u->create_request(r) != NGX_OK) { |
479 | 575 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); |
576 return; | |
577 } | |
578 | |
5008
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
579 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
|
580 |
509 | 581 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
479 | 582 |
3053 | 583 u->output.alignment = clcf->directio_alignment; |
479 | 584 u->output.pool = r->pool; |
585 u->output.bufs.num = 1; | |
509 | 586 u->output.bufs.size = clcf->client_body_buffer_size; |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
587 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
588 if (u->output.output_filter == NULL) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
589 u->output.output_filter = ngx_chain_writer; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
590 u->output.filter_ctx = &u->writer; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
591 } |
479 | 592 |
593 u->writer.pool = r->pool; | |
594 | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
595 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
|
596 |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
597 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
|
598 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
|
599 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
|
600 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
|
601 return; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
602 } |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
603 |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
604 } else { |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
605 |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
606 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
|
607 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
|
608 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
|
609 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
|
610 return; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
611 } |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
612 |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
613 ngx_memzero(u->state, sizeof(ngx_http_upstream_state_t)); |
479 | 614 } |
615 | |
593 | 616 cln = ngx_http_cleanup_add(r, 0); |
569 | 617 if (cln == NULL) { |
618 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | |
619 return; | |
620 } | |
621 | |
622 cln->handler = ngx_http_upstream_cleanup; | |
623 cln->data = r; | |
624 u->cleanup = &cln->handler; | |
625 | |
1658 | 626 if (u->resolved == NULL) { |
627 | |
628 uscf = u->conf->upstream; | |
629 | |
630 } else { | |
631 | |
5660
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
632 #if (NGX_HTTP_SSL) |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
633 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
|
634 #endif |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
635 |
6303
a93345ee8f52
Upstream: fixed "no port" detection in evaluated upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6290
diff
changeset
|
636 host = &u->resolved->host; |
a93345ee8f52
Upstream: fixed "no port" detection in evaluated upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6290
diff
changeset
|
637 |
2422
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2413
diff
changeset
|
638 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
|
639 |
6303
a93345ee8f52
Upstream: fixed "no port" detection in evaluated upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6290
diff
changeset
|
640 if (u->resolved->port == 0) { |
a93345ee8f52
Upstream: fixed "no port" detection in evaluated upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6290
diff
changeset
|
641 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
a93345ee8f52
Upstream: fixed "no port" detection in evaluated upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6290
diff
changeset
|
642 "no port in upstream \"%V\"", host); |
a93345ee8f52
Upstream: fixed "no port" detection in evaluated upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6290
diff
changeset
|
643 ngx_http_upstream_finalize_request(r, u, |
6313 | 644 NGX_HTTP_INTERNAL_SERVER_ERROR); |
6303
a93345ee8f52
Upstream: fixed "no port" detection in evaluated upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6290
diff
changeset
|
645 return; |
a93345ee8f52
Upstream: fixed "no port" detection in evaluated upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6290
diff
changeset
|
646 } |
a93345ee8f52
Upstream: fixed "no port" detection in evaluated upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6290
diff
changeset
|
647 |
2422
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2413
diff
changeset
|
648 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
|
649 != NGX_OK) |
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2413
diff
changeset
|
650 { |
3169
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
651 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
|
652 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
|
653 return; |
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2413
diff
changeset
|
654 } |
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2413
diff
changeset
|
655 |
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2413
diff
changeset
|
656 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
|
657 |
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2413
diff
changeset
|
658 return; |
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2413
diff
changeset
|
659 } |
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2413
diff
changeset
|
660 |
1658 | 661 umcf = ngx_http_get_module_main_conf(r, ngx_http_upstream_module); |
662 | |
663 uscfp = umcf->upstreams.elts; | |
664 | |
665 for (i = 0; i < umcf->upstreams.nelts; i++) { | |
666 | |
667 uscf = uscfp[i]; | |
668 | |
669 if (uscf->host.len == host->len | |
2285 | 670 && ((uscf->port == 0 && u->resolved->no_port) |
1912 | 671 || 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
|
672 && ngx_strncasecmp(uscf->host.data, host->data, host->len) == 0) |
1658 | 673 { |
674 goto found; | |
675 } | |
676 } | |
677 | |
3879
502a6b0acf3f
fix case when a host in fastcgi_pass, scgi_pass, and uwsgi_pass
Igor Sysoev <igor@sysoev.ru>
parents:
3713
diff
changeset
|
678 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
|
679 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
|
680 "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
|
681 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
|
682 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
|
683 return; |
502a6b0acf3f
fix case when a host in fastcgi_pass, scgi_pass, and uwsgi_pass
Igor Sysoev <igor@sysoev.ru>
parents:
3713
diff
changeset
|
684 } |
502a6b0acf3f
fix case when a host in fastcgi_pass, scgi_pass, and uwsgi_pass
Igor Sysoev <igor@sysoev.ru>
parents:
3713
diff
changeset
|
685 |
1658 | 686 temp.name = *host; |
687 | |
688 ctx = ngx_resolve_start(clcf->resolver, &temp); | |
689 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
|
690 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
|
691 NGX_HTTP_INTERNAL_SERVER_ERROR); |
1658 | 692 return; |
693 } | |
694 | |
1683
1e0b028055ec
allow to use IP addresses without defined resolver
Igor Sysoev <igor@sysoev.ru>
parents:
1658
diff
changeset
|
695 if (ctx == NGX_NO_RESOLVER) { |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
696 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
|
697 "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
|
698 |
3169
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
699 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
|
700 return; |
1e0b028055ec
allow to use IP addresses without defined resolver
Igor Sysoev <igor@sysoev.ru>
parents:
1658
diff
changeset
|
701 } |
1e0b028055ec
allow to use IP addresses without defined resolver
Igor Sysoev <igor@sysoev.ru>
parents:
1658
diff
changeset
|
702 |
1658 | 703 ctx->name = *host; |
704 ctx->handler = ngx_http_upstream_resolve_handler; | |
705 ctx->data = r; | |
706 ctx->timeout = clcf->resolver_timeout; | |
707 | |
1959
4f16186f5603
quick resolving handles u->resolved->ctx by itself
Igor Sysoev <igor@sysoev.ru>
parents:
1958
diff
changeset
|
708 u->resolved->ctx = ctx; |
4f16186f5603
quick resolving handles u->resolved->ctx by itself
Igor Sysoev <igor@sysoev.ru>
parents:
1958
diff
changeset
|
709 |
1658 | 710 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
|
711 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
|
712 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
|
713 NGX_HTTP_INTERNAL_SERVER_ERROR); |
1658 | 714 return; |
715 } | |
716 | |
717 return; | |
718 } | |
719 | |
720 found: | |
721 | |
4964
2464ccebdb52
Upstream: fixed SIGSEGV with the "if" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4916
diff
changeset
|
722 if (uscf == NULL) { |
2464ccebdb52
Upstream: fixed SIGSEGV with the "if" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4916
diff
changeset
|
723 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
|
724 "no upstream configuration"); |
2464ccebdb52
Upstream: fixed SIGSEGV with the "if" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4916
diff
changeset
|
725 ngx_http_upstream_finalize_request(r, u, |
2464ccebdb52
Upstream: fixed SIGSEGV with the "if" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4916
diff
changeset
|
726 NGX_HTTP_INTERNAL_SERVER_ERROR); |
2464ccebdb52
Upstream: fixed SIGSEGV with the "if" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4916
diff
changeset
|
727 return; |
2464ccebdb52
Upstream: fixed SIGSEGV with the "if" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4916
diff
changeset
|
728 } |
2464ccebdb52
Upstream: fixed SIGSEGV with the "if" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4916
diff
changeset
|
729 |
5682
110b50657d77
Upstream: restored workaround for "if".
Maxim Dounin <mdounin@mdounin.ru>
parents:
5677
diff
changeset
|
730 #if (NGX_HTTP_SSL) |
110b50657d77
Upstream: restored workaround for "if".
Maxim Dounin <mdounin@mdounin.ru>
parents:
5677
diff
changeset
|
731 u->ssl_name = uscf->host; |
110b50657d77
Upstream: restored workaround for "if".
Maxim Dounin <mdounin@mdounin.ru>
parents:
5677
diff
changeset
|
732 #endif |
110b50657d77
Upstream: restored workaround for "if".
Maxim Dounin <mdounin@mdounin.ru>
parents:
5677
diff
changeset
|
733 |
1658 | 734 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
|
735 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
|
736 NGX_HTTP_INTERNAL_SERVER_ERROR); |
1658 | 737 return; |
738 } | |
739 | |
5832
d09b689911ac
Upstream: limited next_upstream time and tries (ticket #544).
Roman Arutyunyan <arut@nginx.com>
parents:
5827
diff
changeset
|
740 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
|
741 |
d09b689911ac
Upstream: limited next_upstream time and tries (ticket #544).
Roman Arutyunyan <arut@nginx.com>
parents:
5827
diff
changeset
|
742 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
|
743 && 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
|
744 { |
d09b689911ac
Upstream: limited next_upstream time and tries (ticket #544).
Roman Arutyunyan <arut@nginx.com>
parents:
5827
diff
changeset
|
745 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
|
746 } |
d09b689911ac
Upstream: limited next_upstream time and tries (ticket #544).
Roman Arutyunyan <arut@nginx.com>
parents:
5827
diff
changeset
|
747 |
479 | 748 ngx_http_upstream_connect(r, u); |
749 } | |
750 | |
751 | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
752 #if (NGX_HTTP_CACHE) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
753 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
754 static ngx_int_t |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
755 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
|
756 { |
5951
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
757 ngx_int_t rc; |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
758 ngx_http_cache_t *c; |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
759 ngx_http_file_cache_t *cache; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
760 |
3056
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
761 c = r->cache; |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
762 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
763 if (c == NULL) { |
3056
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
764 |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
765 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
|
766 return NGX_DECLINED; |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
767 } |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
768 |
5951
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
769 rc = ngx_http_upstream_cache_get(r, u, &cache); |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
770 |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
771 if (rc != NGX_OK) { |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
772 return rc; |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
773 } |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
774 |
6306
b1858fc47e3b
Style: unified request method checks.
Ruslan Ermilov <ru@nginx.com>
parents:
6303
diff
changeset
|
775 if (r->method == NGX_HTTP_HEAD && u->conf->cache_convert_head) { |
3056
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
776 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
|
777 } |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
778 |
3698
d11227f0107f
rename ngx_http_file_cache_create() to ngx_http_file_cache_new()
Igor Sysoev <igor@sysoev.ru>
parents:
3697
diff
changeset
|
779 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
|
780 return NGX_ERROR; |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
781 } |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
782 |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
783 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
|
784 return NGX_ERROR; |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
785 } |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
786 |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
787 /* TODO: add keys */ |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
788 |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
789 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
|
790 |
3976
215fe9223419
update r3945 with more descriptive error message
Igor Sysoev <igor@sysoev.ru>
parents:
3963
diff
changeset
|
791 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
|
792 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
|
793 "%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
|
794 "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
|
795 &u->conf->module, u->conf->buffer_size, |
215fe9223419
update r3945 with more descriptive error message
Igor Sysoev <igor@sysoev.ru>
parents:
3963
diff
changeset
|
796 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
|
797 |
f1f194ceab16
fix segfault if cache key is larger than upstream buffer size
Igor Sysoev <igor@sysoev.ru>
parents:
3940
diff
changeset
|
798 r->cache = NULL; |
f1f194ceab16
fix segfault if cache key is larger than upstream buffer size
Igor Sysoev <igor@sysoev.ru>
parents:
3940
diff
changeset
|
799 return NGX_DECLINED; |
f1f194ceab16
fix segfault if cache key is larger than upstream buffer size
Igor Sysoev <igor@sysoev.ru>
parents:
3940
diff
changeset
|
800 } |
f1f194ceab16
fix segfault if cache key is larger than upstream buffer size
Igor Sysoev <igor@sysoev.ru>
parents:
3940
diff
changeset
|
801 |
4176
2b5151a2300b
Fixed cache bypass caching of non-cacheable replies (ticket #21).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4152
diff
changeset
|
802 u->cacheable = 1; |
2b5151a2300b
Fixed cache bypass caching of non-cacheable replies (ticket #21).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4152
diff
changeset
|
803 |
5950
eaeecf00d5d7
Upstream: preset some cache configuration when bypassing.
Valentin Bartenev <vbart@nginx.com>
parents:
5949
diff
changeset
|
804 c = r->cache; |
eaeecf00d5d7
Upstream: preset some cache configuration when bypassing.
Valentin Bartenev <vbart@nginx.com>
parents:
5949
diff
changeset
|
805 |
eaeecf00d5d7
Upstream: preset some cache configuration when bypassing.
Valentin Bartenev <vbart@nginx.com>
parents:
5949
diff
changeset
|
806 c->body_start = u->conf->buffer_size; |
eaeecf00d5d7
Upstream: preset some cache configuration when bypassing.
Valentin Bartenev <vbart@nginx.com>
parents:
5949
diff
changeset
|
807 c->min_uses = u->conf->cache_min_uses; |
5951
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
808 c->file_cache = cache; |
5950
eaeecf00d5d7
Upstream: preset some cache configuration when bypassing.
Valentin Bartenev <vbart@nginx.com>
parents:
5949
diff
changeset
|
809 |
3917
2a70484a6580
fix a broken cached response if bypass/no_cache directive values are different,
Igor Sysoev <igor@sysoev.ru>
parents:
3898
diff
changeset
|
810 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
|
811 |
2a70484a6580
fix a broken cached response if bypass/no_cache directive values are different,
Igor Sysoev <igor@sysoev.ru>
parents:
3898
diff
changeset
|
812 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
|
813 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
|
814 |
2a70484a6580
fix a broken cached response if bypass/no_cache directive values are different,
Igor Sysoev <igor@sysoev.ru>
parents:
3898
diff
changeset
|
815 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
|
816 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
|
817 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
|
818 |
2a70484a6580
fix a broken cached response if bypass/no_cache directive values are different,
Igor Sysoev <igor@sysoev.ru>
parents:
3898
diff
changeset
|
819 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
|
820 break; |
2a70484a6580
fix a broken cached response if bypass/no_cache directive values are different,
Igor Sysoev <igor@sysoev.ru>
parents:
3898
diff
changeset
|
821 } |
2a70484a6580
fix a broken cached response if bypass/no_cache directive values are different,
Igor Sysoev <igor@sysoev.ru>
parents:
3898
diff
changeset
|
822 |
4385
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4375
diff
changeset
|
823 c->lock = u->conf->cache_lock; |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4375
diff
changeset
|
824 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
|
825 c->lock_age = u->conf->cache_lock_age; |
4385
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4375
diff
changeset
|
826 |
3056
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
827 u->cache_status = NGX_HTTP_CACHE_MISS; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
828 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
829 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
830 rc = ngx_http_file_cache_open(r); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
831 |
2926
80a314b63c56
delete useless r->cache->uses
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
832 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
|
833 "http upstream cache: %i", rc); |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
834 |
2952 | 835 switch (rc) { |
836 | |
837 case NGX_HTTP_CACHE_UPDATING: | |
838 | |
2927
55ceaef03d34
proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents:
2926
diff
changeset
|
839 if (u->conf->cache_use_stale & NGX_HTTP_UPSTREAM_FT_UPDATING) { |
2952 | 840 u->cache_status = rc; |
2927
55ceaef03d34
proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents:
2926
diff
changeset
|
841 rc = NGX_OK; |
55ceaef03d34
proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents:
2926
diff
changeset
|
842 |
55ceaef03d34
proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents:
2926
diff
changeset
|
843 } else { |
55ceaef03d34
proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents:
2926
diff
changeset
|
844 rc = NGX_HTTP_CACHE_STALE; |
55ceaef03d34
proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents:
2926
diff
changeset
|
845 } |
2952 | 846 |
847 break; | |
848 | |
849 case NGX_OK: | |
850 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
|
851 } |
55ceaef03d34
proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents:
2926
diff
changeset
|
852 |
2952 | 853 switch (rc) { |
854 | |
855 case NGX_OK: | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
856 |
6242
0e3a45ec2a3a
Upstream: fixed cache send error handling.
Roman Arutyunyan <arut@nginx.com>
parents:
6180
diff
changeset
|
857 return NGX_OK; |
2952 | 858 |
859 case NGX_HTTP_CACHE_STALE: | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
860 |
2665
4d627567c324
fix r2664: ..._cache_valid did not work for stale responses
Igor Sysoev <igor@sysoev.ru>
parents:
2664
diff
changeset
|
861 c->valid_sec = 0; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
862 u->buffer.start = NULL; |
2952 | 863 u->cache_status = NGX_HTTP_CACHE_EXPIRED; |
864 | |
865 break; | |
866 | |
867 case NGX_DECLINED: | |
2592
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 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
|
870 u->buffer.start = NULL; |
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 } else { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
873 u->buffer.pos = u->buffer.start + c->header_start; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
874 u->buffer.last = u->buffer.pos; |
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 |
2952 | 877 break; |
878 | |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
879 case NGX_HTTP_CACHE_SCARCE: |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
880 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
881 u->cacheable = 0; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
882 |
2952 | 883 break; |
884 | |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
885 case NGX_AGAIN: |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
886 |
3055
92b6cfaa3c27
fix sending a cached file using AIO
Igor Sysoev <igor@sysoev.ru>
parents:
3053
diff
changeset
|
887 return NGX_BUSY; |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
888 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
889 case NGX_ERROR: |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
890 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
891 return NGX_ERROR; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
892 |
2952 | 893 default: |
2592
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 /* 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
|
896 |
2952 | 897 u->cache_status = NGX_HTTP_CACHE_HIT; |
898 | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
899 return rc; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
900 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
901 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
902 r->cached = 0; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
903 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
904 return NGX_DECLINED; |
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 |
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 static ngx_int_t |
5951
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
909 ngx_http_upstream_cache_get(ngx_http_request_t *r, ngx_http_upstream_t *u, |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
910 ngx_http_file_cache_t **cache) |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
911 { |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
912 ngx_str_t *name, val; |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
913 ngx_uint_t i; |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
914 ngx_http_file_cache_t **caches; |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
915 |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
916 if (u->conf->cache_zone) { |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
917 *cache = u->conf->cache_zone->data; |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
918 return NGX_OK; |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
919 } |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
920 |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
921 if (ngx_http_complex_value(r, u->conf->cache_value, &val) != NGX_OK) { |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
922 return NGX_ERROR; |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
923 } |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
924 |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
925 if (val.len == 0 |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
926 || (val.len == 3 && ngx_strncmp(val.data, "off", 3) == 0)) |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
927 { |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
928 return NGX_DECLINED; |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
929 } |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
930 |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
931 caches = u->caches->elts; |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
932 |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
933 for (i = 0; i < u->caches->nelts; i++) { |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
934 name = &caches[i]->shm_zone->shm.name; |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
935 |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
936 if (name->len == val.len |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
937 && ngx_strncmp(name->data, val.data, val.len) == 0) |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
938 { |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
939 *cache = caches[i]; |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
940 return NGX_OK; |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
941 } |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
942 } |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
943 |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
944 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
945 "cache \"%V\" not found", &val); |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
946 |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
947 return NGX_ERROR; |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
948 } |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
949 |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
950 |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
951 static ngx_int_t |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
952 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
|
953 { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
954 ngx_int_t rc; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
955 ngx_http_cache_t *c; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
956 |
2952 | 957 r->cached = 1; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
958 c = r->cache; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
959 |
3369
479468a7d982
fix handling cached HTTP/0.9 response
Igor Sysoev <igor@sysoev.ru>
parents:
3272
diff
changeset
|
960 if (c->header_start == c->body_start) { |
479468a7d982
fix handling cached HTTP/0.9 response
Igor Sysoev <igor@sysoev.ru>
parents:
3272
diff
changeset
|
961 r->http_version = NGX_HTTP_VERSION_9; |
479468a7d982
fix handling cached HTTP/0.9 response
Igor Sysoev <igor@sysoev.ru>
parents:
3272
diff
changeset
|
962 return ngx_http_cache_send(r); |
479468a7d982
fix handling cached HTTP/0.9 response
Igor Sysoev <igor@sysoev.ru>
parents:
3272
diff
changeset
|
963 } |
479468a7d982
fix handling cached HTTP/0.9 response
Igor Sysoev <igor@sysoev.ru>
parents:
3272
diff
changeset
|
964 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
965 /* TODO: cache stack */ |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
966 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
967 u->buffer = *c->buf; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
968 u->buffer.pos += c->header_start; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
969 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
970 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
|
971 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
|
972 u->headers_in.last_modified_time = -1; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
973 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
974 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
|
975 sizeof(ngx_table_elt_t)) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
976 != NGX_OK) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
977 { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
978 return NGX_ERROR; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
979 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
980 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
981 rc = u->process_header(r); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
982 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
983 if (rc == NGX_OK) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
984 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
985 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
|
986 return NGX_DONE; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
987 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
988 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
989 return ngx_http_cache_send(r); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
990 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
991 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
992 if (rc == NGX_ERROR) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
993 return NGX_ERROR; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
994 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
995 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
996 /* rc == NGX_HTTP_UPSTREAM_INVALID_HEADER */ |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
997 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
998 /* TODO: delete file */ |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
999 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1000 return rc; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1001 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1002 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1003 #endif |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1004 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1005 |
487 | 1006 static void |
1658 | 1007 ngx_http_upstream_resolve_handler(ngx_resolver_ctx_t *ctx) |
1008 { | |
5113
08b36f2afc3f
Upstream: fixed previous commit.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5112
diff
changeset
|
1009 ngx_connection_t *c; |
1658 | 1010 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
|
1011 ngx_http_upstream_t *u; |
1658 | 1012 ngx_http_upstream_resolved_t *ur; |
1013 | |
1014 r = ctx->data; | |
5113
08b36f2afc3f
Upstream: fixed previous commit.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5112
diff
changeset
|
1015 c = r->connection; |
1658 | 1016 |
3169
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
1017 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
|
1018 ur = u->resolved; |
1658 | 1019 |
5928
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5911
diff
changeset
|
1020 ngx_http_set_log_request(c->log, r); |
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5911
diff
changeset
|
1021 |
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5911
diff
changeset
|
1022 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, |
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5911
diff
changeset
|
1023 "http upstream resolve: \"%V?%V\"", &r->uri, &r->args); |
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5911
diff
changeset
|
1024 |
1658 | 1025 if (ctx->state) { |
1026 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
1027 "%V could not be resolved (%i: %s)", | |
1028 &ctx->name, ctx->state, | |
1029 ngx_resolver_strerror(ctx->state)); | |
1030 | |
3169
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
1031 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
|
1032 goto failed; |
1658 | 1033 } |
1034 | |
1035 ur->naddrs = ctx->naddrs; | |
1036 ur->addrs = ctx->addrs; | |
1037 | |
1038 #if (NGX_DEBUG) | |
1039 { | |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5453
diff
changeset
|
1040 u_char text[NGX_SOCKADDR_STRLEN]; |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5453
diff
changeset
|
1041 ngx_str_t addr; |
1658 | 1042 ngx_uint_t i; |
1043 | |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5453
diff
changeset
|
1044 addr.data = text; |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5453
diff
changeset
|
1045 |
1658 | 1046 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
|
1047 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
|
1048 text, NGX_SOCKADDR_STRLEN, 0); |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5453
diff
changeset
|
1049 |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5453
diff
changeset
|
1050 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
|
1051 "name was resolved to %V", &addr); |
1658 | 1052 } |
1053 } | |
1054 #endif | |
1055 | |
1056 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
|
1057 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
|
1058 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
|
1059 goto failed; |
1658 | 1060 } |
1061 | |
1062 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
|
1063 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
|
1064 |
5885
5a042519bfe7
Upstream: limited next_upstream time and tries when resolving DNS.
Gu Feng <flygoast@126.com>
parents:
5883
diff
changeset
|
1065 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
|
1066 |
5a042519bfe7
Upstream: limited next_upstream time and tries when resolving DNS.
Gu Feng <flygoast@126.com>
parents:
5883
diff
changeset
|
1067 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
|
1068 && 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
|
1069 { |
5a042519bfe7
Upstream: limited next_upstream time and tries when resolving DNS.
Gu Feng <flygoast@126.com>
parents:
5883
diff
changeset
|
1070 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
|
1071 } |
5a042519bfe7
Upstream: limited next_upstream time and tries when resolving DNS.
Gu Feng <flygoast@126.com>
parents:
5883
diff
changeset
|
1072 |
3169
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
1073 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
|
1074 |
d3c15c7831eb
Upstream: call ngx_http_run_posted_requests() on resolve errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5104
diff
changeset
|
1075 failed: |
d3c15c7831eb
Upstream: call ngx_http_run_posted_requests() on resolve errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5104
diff
changeset
|
1076 |
5113
08b36f2afc3f
Upstream: fixed previous commit.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5112
diff
changeset
|
1077 ngx_http_run_posted_requests(c); |
1658 | 1078 } |
1079 | |
1080 | |
1081 static void | |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1082 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
|
1083 { |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1084 ngx_connection_t *c; |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1085 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
|
1086 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
|
1087 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1088 c = ev->data; |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1089 r = c->data; |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1090 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1091 u = r->upstream; |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1092 c = r->connection; |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1093 |
5928
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5911
diff
changeset
|
1094 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
|
1095 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1096 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
|
1097 "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
|
1098 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1099 if (ev->write) { |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1100 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
|
1101 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1102 } else { |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1103 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
|
1104 } |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1105 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1106 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
|
1107 } |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1108 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1109 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1110 static void |
509 | 1111 ngx_http_upstream_rd_check_broken_connection(ngx_http_request_t *r) |
1112 { | |
1113 ngx_http_upstream_check_broken_connection(r, r->connection->read); | |
1114 } | |
1115 | |
1116 | |
1117 static void | |
1118 ngx_http_upstream_wr_check_broken_connection(ngx_http_request_t *r) | |
1119 { | |
1120 ngx_http_upstream_check_broken_connection(r, r->connection->write); | |
1121 } | |
1122 | |
1123 | |
1124 static void | |
1125 ngx_http_upstream_check_broken_connection(ngx_http_request_t *r, | |
1126 ngx_event_t *ev) | |
479 | 1127 { |
1128 int n; | |
1129 char buf[1]; | |
577 | 1130 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
|
1131 ngx_int_t event; |
479 | 1132 ngx_connection_t *c; |
1133 ngx_http_upstream_t *u; | |
1134 | |
527 | 1135 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, ev->log, 0, |
1136 "http upstream check client, write event:%d, \"%V\"", | |
1137 ev->write, &r->uri); | |
479 | 1138 |
509 | 1139 c = r->connection; |
483 | 1140 u = r->upstream; |
1141 | |
583 | 1142 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
|
1143 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
|
1144 |
6ad4bba6313e
delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents:
2805
diff
changeset
|
1145 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
|
1146 |
6ad4bba6313e
delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents:
2805
diff
changeset
|
1147 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
|
1148 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
|
1149 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
|
1150 return; |
6ad4bba6313e
delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents:
2805
diff
changeset
|
1151 } |
6ad4bba6313e
delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents:
2805
diff
changeset
|
1152 } |
6ad4bba6313e
delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents:
2805
diff
changeset
|
1153 |
2757
9cc973b46af1
get a full response if the response is cacheable or storable even
Igor Sysoev <igor@sysoev.ru>
parents:
2708
diff
changeset
|
1154 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
|
1155 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
|
1156 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
|
1157 } |
2807
6ad4bba6313e
delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents:
2805
diff
changeset
|
1158 |
527 | 1159 return; |
1160 } | |
1161 | |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
6242
diff
changeset
|
1162 #if (NGX_HTTP_V2) |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
6242
diff
changeset
|
1163 if (r->stream) { |
5121
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
5113
diff
changeset
|
1164 return; |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
5113
diff
changeset
|
1165 } |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
5113
diff
changeset
|
1166 #endif |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
5113
diff
changeset
|
1167 |
479 | 1168 #if (NGX_HAVE_KQUEUE) |
1169 | |
1170 if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) { | |
1171 | |
1172 if (!ev->pending_eof) { | |
1173 return; | |
1174 } | |
1175 | |
1176 ev->eof = 1; | |
583 | 1177 c->error = 1; |
479 | 1178 |
1179 if (ev->kq_errno) { | |
1180 ev->error = 1; | |
1181 } | |
1182 | |
2757
9cc973b46af1
get a full response if the response is cacheable or storable even
Igor Sysoev <igor@sysoev.ru>
parents:
2708
diff
changeset
|
1183 if (!u->cacheable && u->peer.connection) { |
479 | 1184 ngx_log_error(NGX_LOG_INFO, ev->log, ev->kq_errno, |
4182 | 1185 "kevent() reported that client prematurely closed " |
527 | 1186 "connection, so upstream connection is closed too"); |
479 | 1187 ngx_http_upstream_finalize_request(r, u, |
1188 NGX_HTTP_CLIENT_CLOSED_REQUEST); | |
1189 return; | |
1190 } | |
1191 | |
1192 ngx_log_error(NGX_LOG_INFO, ev->log, ev->kq_errno, | |
4182 | 1193 "kevent() reported that client prematurely closed " |
1194 "connection"); | |
479 | 1195 |
1196 if (u->peer.connection == NULL) { | |
1197 ngx_http_upstream_finalize_request(r, u, | |
1198 NGX_HTTP_CLIENT_CLOSED_REQUEST); | |
1199 } | |
1200 | |
1201 return; | |
1202 } | |
1203 | |
1204 #endif | |
1205 | |
5373
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1206 #if (NGX_HAVE_EPOLLRDHUP) |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1207 |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1208 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
|
1209 socklen_t len; |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1210 |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1211 ev->eof = 1; |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1212 c->error = 1; |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1213 |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1214 err = 0; |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1215 len = sizeof(ngx_err_t); |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1216 |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1217 /* |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1218 * 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
|
1219 * 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
|
1220 */ |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1221 |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1222 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
|
1223 == -1) |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1224 { |
5557
188481078faf
Use ngx_socket_errno where appropriate.
Piotr Sikora <piotr@cloudflare.com>
parents:
5546
diff
changeset
|
1225 err = ngx_socket_errno; |
5373
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1226 } |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1227 |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1228 if (err) { |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1229 ev->error = 1; |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1230 } |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1231 |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1232 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
|
1233 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
|
1234 "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
|
1235 "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
|
1236 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
|
1237 NGX_HTTP_CLIENT_CLOSED_REQUEST); |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1238 return; |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1239 } |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1240 |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1241 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
|
1242 "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
|
1243 "connection"); |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1244 |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1245 if (u->peer.connection == NULL) { |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1246 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
|
1247 NGX_HTTP_CLIENT_CLOSED_REQUEST); |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1248 } |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1249 |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1250 return; |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1251 } |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1252 |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1253 #endif |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1254 |
479 | 1255 n = recv(c->fd, buf, 1, MSG_PEEK); |
1256 | |
1257 err = ngx_socket_errno; | |
1258 | |
1109 | 1259 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ev->log, err, |
1260 "http upstream recv(): %d", n); | |
1261 | |
479 | 1262 if (ev->write && (n >= 0 || err == NGX_EAGAIN)) { |
1263 return; | |
1264 } | |
1265 | |
1266 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
|
1267 |
6ad4bba6313e
delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents:
2805
diff
changeset
|
1268 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
|
1269 |
6ad4bba6313e
delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents:
2805
diff
changeset
|
1270 if (ngx_del_event(ev, event, 0) != NGX_OK) { |
479 | 1271 ngx_http_upstream_finalize_request(r, u, |
1272 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
1273 return; | |
1274 } | |
1275 } | |
1276 | |
1277 if (n > 0) { | |
1278 return; | |
1279 } | |
1280 | |
1281 if (n == -1) { | |
1282 if (err == NGX_EAGAIN) { | |
1283 return; | |
1284 } | |
1285 | |
1286 ev->error = 1; | |
1287 | |
483 | 1288 } else { /* n == 0 */ |
479 | 1289 err = 0; |
1290 } | |
1291 | |
529 | 1292 ev->eof = 1; |
583 | 1293 c->error = 1; |
529 | 1294 |
2757
9cc973b46af1
get a full response if the response is cacheable or storable even
Igor Sysoev <igor@sysoev.ru>
parents:
2708
diff
changeset
|
1295 if (!u->cacheable && u->peer.connection) { |
479 | 1296 ngx_log_error(NGX_LOG_INFO, ev->log, err, |
4182 | 1297 "client prematurely closed connection, " |
479 | 1298 "so upstream connection is closed too"); |
1299 ngx_http_upstream_finalize_request(r, u, | |
1300 NGX_HTTP_CLIENT_CLOSED_REQUEST); | |
1301 return; | |
1302 } | |
1303 | |
1304 ngx_log_error(NGX_LOG_INFO, ev->log, err, | |
4182 | 1305 "client prematurely closed connection"); |
479 | 1306 |
1307 if (u->peer.connection == NULL) { | |
1308 ngx_http_upstream_finalize_request(r, u, | |
1309 NGX_HTTP_CLIENT_CLOSED_REQUEST); | |
1310 } | |
1311 } | |
1312 | |
1313 | |
487 | 1314 static void |
1315 ngx_http_upstream_connect(ngx_http_request_t *r, ngx_http_upstream_t *u) | |
479 | 1316 { |
591 | 1317 ngx_int_t rc; |
1318 ngx_connection_t *c; | |
479 | 1319 |
483 | 1320 r->connection->log->action = "connecting to upstream"; |
479 | 1321 |
6146
59fc60585f1e
Upstream: times to obtain header/response are stored as ngx_msec_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6125
diff
changeset
|
1322 if (u->state && u->state->response_time) { |
59fc60585f1e
Upstream: times to obtain header/response are stored as ngx_msec_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6125
diff
changeset
|
1323 u->state->response_time = ngx_current_msec - u->state->response_time; |
665 | 1324 } |
1325 | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
1326 u->state = ngx_array_push(r->upstream_states); |
665 | 1327 if (u->state == NULL) { |
1328 ngx_http_upstream_finalize_request(r, u, | |
1329 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
1330 return; | |
1331 } | |
1332 | |
1333 ngx_memzero(u->state, sizeof(ngx_http_upstream_state_t)); | |
1334 | |
6146
59fc60585f1e
Upstream: times to obtain header/response are stored as ngx_msec_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6125
diff
changeset
|
1335 u->state->response_time = ngx_current_msec; |
6147
74b6ef56ea56
Upstream: $upstream_connect_time.
Ruslan Ermilov <ru@nginx.com>
parents:
6146
diff
changeset
|
1336 u->state->connect_time = (ngx_msec_t) -1; |
6146
59fc60585f1e
Upstream: times to obtain header/response are stored as ngx_msec_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6125
diff
changeset
|
1337 u->state->header_time = (ngx_msec_t) -1; |
665 | 1338 |
479 | 1339 rc = ngx_event_connect_peer(&u->peer); |
1340 | |
1341 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
1342 "http upstream connect: %i", rc); | |
1343 | |
1344 if (rc == NGX_ERROR) { | |
1345 ngx_http_upstream_finalize_request(r, u, | |
1346 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
1347 return; | |
1348 } | |
1349 | |
1707
f3188f6eae1f
$upstream_addr did not contain last address, the bug was introduced in r1659
Igor Sysoev <igor@sysoev.ru>
parents:
1706
diff
changeset
|
1350 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
|
1351 |
543 | 1352 if (rc == NGX_BUSY) { |
1353 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "no live upstreams"); | |
1378 | 1354 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_NOLIVE); |
1355 return; | |
543 | 1356 } |
1357 | |
1378 | 1358 if (rc == NGX_DECLINED) { |
479 | 1359 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR); |
1360 return; | |
1361 } | |
1362 | |
5261
af60a210cb78
Upstream: updated list of ngx_event_connect_peer() return values.
Ruslan Ermilov <ru@nginx.com>
parents:
5231
diff
changeset
|
1363 /* rc == NGX_OK || rc == NGX_AGAIN || rc == NGX_DONE */ |
577 | 1364 |
479 | 1365 c = u->peer.connection; |
1366 | |
1367 c->data = r; | |
591 | 1368 |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1369 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
|
1370 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
|
1371 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1372 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
|
1373 u->read_event_handler = ngx_http_upstream_process_header; |
479 | 1374 |
1397
6c25a49e548a
upstream sendfile bit was overridden by r->connection->sendfile
Igor Sysoev <igor@sysoev.ru>
parents:
1378
diff
changeset
|
1375 c->sendfile &= r->connection->sendfile; |
1958 | 1376 u->output.sendfile = c->sendfile; |
479 | 1377 |
4116
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1378 if (c->pool == NULL) { |
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1379 |
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1380 /* 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
|
1381 |
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1382 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
|
1383 if (c->pool == NULL) { |
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1384 ngx_http_upstream_finalize_request(r, u, |
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1385 NGX_HTTP_INTERNAL_SERVER_ERROR); |
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1386 return; |
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1387 } |
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1388 } |
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1389 |
2847 | 1390 c->log = r->connection->log; |
4116
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1391 c->pool->log = c->log; |
2847 | 1392 c->read->log = c->log; |
1393 c->write->log = c->log; | |
479 | 1394 |
1395 /* init or reinit the ngx_output_chain() and ngx_chain_writer() contexts */ | |
1396 | |
1397 u->writer.out = NULL; | |
1398 u->writer.last = &u->writer.out; | |
1399 u->writer.connection = c; | |
1400 u->writer.limit = 0; | |
1401 | |
1402 if (u->request_sent) { | |
509 | 1403 if (ngx_http_upstream_reinit(r, u) != NGX_OK) { |
1404 ngx_http_upstream_finalize_request(r, u, | |
1405 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
1406 return; | |
1407 } | |
479 | 1408 } |
1409 | |
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
|
1410 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
|
1411 && 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
|
1412 && 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
|
1413 && 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
|
1414 { |
573 | 1415 /* |
1416 * 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
|
1417 * the subrequests should allocate their own temporary bufs |
573 | 1418 */ |
1419 | |
1420 u->output.free = ngx_alloc_chain_link(r->pool); | |
1421 if (u->output.free == NULL) { | |
1422 ngx_http_upstream_finalize_request(r, u, | |
1423 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
1424 return; | |
479 | 1425 } |
573 | 1426 |
1427 u->output.free->buf = r->request_body->buf; | |
1428 u->output.free->next = NULL; | |
1429 u->output.allocated = 1; | |
1430 | |
1431 r->request_body->buf->pos = r->request_body->buf->start; | |
1432 r->request_body->buf->last = r->request_body->buf->start; | |
1433 r->request_body->buf->tag = u->output.tag; | |
479 | 1434 } |
1435 | |
1436 u->request_sent = 0; | |
1437 | |
1438 if (rc == NGX_AGAIN) { | |
1439 ngx_add_timer(c->write, u->conf->connect_timeout); | |
1440 return; | |
1441 } | |
1442 | |
577 | 1443 #if (NGX_HTTP_SSL) |
1444 | |
1658 | 1445 if (u->ssl && c->ssl == NULL) { |
591 | 1446 ngx_http_upstream_ssl_init_connection(r, u, c); |
577 | 1447 return; |
1448 } | |
1449 | |
1450 #endif | |
1451 | |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1452 ngx_http_upstream_send_request(r, u, 1); |
479 | 1453 } |
1454 | |
1455 | |
577 | 1456 #if (NGX_HTTP_SSL) |
1457 | |
1458 static void | |
591 | 1459 ngx_http_upstream_ssl_init_connection(ngx_http_request_t *r, |
1460 ngx_http_upstream_t *u, ngx_connection_t *c) | |
1461 { | |
6068
643f2ce02f1c
Upstream: abbreviated SSL handshake may interact badly with Nagle.
Ruslan Ermilov <ru@nginx.com>
parents:
6050
diff
changeset
|
1462 int tcp_nodelay; |
643f2ce02f1c
Upstream: abbreviated SSL handshake may interact badly with Nagle.
Ruslan Ermilov <ru@nginx.com>
parents:
6050
diff
changeset
|
1463 ngx_int_t rc; |
643f2ce02f1c
Upstream: abbreviated SSL handshake may interact badly with Nagle.
Ruslan Ermilov <ru@nginx.com>
parents:
6050
diff
changeset
|
1464 ngx_http_core_loc_conf_t *clcf; |
591 | 1465 |
5305
12b750d35162
Upstream: reliably detect connection failures with SSL peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5304
diff
changeset
|
1466 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
|
1467 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
|
1468 return; |
12b750d35162
Upstream: reliably detect connection failures with SSL peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5304
diff
changeset
|
1469 } |
12b750d35162
Upstream: reliably detect connection failures with SSL peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5304
diff
changeset
|
1470 |
591 | 1471 if (ngx_ssl_create_connection(u->conf->ssl, c, |
1472 NGX_SSL_BUFFER|NGX_SSL_CLIENT) | |
2536
a6d6d762c554
small optimization: " == NGX_ERROR" > " != NGX_OK"
Igor Sysoev <igor@sysoev.ru>
parents:
2463
diff
changeset
|
1473 != NGX_OK) |
591 | 1474 { |
1475 ngx_http_upstream_finalize_request(r, u, | |
1476 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
1477 return; | |
1478 } | |
1479 | |
1480 c->sendfile = 0; | |
619 | 1481 u->output.sendfile = 0; |
591 | 1482 |
5661
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1483 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
|
1484 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
|
1485 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
|
1486 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
|
1487 return; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1488 } |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1489 } |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1490 |
2184 | 1491 if (u->conf->ssl_session_reuse) { |
1492 if (u->peer.set_session(&u->peer, u->peer.data) != NGX_OK) { | |
1493 ngx_http_upstream_finalize_request(r, u, | |
1494 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
1495 return; | |
1496 } | |
6068
643f2ce02f1c
Upstream: abbreviated SSL handshake may interact badly with Nagle.
Ruslan Ermilov <ru@nginx.com>
parents:
6050
diff
changeset
|
1497 |
643f2ce02f1c
Upstream: abbreviated SSL handshake may interact badly with Nagle.
Ruslan Ermilov <ru@nginx.com>
parents:
6050
diff
changeset
|
1498 /* abbreviated SSL handshake may interact badly with Nagle */ |
643f2ce02f1c
Upstream: abbreviated SSL handshake may interact badly with Nagle.
Ruslan Ermilov <ru@nginx.com>
parents:
6050
diff
changeset
|
1499 |
643f2ce02f1c
Upstream: abbreviated SSL handshake may interact badly with Nagle.
Ruslan Ermilov <ru@nginx.com>
parents:
6050
diff
changeset
|
1500 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
643f2ce02f1c
Upstream: abbreviated SSL handshake may interact badly with Nagle.
Ruslan Ermilov <ru@nginx.com>
parents:
6050
diff
changeset
|
1501 |
643f2ce02f1c
Upstream: abbreviated SSL handshake may interact badly with Nagle.
Ruslan Ermilov <ru@nginx.com>
parents:
6050
diff
changeset
|
1502 if (clcf->tcp_nodelay && c->tcp_nodelay == NGX_TCP_NODELAY_UNSET) { |
643f2ce02f1c
Upstream: abbreviated SSL handshake may interact badly with Nagle.
Ruslan Ermilov <ru@nginx.com>
parents:
6050
diff
changeset
|
1503 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "tcp_nodelay"); |
643f2ce02f1c
Upstream: abbreviated SSL handshake may interact badly with Nagle.
Ruslan Ermilov <ru@nginx.com>
parents:
6050
diff
changeset
|
1504 |
643f2ce02f1c
Upstream: abbreviated SSL handshake may interact badly with Nagle.
Ruslan Ermilov <ru@nginx.com>
parents:
6050
diff
changeset
|
1505 tcp_nodelay = 1; |
643f2ce02f1c
Upstream: abbreviated SSL handshake may interact badly with Nagle.
Ruslan Ermilov <ru@nginx.com>
parents:
6050
diff
changeset
|
1506 |
643f2ce02f1c
Upstream: abbreviated SSL handshake may interact badly with Nagle.
Ruslan Ermilov <ru@nginx.com>
parents:
6050
diff
changeset
|
1507 if (setsockopt(c->fd, IPPROTO_TCP, TCP_NODELAY, |
643f2ce02f1c
Upstream: abbreviated SSL handshake may interact badly with Nagle.
Ruslan Ermilov <ru@nginx.com>
parents:
6050
diff
changeset
|
1508 (const void *) &tcp_nodelay, sizeof(int)) == -1) |
643f2ce02f1c
Upstream: abbreviated SSL handshake may interact badly with Nagle.
Ruslan Ermilov <ru@nginx.com>
parents:
6050
diff
changeset
|
1509 { |
643f2ce02f1c
Upstream: abbreviated SSL handshake may interact badly with Nagle.
Ruslan Ermilov <ru@nginx.com>
parents:
6050
diff
changeset
|
1510 ngx_connection_error(c, ngx_socket_errno, |
643f2ce02f1c
Upstream: abbreviated SSL handshake may interact badly with Nagle.
Ruslan Ermilov <ru@nginx.com>
parents:
6050
diff
changeset
|
1511 "setsockopt(TCP_NODELAY) failed"); |
643f2ce02f1c
Upstream: abbreviated SSL handshake may interact badly with Nagle.
Ruslan Ermilov <ru@nginx.com>
parents:
6050
diff
changeset
|
1512 ngx_http_upstream_finalize_request(r, u, |
643f2ce02f1c
Upstream: abbreviated SSL handshake may interact badly with Nagle.
Ruslan Ermilov <ru@nginx.com>
parents:
6050
diff
changeset
|
1513 NGX_HTTP_INTERNAL_SERVER_ERROR); |
643f2ce02f1c
Upstream: abbreviated SSL handshake may interact badly with Nagle.
Ruslan Ermilov <ru@nginx.com>
parents:
6050
diff
changeset
|
1514 return; |
643f2ce02f1c
Upstream: abbreviated SSL handshake may interact badly with Nagle.
Ruslan Ermilov <ru@nginx.com>
parents:
6050
diff
changeset
|
1515 } |
643f2ce02f1c
Upstream: abbreviated SSL handshake may interact badly with Nagle.
Ruslan Ermilov <ru@nginx.com>
parents:
6050
diff
changeset
|
1516 |
643f2ce02f1c
Upstream: abbreviated SSL handshake may interact badly with Nagle.
Ruslan Ermilov <ru@nginx.com>
parents:
6050
diff
changeset
|
1517 c->tcp_nodelay = NGX_TCP_NODELAY_SET; |
643f2ce02f1c
Upstream: abbreviated SSL handshake may interact badly with Nagle.
Ruslan Ermilov <ru@nginx.com>
parents:
6050
diff
changeset
|
1518 } |
591 | 1519 } |
1520 | |
641 | 1521 r->connection->log->action = "SSL handshaking to upstream"; |
1522 | |
591 | 1523 rc = ngx_ssl_handshake(c); |
1524 | |
1525 if (rc == NGX_AGAIN) { | |
5774
9bf58a3da25b
Upstream: SSL handshake timeouts.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5770
diff
changeset
|
1526 |
9bf58a3da25b
Upstream: SSL handshake timeouts.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5770
diff
changeset
|
1527 if (!c->write->timer_set) { |
9bf58a3da25b
Upstream: SSL handshake timeouts.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5770
diff
changeset
|
1528 ngx_add_timer(c->write, u->conf->connect_timeout); |
9bf58a3da25b
Upstream: SSL handshake timeouts.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5770
diff
changeset
|
1529 } |
9bf58a3da25b
Upstream: SSL handshake timeouts.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5770
diff
changeset
|
1530 |
591 | 1531 c->ssl->handler = ngx_http_upstream_ssl_handshake; |
1532 return; | |
1533 } | |
1534 | |
1535 ngx_http_upstream_ssl_handshake(c); | |
1536 } | |
1537 | |
1538 | |
1539 static void | |
577 | 1540 ngx_http_upstream_ssl_handshake(ngx_connection_t *c) |
1541 { | |
5661
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1542 long rc; |
577 | 1543 ngx_http_request_t *r; |
1544 ngx_http_upstream_t *u; | |
1545 | |
1546 r = c->data; | |
1547 u = r->upstream; | |
1548 | |
5928
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5911
diff
changeset
|
1549 ngx_http_set_log_request(c->log, r); |
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5911
diff
changeset
|
1550 |
577 | 1551 if (c->ssl->handshaked) { |
1552 | |
5661
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1553 if (u->conf->ssl_verify) { |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1554 rc = SSL_get_verify_result(c->ssl->connection); |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1555 |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1556 if (rc != X509_V_OK) { |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1557 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
|
1558 "upstream SSL certificate verify error: (%l:%s)", |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1559 rc, X509_verify_cert_error_string(rc)); |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1560 goto failed; |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1561 } |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1562 |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1563 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
|
1564 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
|
1565 "upstream SSL certificate does not match \"%V\"", |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1566 &u->ssl_name); |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1567 goto failed; |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1568 } |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1569 } |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1570 |
2184 | 1571 if (u->conf->ssl_session_reuse) { |
1572 u->peer.save_session(&u->peer, u->peer.data); | |
1573 } | |
884 | 1574 |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1575 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
|
1576 c->read->handler = ngx_http_upstream_handler; |
577 | 1577 |
5340
13a5f4765887
Upstream: posted requests handling after ssl handshake errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5305
diff
changeset
|
1578 c = r->connection; |
13a5f4765887
Upstream: posted requests handling after ssl handshake errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5305
diff
changeset
|
1579 |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1580 ngx_http_upstream_send_request(r, u, 1); |
577 | 1581 |
5340
13a5f4765887
Upstream: posted requests handling after ssl handshake errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5305
diff
changeset
|
1582 ngx_http_run_posted_requests(c); |
577 | 1583 return; |
1584 } | |
1585 | |
5661
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1586 failed: |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1587 |
5340
13a5f4765887
Upstream: posted requests handling after ssl handshake errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5305
diff
changeset
|
1588 c = r->connection; |
13a5f4765887
Upstream: posted requests handling after ssl handshake errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5305
diff
changeset
|
1589 |
577 | 1590 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR); |
1591 | |
5340
13a5f4765887
Upstream: posted requests handling after ssl handshake errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5305
diff
changeset
|
1592 ngx_http_run_posted_requests(c); |
577 | 1593 } |
1594 | |
5660
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1595 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1596 static ngx_int_t |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1597 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
|
1598 ngx_connection_t *c) |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1599 { |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1600 u_char *p, *last; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1601 ngx_str_t name; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1602 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1603 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
|
1604 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
|
1605 return NGX_ERROR; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1606 } |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1607 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1608 } else { |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1609 name = u->ssl_name; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1610 } |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1611 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1612 if (name.len == 0) { |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1613 goto done; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1614 } |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1615 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1616 /* |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1617 * 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
|
1618 * 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
|
1619 */ |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1620 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1621 p = name.data; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1622 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
|
1623 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1624 if (*p == '[') { |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1625 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
|
1626 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1627 if (p == NULL) { |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1628 p = name.data; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1629 } |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1630 } |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1631 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1632 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
|
1633 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1634 if (p != NULL) { |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1635 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
|
1636 } |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1637 |
5661
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1638 if (!u->conf->ssl_server_name) { |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1639 goto done; |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1640 } |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1641 |
5660
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1642 #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
|
1643 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1644 /* 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
|
1645 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1646 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
|
1647 goto done; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1648 } |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1649 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1650 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
|
1651 goto done; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1652 } |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1653 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1654 /* |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1655 * 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
|
1656 * 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
|
1657 */ |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1658 |
5667
16405e02e612
Upstream: for ssl name, non-aligned memory allocation is enough.
Ruslan Ermilov <ru@nginx.com>
parents:
5661
diff
changeset
|
1659 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
|
1660 if (p == NULL) { |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1661 return NGX_ERROR; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1662 } |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1663 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1664 (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
|
1665 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1666 name.data = p; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1667 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1668 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
|
1669 "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
|
1670 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1671 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
|
1672 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
|
1673 "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
|
1674 return NGX_ERROR; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1675 } |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1676 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1677 #endif |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1678 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1679 done: |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1680 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1681 u->ssl_name = name; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1682 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1683 return NGX_OK; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1684 } |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1685 |
577 | 1686 #endif |
1687 | |
1688 | |
509 | 1689 static ngx_int_t |
487 | 1690 ngx_http_upstream_reinit(ngx_http_request_t *r, ngx_http_upstream_t *u) |
479 | 1691 { |
5848
106a8bfa4f42
Upstream: fixed file buffers reinit in ngx_http_upstream_reinit().
Roman Arutyunyan <arut@nginx.com>
parents:
5832
diff
changeset
|
1692 off_t file_pos; |
479 | 1693 ngx_chain_t *cl; |
1694 | |
509 | 1695 if (u->reinit_request(r) != NGX_OK) { |
1696 return NGX_ERROR; | |
1697 } | |
1698 | |
4120
42135dd1f0ea
Upstream: keepalive flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4119
diff
changeset
|
1699 u->keepalive = 0; |
5072
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
1700 u->upgrade = 0; |
4120
42135dd1f0ea
Upstream: keepalive flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4119
diff
changeset
|
1701 |
1705 | 1702 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
|
1703 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
|
1704 u->headers_in.last_modified_time = -1; |
1705 | 1705 |
1706 if (ngx_list_init(&u->headers_in.headers, r->pool, 8, | |
591 | 1707 sizeof(ngx_table_elt_t)) |
1708 != NGX_OK) | |
509 | 1709 { |
1710 return NGX_ERROR; | |
479 | 1711 } |
1712 | |
1713 /* reinit the request chain */ | |
577 | 1714 |
5848
106a8bfa4f42
Upstream: fixed file buffers reinit in ngx_http_upstream_reinit().
Roman Arutyunyan <arut@nginx.com>
parents:
5832
diff
changeset
|
1715 file_pos = 0; |
106a8bfa4f42
Upstream: fixed file buffers reinit in ngx_http_upstream_reinit().
Roman Arutyunyan <arut@nginx.com>
parents:
5832
diff
changeset
|
1716 |
509 | 1717 for (cl = u->request_bufs; cl; cl = cl->next) { |
479 | 1718 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
|
1719 |
106a8bfa4f42
Upstream: fixed file buffers reinit in ngx_http_upstream_reinit().
Roman Arutyunyan <arut@nginx.com>
parents:
5832
diff
changeset
|
1720 /* 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
|
1721 |
106a8bfa4f42
Upstream: fixed file buffers reinit in ngx_http_upstream_reinit().
Roman Arutyunyan <arut@nginx.com>
parents:
5832
diff
changeset
|
1722 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
|
1723 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
|
1724 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
|
1725 } |
479 | 1726 } |
1727 | |
509 | 1728 /* reinit the subrequest's ngx_output_chain() context */ |
1729 | |
573 | 1730 if (r->request_body && r->request_body->temp_file |
597 | 1731 && r != r->main && u->output.buf) |
573 | 1732 { |
1733 u->output.free = ngx_alloc_chain_link(r->pool); | |
1734 if (u->output.free == NULL) { | |
1735 return NGX_ERROR; | |
509 | 1736 } |
573 | 1737 |
1738 u->output.free->buf = u->output.buf; | |
1739 u->output.free->next = NULL; | |
1740 | |
1741 u->output.buf->pos = u->output.buf->start; | |
1742 u->output.buf->last = u->output.buf->start; | |
509 | 1743 } |
479 | 1744 |
1745 u->output.buf = NULL; | |
1746 u->output.in = NULL; | |
1747 u->output.busy = NULL; | |
577 | 1748 |
581 | 1749 /* reinit u->buffer */ |
577 | 1750 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1751 u->buffer.pos = u->buffer.start; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1752 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1753 #if (NGX_HTTP_CACHE) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1754 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1755 if (r->cache) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1756 u->buffer.pos += r->cache->header_start; |
479 | 1757 } |
509 | 1758 |
479 | 1759 #endif |
1760 | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1761 u->buffer.last = u->buffer.pos; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1762 |
509 | 1763 return NGX_OK; |
479 | 1764 } |
1765 | |
1766 | |
487 | 1767 static void |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1768 ngx_http_upstream_send_request(ngx_http_request_t *r, ngx_http_upstream_t *u, |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1769 ngx_uint_t do_write) |
479 | 1770 { |
1153
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
1771 ngx_int_t rc; |
483 | 1772 ngx_connection_t *c; |
577 | 1773 |
479 | 1774 c = u->peer.connection; |
1775 | |
1776 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
1777 "http upstream send request"); | |
1778 | |
6147
74b6ef56ea56
Upstream: $upstream_connect_time.
Ruslan Ermilov <ru@nginx.com>
parents:
6146
diff
changeset
|
1779 if (u->state->connect_time == (ngx_msec_t) -1) { |
74b6ef56ea56
Upstream: $upstream_connect_time.
Ruslan Ermilov <ru@nginx.com>
parents:
6146
diff
changeset
|
1780 u->state->connect_time = ngx_current_msec - u->state->response_time; |
74b6ef56ea56
Upstream: $upstream_connect_time.
Ruslan Ermilov <ru@nginx.com>
parents:
6146
diff
changeset
|
1781 } |
74b6ef56ea56
Upstream: $upstream_connect_time.
Ruslan Ermilov <ru@nginx.com>
parents:
6146
diff
changeset
|
1782 |
1153
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
1783 if (!u->request_sent && ngx_http_upstream_test_connect(c) != NGX_OK) { |
1166 | 1784 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
|
1785 return; |
479 | 1786 } |
1787 | |
483 | 1788 c->log->action = "sending request to upstream"; |
479 | 1789 |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1790 rc = ngx_http_upstream_send_request_body(r, u, do_write); |
479 | 1791 |
1792 if (rc == NGX_ERROR) { | |
1793 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR); | |
1794 return; | |
1795 } | |
1796 | |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1797 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1798 ngx_http_upstream_finalize_request(r, u, rc); |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1799 return; |
479 | 1800 } |
1801 | |
1802 if (rc == NGX_AGAIN) { | |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1803 if (!c->write->ready) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1804 ngx_add_timer(c->write, u->conf->send_timeout); |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1805 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1806 } else if (c->write->timer_set) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1807 ngx_del_timer(c->write); |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1808 } |
479 | 1809 |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1810 if (ngx_handle_write_event(c->write, u->conf->send_lowat) != NGX_OK) { |
479 | 1811 ngx_http_upstream_finalize_request(r, u, |
1812 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
1813 return; | |
1814 } | |
1815 | |
1816 return; | |
1817 } | |
1818 | |
1819 /* rc == NGX_OK */ | |
1820 | |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1821 if (c->write->timer_set) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1822 ngx_del_timer(c->write); |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1823 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1824 |
479 | 1825 if (c->tcp_nopush == NGX_TCP_NOPUSH_SET) { |
1826 if (ngx_tcp_push(c->fd) == NGX_ERROR) { | |
1827 ngx_log_error(NGX_LOG_CRIT, c->log, ngx_socket_errno, | |
1828 ngx_tcp_push_n " failed"); | |
1829 ngx_http_upstream_finalize_request(r, u, | |
1830 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
577 | 1831 return; |
479 | 1832 } |
1833 | |
1834 c->tcp_nopush = NGX_TCP_NOPUSH_UNSET; | |
1835 } | |
577 | 1836 |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1837 u->write_event_handler = ngx_http_upstream_dummy_handler; |
479 | 1838 |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1839 if (ngx_handle_write_event(c->write, 0) != NGX_OK) { |
479 | 1840 ngx_http_upstream_finalize_request(r, u, |
1841 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
1842 return; | |
1843 } | |
5745
9d3a9c45fc43
Upstream: fixed handling of write event after sending request.
Valentin Bartenev <vbart@nginx.com>
parents:
5738
diff
changeset
|
1844 |
9d3a9c45fc43
Upstream: fixed handling of write event after sending request.
Valentin Bartenev <vbart@nginx.com>
parents:
5738
diff
changeset
|
1845 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
|
1846 |
9d3a9c45fc43
Upstream: fixed handling of write event after sending request.
Valentin Bartenev <vbart@nginx.com>
parents:
5738
diff
changeset
|
1847 if (c->read->ready) { |
9d3a9c45fc43
Upstream: fixed handling of write event after sending request.
Valentin Bartenev <vbart@nginx.com>
parents:
5738
diff
changeset
|
1848 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
|
1849 return; |
9d3a9c45fc43
Upstream: fixed handling of write event after sending request.
Valentin Bartenev <vbart@nginx.com>
parents:
5738
diff
changeset
|
1850 } |
479 | 1851 } |
1852 | |
1853 | |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1854 static ngx_int_t |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1855 ngx_http_upstream_send_request_body(ngx_http_request_t *r, |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1856 ngx_http_upstream_t *u, ngx_uint_t do_write) |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1857 { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1858 int tcp_nodelay; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1859 ngx_int_t rc; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1860 ngx_chain_t *out, *cl, *ln; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1861 ngx_connection_t *c; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1862 ngx_http_core_loc_conf_t *clcf; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1863 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1864 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1865 "http upstream send request body"); |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1866 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1867 if (!r->request_body_no_buffering) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1868 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1869 /* buffered request body */ |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1870 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1871 if (!u->request_sent) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1872 u->request_sent = 1; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1873 out = u->request_bufs; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1874 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1875 } else { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1876 out = NULL; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1877 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1878 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1879 return ngx_output_chain(&u->output, out); |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1880 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1881 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1882 if (!u->request_sent) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1883 u->request_sent = 1; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1884 out = u->request_bufs; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1885 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1886 if (r->request_body->bufs) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1887 for (cl = out; cl->next; cl = out->next) { /* void */ } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1888 cl->next = r->request_body->bufs; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1889 r->request_body->bufs = NULL; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1890 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1891 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1892 c = u->peer.connection; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1893 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1894 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1895 if (clcf->tcp_nodelay && c->tcp_nodelay == NGX_TCP_NODELAY_UNSET) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1896 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "tcp_nodelay"); |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1897 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1898 tcp_nodelay = 1; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1899 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1900 if (setsockopt(c->fd, IPPROTO_TCP, TCP_NODELAY, |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1901 (const void *) &tcp_nodelay, sizeof(int)) == -1) |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1902 { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1903 ngx_connection_error(c, ngx_socket_errno, |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1904 "setsockopt(TCP_NODELAY) failed"); |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1905 return NGX_ERROR; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1906 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1907 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1908 c->tcp_nodelay = NGX_TCP_NODELAY_SET; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1909 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1910 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1911 r->read_event_handler = ngx_http_upstream_read_request_handler; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1912 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1913 } else { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1914 out = NULL; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1915 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1916 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1917 for ( ;; ) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1918 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1919 if (do_write) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1920 rc = ngx_output_chain(&u->output, out); |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1921 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1922 if (rc == NGX_ERROR) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1923 return NGX_ERROR; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1924 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1925 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1926 while (out) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1927 ln = out; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1928 out = out->next; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1929 ngx_free_chain(r->pool, ln); |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1930 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1931 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1932 if (rc == NGX_OK && !r->reading_body) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1933 break; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1934 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1935 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1936 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1937 if (r->reading_body) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1938 /* read client request body */ |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1939 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1940 rc = ngx_http_read_unbuffered_request_body(r); |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1941 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1942 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1943 return rc; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1944 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1945 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1946 out = r->request_body->bufs; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1947 r->request_body->bufs = NULL; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1948 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1949 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1950 /* stop if there is nothing to send */ |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1951 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1952 if (out == NULL) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1953 rc = NGX_AGAIN; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1954 break; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1955 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1956 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1957 do_write = 1; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1958 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1959 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1960 if (!r->reading_body) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1961 if (!u->store && !r->post_action && !u->conf->ignore_client_abort) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1962 r->read_event_handler = |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1963 ngx_http_upstream_rd_check_broken_connection; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1964 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1965 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1966 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1967 return rc; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1968 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1969 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1970 |
487 | 1971 static void |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1972 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
|
1973 ngx_http_upstream_t *u) |
479 | 1974 { |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1975 ngx_connection_t *c; |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1976 |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1977 c = u->peer.connection; |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1978 |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1979 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
479 | 1980 "http upstream send request handler"); |
1981 | |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1982 if (c->write->timedout) { |
479 | 1983 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_TIMEOUT); |
1984 return; | |
1985 } | |
1986 | |
591 | 1987 #if (NGX_HTTP_SSL) |
1988 | |
1658 | 1989 if (u->ssl && c->ssl == NULL) { |
591 | 1990 ngx_http_upstream_ssl_init_connection(r, u, c); |
1991 return; | |
1992 } | |
1993 | |
1994 #endif | |
1995 | |
651 | 1996 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
|
1997 u->write_event_handler = ngx_http_upstream_dummy_handler; |
651 | 1998 |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1999 (void) ngx_handle_write_event(c->write, 0); |
651 | 2000 |
2001 return; | |
2002 } | |
2003 | |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2004 ngx_http_upstream_send_request(r, u, 1); |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2005 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2006 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2007 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2008 static void |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2009 ngx_http_upstream_read_request_handler(ngx_http_request_t *r) |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2010 { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2011 ngx_connection_t *c; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2012 ngx_http_upstream_t *u; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2013 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2014 c = r->connection; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2015 u = r->upstream; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2016 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2017 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2018 "http upstream read request handler"); |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2019 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2020 if (c->read->timedout) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2021 c->timedout = 1; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2022 ngx_http_upstream_finalize_request(r, u, NGX_HTTP_REQUEST_TIME_OUT); |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2023 return; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2024 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2025 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2026 ngx_http_upstream_send_request(r, u, 0); |
479 | 2027 } |
2028 | |
2029 | |
487 | 2030 static void |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2031 ngx_http_upstream_process_header(ngx_http_request_t *r, ngx_http_upstream_t *u) |
479 | 2032 { |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2033 ssize_t n; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2034 ngx_int_t rc; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2035 ngx_connection_t *c; |
479 | 2036 |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2037 c = u->peer.connection; |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2038 |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2039 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, |
483 | 2040 "http upstream process header"); |
479 | 2041 |
483 | 2042 c->log->action = "reading response header from upstream"; |
479 | 2043 |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2044 if (c->read->timedout) { |
479 | 2045 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_TIMEOUT); |
2046 return; | |
2047 } | |
577 | 2048 |
1153
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2049 if (!u->request_sent && ngx_http_upstream_test_connect(c) != NGX_OK) { |
1166 | 2050 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
|
2051 return; |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2052 } |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2053 |
581 | 2054 if (u->buffer.start == NULL) { |
2055 u->buffer.start = ngx_palloc(r->pool, u->conf->buffer_size); | |
2056 if (u->buffer.start == NULL) { | |
479 | 2057 ngx_http_upstream_finalize_request(r, u, |
2058 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
2059 return; | |
2060 } | |
2061 | |
581 | 2062 u->buffer.pos = u->buffer.start; |
2063 u->buffer.last = u->buffer.start; | |
2064 u->buffer.end = u->buffer.start + u->conf->buffer_size; | |
2065 u->buffer.temporary = 1; | |
2066 | |
2067 u->buffer.tag = u->output.tag; | |
479 | 2068 |
1705 | 2069 if (ngx_list_init(&u->headers_in.headers, r->pool, 8, |
581 | 2070 sizeof(ngx_table_elt_t)) |
2071 != NGX_OK) | |
509 | 2072 { |
2073 ngx_http_upstream_finalize_request(r, u, | |
2074 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
2075 return; | |
2076 } | |
2077 | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2078 #if (NGX_HTTP_CACHE) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2079 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2080 if (r->cache) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2081 u->buffer.pos += r->cache->header_start; |
581 | 2082 u->buffer.last = u->buffer.pos; |
479 | 2083 } |
2084 #endif | |
2085 } | |
2086 | |
2360
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2087 for ( ;; ) { |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2088 |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2089 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
|
2090 |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2091 if (n == NGX_AGAIN) { |
479 | 2092 #if 0 |
2360
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2093 ngx_add_timer(rev, u->read_timeout); |
479 | 2094 #endif |
2095 | |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2096 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
|
2097 ngx_http_upstream_finalize_request(r, u, |
479 | 2098 NGX_HTTP_INTERNAL_SERVER_ERROR); |
2360
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2099 return; |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2100 } |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2101 |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2102 return; |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2103 } |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2104 |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2105 if (n == 0) { |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2106 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
|
2107 "upstream prematurely closed connection"); |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2108 } |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2109 |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2110 if (n == NGX_ERROR || n == 0) { |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2111 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR); |
479 | 2112 return; |
2113 } | |
2114 | |
2360
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2115 u->buffer.last += n; |
479 | 2116 |
2117 #if 0 | |
2360
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2118 u->valid_header_in = 0; |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2119 |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2120 u->peer.cached = 0; |
479 | 2121 #endif |
2122 | |
2360
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2123 rc = u->process_header(r); |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2124 |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2125 if (rc == NGX_AGAIN) { |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2126 |
4460
6299d1c4dbb4
Upstream: fixed "too big header" check.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
2127 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
|
2128 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
|
2129 "upstream sent too big header"); |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2130 |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2131 ngx_http_upstream_next(r, u, |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2132 NGX_HTTP_UPSTREAM_FT_INVALID_HEADER); |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2133 return; |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2134 } |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2135 |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2136 continue; |
479 | 2137 } |
2138 | |
2360
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2139 break; |
479 | 2140 } |
2141 | |
2142 if (rc == NGX_HTTP_UPSTREAM_INVALID_HEADER) { | |
2143 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_INVALID_HEADER); | |
2144 return; | |
2145 } | |
2146 | |
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
|
2147 if (rc == NGX_ERROR) { |
479 | 2148 ngx_http_upstream_finalize_request(r, u, |
2149 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
2150 return; | |
2151 } | |
2152 | |
2153 /* rc == NGX_OK */ | |
2154 | |
6146
59fc60585f1e
Upstream: times to obtain header/response are stored as ngx_msec_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6125
diff
changeset
|
2155 u->state->header_time = ngx_current_msec - u->state->response_time; |
5964
0a198a517eaf
Upstream: $upstream_header_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
5960
diff
changeset
|
2156 |
5209
07e515e65984
Upstream: allow to intercept responses with status 300.
Ruslan Ermilov <ru@nginx.com>
parents:
5169
diff
changeset
|
2157 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
|
2158 |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2159 if (ngx_http_upstream_test_next(r, u) == NGX_OK) { |
509 | 2160 return; |
2161 } | |
2162 | |
2267
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2163 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
|
2164 return; |
487 | 2165 } |
2166 } | |
2167 | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2168 if (ngx_http_upstream_process_headers(r, u) != NGX_OK) { |
515 | 2169 return; |
2170 } | |
2171 | |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2172 if (!r->subrequest_in_memory) { |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2173 ngx_http_upstream_send_response(r, u); |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2174 return; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2175 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2176 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2177 /* subrequest content in memory */ |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2178 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2179 if (u->input_filter == NULL) { |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2180 u->input_filter_init = ngx_http_upstream_non_buffered_filter_init; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2181 u->input_filter = ngx_http_upstream_non_buffered_filter; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2182 u->input_filter_ctx = r; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2183 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2184 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2185 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
|
2186 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2187 return; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2188 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2189 |
2308
3f98400e31e9
memcached response was stored in variable with END
Igor Sysoev <igor@sysoev.ru>
parents:
2285
diff
changeset
|
2190 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
|
2191 |
3f98400e31e9
memcached response was stored in variable with END
Igor Sysoev <igor@sysoev.ru>
parents:
2285
diff
changeset
|
2192 if (n) { |
5216
4a40163772a1
Upstream: made the assignment more obvious.
Ruslan Ermilov <ru@nginx.com>
parents:
5209
diff
changeset
|
2193 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
|
2194 |
2402 | 2195 u->state->response_length += n; |
2196 | |
2308
3f98400e31e9
memcached response was stored in variable with END
Igor Sysoev <igor@sysoev.ru>
parents:
2285
diff
changeset
|
2197 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
|
2198 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2199 return; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2200 } |
5217
ddba4e308ecc
Upstream: slightly optimized ngx_http_upstream_process_header().
Ruslan Ermilov <ru@nginx.com>
parents:
5216
diff
changeset
|
2201 } |
ddba4e308ecc
Upstream: slightly optimized ngx_http_upstream_process_header().
Ruslan Ermilov <ru@nginx.com>
parents:
5216
diff
changeset
|
2202 |
ddba4e308ecc
Upstream: slightly optimized ngx_http_upstream_process_header().
Ruslan Ermilov <ru@nginx.com>
parents:
5216
diff
changeset
|
2203 if (u->length == 0) { |
ddba4e308ecc
Upstream: slightly optimized ngx_http_upstream_process_header().
Ruslan Ermilov <ru@nginx.com>
parents:
5216
diff
changeset
|
2204 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
|
2205 return; |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2206 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2207 |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
2208 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
|
2209 |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2210 ngx_http_upstream_process_body_in_memory(r, u); |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2211 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2212 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2213 |
1153
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2214 static ngx_int_t |
2268
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2215 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
|
2216 { |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2217 ngx_uint_t status; |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2218 ngx_http_upstream_next_t *un; |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2219 |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2220 status = u->headers_in.status_n; |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2221 |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2222 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
|
2223 |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2224 if (status != un->status) { |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2225 continue; |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2226 } |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2227 |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2228 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
|
2229 ngx_http_upstream_next(r, u, un->mask); |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2230 return NGX_OK; |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2231 } |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2232 |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2233 #if (NGX_HTTP_CACHE) |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2234 |
2952 | 2235 if (u->cache_status == NGX_HTTP_CACHE_EXPIRED |
2236 && (u->conf->cache_use_stale & un->mask)) | |
2237 { | |
2824
d106509491b5
fix building --without-http-cache
Igor Sysoev <igor@sysoev.ru>
parents:
2807
diff
changeset
|
2238 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
|
2239 |
60551422e150
reinit proxy/fastcgi header parser before ngx_http_upstream_cache_send()
Igor Sysoev <igor@sysoev.ru>
parents:
2804
diff
changeset
|
2240 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
|
2241 |
60551422e150
reinit proxy/fastcgi header parser before ngx_http_upstream_cache_send()
Igor Sysoev <igor@sysoev.ru>
parents:
2804
diff
changeset
|
2242 if (rc == NGX_OK) { |
2952 | 2243 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
|
2244 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
|
2245 } |
60551422e150
reinit proxy/fastcgi header parser before ngx_http_upstream_cache_send()
Igor Sysoev <igor@sysoev.ru>
parents:
2804
diff
changeset
|
2246 |
60551422e150
reinit proxy/fastcgi header parser before ngx_http_upstream_cache_send()
Igor Sysoev <igor@sysoev.ru>
parents:
2804
diff
changeset
|
2247 ngx_http_upstream_finalize_request(r, u, rc); |
2268
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2248 return NGX_OK; |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2249 } |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2250 |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2251 #endif |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2252 } |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2253 |
5441
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2254 #if (NGX_HTTP_CACHE) |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2255 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2256 if (status == NGX_HTTP_NOT_MODIFIED |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2257 && u->cache_status == NGX_HTTP_CACHE_EXPIRED |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2258 && u->conf->cache_revalidate) |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2259 { |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2260 time_t now, valid; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2261 ngx_int_t rc; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2262 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2263 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
|
2264 "http upstream not modified"); |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2265 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2266 now = ngx_time(); |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2267 valid = r->cache->valid_sec; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2268 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2269 rc = u->reinit_request(r); |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2270 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2271 if (rc != NGX_OK) { |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2272 ngx_http_upstream_finalize_request(r, u, rc); |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2273 return NGX_OK; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2274 } |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2275 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2276 u->cache_status = NGX_HTTP_CACHE_REVALIDATED; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2277 rc = ngx_http_upstream_cache_send(r, u); |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2278 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2279 if (valid == 0) { |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2280 valid = r->cache->valid_sec; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2281 } |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2282 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2283 if (valid == 0) { |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2284 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
|
2285 u->headers_in.status_n); |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2286 if (valid) { |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2287 valid = now + valid; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2288 } |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2289 } |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2290 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2291 if (valid) { |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2292 r->cache->valid_sec = valid; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2293 r->cache->date = now; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2294 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2295 ngx_http_file_cache_update_header(r); |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2296 } |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2297 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2298 ngx_http_upstream_finalize_request(r, u, rc); |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2299 return NGX_OK; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2300 } |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2301 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2302 #endif |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2303 |
2268
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2304 return NGX_DECLINED; |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2305 } |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2306 |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2307 |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2308 static ngx_int_t |
2267
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2309 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
|
2310 ngx_http_upstream_t *u) |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2311 { |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2312 ngx_int_t status; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2313 ngx_uint_t i; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2314 ngx_table_elt_t *h; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2315 ngx_http_err_page_t *err_page; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2316 ngx_http_core_loc_conf_t *clcf; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2317 |
2441
0c117a89f399
in miss case memcached module returned END instead of default 404 page body
Igor Sysoev <igor@sysoev.ru>
parents:
2422
diff
changeset
|
2318 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
|
2319 |
0c117a89f399
in miss case memcached module returned END instead of default 404 page body
Igor Sysoev <igor@sysoev.ru>
parents:
2422
diff
changeset
|
2320 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
|
2321 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
|
2322 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
|
2323 } |
0c117a89f399
in miss case memcached module returned END instead of default 404 page body
Igor Sysoev <igor@sysoev.ru>
parents:
2422
diff
changeset
|
2324 |
2267
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2325 if (!u->conf->intercept_errors) { |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2326 return NGX_DECLINED; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2327 } |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2328 |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2329 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
|
2330 |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2331 if (clcf->error_pages == NULL) { |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2332 return NGX_DECLINED; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2333 } |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2334 |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2335 err_page = clcf->error_pages->elts; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2336 for (i = 0; i < clcf->error_pages->nelts; i++) { |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2337 |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2338 if (err_page[i].status == status) { |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2339 |
2953
aa12525236da
fix segfault if there is error_page 401, proxy_intercept_errors is on
Igor Sysoev <igor@sysoev.ru>
parents:
2952
diff
changeset
|
2340 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
|
2341 && 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
|
2342 { |
2267
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2343 h = ngx_list_push(&r->headers_out.headers); |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2344 |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2345 if (h == NULL) { |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2346 ngx_http_upstream_finalize_request(r, u, |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2347 NGX_HTTP_INTERNAL_SERVER_ERROR); |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2348 return NGX_OK; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2349 } |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2350 |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2351 *h = *u->headers_in.www_authenticate; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2352 |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2353 r->headers_out.www_authenticate = h; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2354 } |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2355 |
3706
ea908f6ae499
an intercepted error code was not cached
Igor Sysoev <igor@sysoev.ru>
parents:
3705
diff
changeset
|
2356 #if (NGX_HTTP_CACHE) |
ea908f6ae499
an intercepted error code was not cached
Igor Sysoev <igor@sysoev.ru>
parents:
3705
diff
changeset
|
2357 |
3709
64777690c697
fix r3707: cache node should be freed be a response is not cached
Igor Sysoev <igor@sysoev.ru>
parents:
3708
diff
changeset
|
2358 if (r->cache) { |
3706
ea908f6ae499
an intercepted error code was not cached
Igor Sysoev <igor@sysoev.ru>
parents:
3705
diff
changeset
|
2359 time_t valid; |
ea908f6ae499
an intercepted error code was not cached
Igor Sysoev <igor@sysoev.ru>
parents:
3705
diff
changeset
|
2360 |
ea908f6ae499
an intercepted error code was not cached
Igor Sysoev <igor@sysoev.ru>
parents:
3705
diff
changeset
|
2361 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
|
2362 |
ea908f6ae499
an intercepted error code was not cached
Igor Sysoev <igor@sysoev.ru>
parents:
3705
diff
changeset
|
2363 if (valid) { |
ea908f6ae499
an intercepted error code was not cached
Igor Sysoev <igor@sysoev.ru>
parents:
3705
diff
changeset
|
2364 r->cache->valid_sec = ngx_time() + valid; |
ea908f6ae499
an intercepted error code was not cached
Igor Sysoev <igor@sysoev.ru>
parents:
3705
diff
changeset
|
2365 r->cache->error = status; |
ea908f6ae499
an intercepted error code was not cached
Igor Sysoev <igor@sysoev.ru>
parents:
3705
diff
changeset
|
2366 } |
ea908f6ae499
an intercepted error code was not cached
Igor Sysoev <igor@sysoev.ru>
parents:
3705
diff
changeset
|
2367 |
3711
ce6ba077c270
several changes in cache cleanup handling:
Igor Sysoev <igor@sysoev.ru>
parents:
3709
diff
changeset
|
2368 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
|
2369 } |
ea908f6ae499
an intercepted error code was not cached
Igor Sysoev <igor@sysoev.ru>
parents:
3705
diff
changeset
|
2370 #endif |
2267
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2371 ngx_http_upstream_finalize_request(r, u, status); |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2372 |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2373 return NGX_OK; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2374 } |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2375 } |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2376 |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2377 return NGX_DECLINED; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2378 } |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2379 |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2380 |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2381 static ngx_int_t |
1153
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2382 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
|
2383 { |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2384 int err; |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2385 socklen_t len; |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2386 |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2387 #if (NGX_HAVE_KQUEUE) |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2388 |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2389 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
|
2390 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
|
2391 if (c->write->pending_eof) { |
e62219793beb
Upstream: better detection of connect() failures with kqueue.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4895
diff
changeset
|
2392 err = c->write->kq_errno; |
e62219793beb
Upstream: better detection of connect() failures with kqueue.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4895
diff
changeset
|
2393 |
e62219793beb
Upstream: better detection of connect() failures with kqueue.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4895
diff
changeset
|
2394 } else { |
e62219793beb
Upstream: better detection of connect() failures with kqueue.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4895
diff
changeset
|
2395 err = c->read->kq_errno; |
e62219793beb
Upstream: better detection of connect() failures with kqueue.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4895
diff
changeset
|
2396 } |
e62219793beb
Upstream: better detection of connect() failures with kqueue.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4895
diff
changeset
|
2397 |
1469
0a269c464eaf
connection error should be logged with "connecting to upstream" action,
Igor Sysoev <igor@sysoev.ru>
parents:
1468
diff
changeset
|
2398 c->log->action = "connecting to upstream"; |
4916
79c8e87b1fcb
Trailing whitespace fix.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4915
diff
changeset
|
2399 (void) ngx_connection_error(c, err, |
1166 | 2400 "kevent() reported that connect() failed"); |
2401 return NGX_ERROR; | |
2402 } | |
1153
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2403 |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2404 } else |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2405 #endif |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2406 { |
1166 | 2407 err = 0; |
2408 len = sizeof(int); | |
2409 | |
2410 /* | |
2411 * BSDs and Linux return 0 and set a pending error in err | |
2412 * Solaris returns -1 and sets errno | |
2413 */ | |
2414 | |
2415 if (getsockopt(c->fd, SOL_SOCKET, SO_ERROR, (void *) &err, &len) | |
2416 == -1) | |
2417 { | |
5557
188481078faf
Use ngx_socket_errno where appropriate.
Piotr Sikora <piotr@cloudflare.com>
parents:
5546
diff
changeset
|
2418 err = ngx_socket_errno; |
1166 | 2419 } |
2420 | |
2421 if (err) { | |
1469
0a269c464eaf
connection error should be logged with "connecting to upstream" action,
Igor Sysoev <igor@sysoev.ru>
parents:
1468
diff
changeset
|
2422 c->log->action = "connecting to upstream"; |
1166 | 2423 (void) ngx_connection_error(c, err, "connect() failed"); |
2424 return NGX_ERROR; | |
2425 } | |
1153
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2426 } |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2427 |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2428 return NGX_OK; |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2429 } |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2430 |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2431 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2432 static ngx_int_t |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2433 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
|
2434 { |
5489
6d357b2a9d6e
Upstream: keep $upstream_http_x_accel_redirect intact.
Ruslan Ermilov <ru@nginx.com>
parents:
5477
diff
changeset
|
2435 ngx_str_t uri, args; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2436 ngx_uint_t i, flags; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2437 ngx_list_part_t *part; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2438 ngx_table_elt_t *h; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2439 ngx_http_upstream_header_t *hh; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2440 ngx_http_upstream_main_conf_t *umcf; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2441 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2442 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
|
2443 |
2786
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
2444 if (u->headers_in.x_accel_redirect |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
2445 && !(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
|
2446 { |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2447 ngx_http_upstream_finalize_request(r, u, NGX_DECLINED); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2448 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2449 part = &u->headers_in.headers.part; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2450 h = part->elts; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2451 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2452 for (i = 0; /* void */; i++) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2453 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2454 if (i >= part->nelts) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2455 if (part->next == NULL) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2456 break; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2457 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2458 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2459 part = part->next; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2460 h = part->elts; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2461 i = 0; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2462 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2463 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2464 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
|
2465 h[i].lowcase_key, h[i].key.len); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2466 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2467 if (hh && hh->redirect) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2468 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
|
2469 ngx_http_finalize_request(r, |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2470 NGX_HTTP_INTERNAL_SERVER_ERROR); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2471 return NGX_DONE; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2472 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2473 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2474 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2475 |
5489
6d357b2a9d6e
Upstream: keep $upstream_http_x_accel_redirect intact.
Ruslan Ermilov <ru@nginx.com>
parents:
5477
diff
changeset
|
2476 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
|
2477 |
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2478 if (uri.data[0] == '@') { |
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2479 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
|
2480 |
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2481 } else { |
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2482 ngx_str_null(&args); |
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2483 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
|
2484 |
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2485 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
|
2486 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
|
2487 return NGX_DONE; |
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2488 } |
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2489 |
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2490 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
|
2491 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
|
2492 } |
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2493 |
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2494 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
|
2495 } |
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2496 |
3120
40b8b398dbbc
fix request counter for X-Accel-Redirect, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3112
diff
changeset
|
2497 ngx_http_finalize_request(r, NGX_DONE); |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2498 return NGX_DONE; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2499 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2500 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2501 part = &u->headers_in.headers.part; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2502 h = part->elts; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2503 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2504 for (i = 0; /* void */; i++) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2505 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2506 if (i >= part->nelts) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2507 if (part->next == NULL) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2508 break; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2509 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2510 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2511 part = part->next; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2512 h = part->elts; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2513 i = 0; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2514 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2515 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2516 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
|
2517 h[i].lowcase_key, h[i].key.len)) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2518 { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2519 continue; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2520 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2521 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2522 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
|
2523 h[i].lowcase_key, h[i].key.len); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2524 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2525 if (hh) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2526 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
|
2527 ngx_http_upstream_finalize_request(r, u, |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2528 NGX_HTTP_INTERNAL_SERVER_ERROR); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2529 return NGX_DONE; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2530 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2531 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2532 continue; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2533 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2534 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2535 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
|
2536 ngx_http_upstream_finalize_request(r, u, |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2537 NGX_HTTP_INTERNAL_SERVER_ERROR); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2538 return NGX_DONE; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2539 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2540 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2541 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2542 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
|
2543 r->headers_out.server->hash = 0; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2544 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2545 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2546 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
|
2547 r->headers_out.date->hash = 0; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2548 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2549 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2550 r->headers_out.status = u->headers_in.status_n; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2551 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
|
2552 |
4117
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
2553 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
|
2554 |
5735
5fb1e57c758a
Entity tags: explicit flag to skip not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5732
diff
changeset
|
2555 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
|
2556 |
5874
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
2557 if (u->conf->force_ranges) { |
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
2558 r->allow_ranges = 1; |
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
2559 r->single_range = 1; |
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
2560 |
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
2561 #if (NGX_HTTP_CACHE) |
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
2562 if (r->cached) { |
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
2563 r->single_range = 0; |
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
2564 } |
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
2565 #endif |
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
2566 } |
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
2567 |
5300
f538a67c9f77
Upstream: u->length now defaults to -1 (API change).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5299
diff
changeset
|
2568 u->length = -1; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2569 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2570 return NGX_OK; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2571 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2572 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2573 |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2574 static void |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2575 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
|
2576 ngx_http_upstream_t *u) |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2577 { |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2578 size_t size; |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2579 ssize_t n; |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2580 ngx_buf_t *b; |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2581 ngx_event_t *rev; |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2582 ngx_connection_t *c; |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2583 |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2584 c = u->peer.connection; |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2585 rev = c->read; |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2586 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2587 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2588 "http upstream process body on memory"); |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2589 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2590 if (rev->timedout) { |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2591 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
|
2592 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
|
2593 return; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2594 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2595 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2596 b = &u->buffer; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2597 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2598 for ( ;; ) { |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2599 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2600 size = b->end - b->last; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2601 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2602 if (size == 0) { |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2603 ngx_log_error(NGX_LOG_ALERT, c->log, 0, |
3708 | 2604 "upstream buffer is too small to read response"); |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2605 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2606 return; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2607 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2608 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2609 n = c->recv(c, b->last, size); |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2610 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2611 if (n == NGX_AGAIN) { |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2612 break; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2613 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2614 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2615 if (n == 0 || n == NGX_ERROR) { |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2616 ngx_http_upstream_finalize_request(r, u, n); |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2617 return; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2618 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2619 |
2402 | 2620 u->state->response_length += n; |
2621 | |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2622 if (u->input_filter(u->input_filter_ctx, n) == NGX_ERROR) { |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2623 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2624 return; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2625 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2626 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2627 if (!rev->ready) { |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2628 break; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2629 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2630 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2631 |
4120
42135dd1f0ea
Upstream: keepalive flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4119
diff
changeset
|
2632 if (u->length == 0) { |
42135dd1f0ea
Upstream: keepalive flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4119
diff
changeset
|
2633 ngx_http_upstream_finalize_request(r, u, 0); |
42135dd1f0ea
Upstream: keepalive flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4119
diff
changeset
|
2634 return; |
42135dd1f0ea
Upstream: keepalive flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4119
diff
changeset
|
2635 } |
42135dd1f0ea
Upstream: keepalive flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4119
diff
changeset
|
2636 |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2637 if (ngx_handle_read_event(rev, 0) != NGX_OK) { |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2638 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2639 return; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2640 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2641 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2642 if (rev->active) { |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2643 ngx_add_timer(rev, u->conf->read_timeout); |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2644 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2645 } else if (rev->timer_set) { |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2646 ngx_del_timer(rev); |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2647 } |
681 | 2648 } |
2649 | |
2650 | |
2651 static void | |
2652 ngx_http_upstream_send_response(ngx_http_request_t *r, ngx_http_upstream_t *u) | |
2653 { | |
2654 int tcp_nodelay; | |
2402 | 2655 ssize_t n; |
681 | 2656 ngx_int_t rc; |
2657 ngx_event_pipe_t *p; | |
2658 ngx_connection_t *c; | |
2659 ngx_http_core_loc_conf_t *clcf; | |
2660 | |
509 | 2661 rc = ngx_http_send_header(r); |
479 | 2662 |
2701 | 2663 if (rc == NGX_ERROR || rc > NGX_OK || r->post_action) { |
485 | 2664 ngx_http_upstream_finalize_request(r, u, rc); |
479 | 2665 return; |
2666 } | |
2667 | |
5353
1608b1135a1d
Upstream: setting u->header_sent before ngx_http_upstream_upgrade().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5340
diff
changeset
|
2668 u->header_sent = 1; |
1608b1135a1d
Upstream: setting u->header_sent before ngx_http_upstream_upgrade().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5340
diff
changeset
|
2669 |
5072
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2670 if (u->upgrade) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2671 ngx_http_upstream_upgrade(r, u); |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2672 return; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2673 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2674 |
2704
ac1e2e199c9f
shutdown client connection for cacheable header only responses
Igor Sysoev <igor@sysoev.ru>
parents:
2703
diff
changeset
|
2675 c = r->connection; |
ac1e2e199c9f
shutdown client connection for cacheable header only responses
Igor Sysoev <igor@sysoev.ru>
parents:
2703
diff
changeset
|
2676 |
2701 | 2677 if (r->header_only) { |
2704
ac1e2e199c9f
shutdown client connection for cacheable header only responses
Igor Sysoev <igor@sysoev.ru>
parents:
2703
diff
changeset
|
2678 |
5746
35990c69b3ac
Upstream: p->downstream_error instead of closing connection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5745
diff
changeset
|
2679 if (!u->buffering) { |
2701 | 2680 ngx_http_upstream_finalize_request(r, u, rc); |
2681 return; | |
2682 } | |
5746
35990c69b3ac
Upstream: p->downstream_error instead of closing connection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5745
diff
changeset
|
2683 |
35990c69b3ac
Upstream: p->downstream_error instead of closing connection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5745
diff
changeset
|
2684 if (!u->cacheable && !u->store) { |
35990c69b3ac
Upstream: p->downstream_error instead of closing connection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5745
diff
changeset
|
2685 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
|
2686 return; |
35990c69b3ac
Upstream: p->downstream_error instead of closing connection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5745
diff
changeset
|
2687 } |
35990c69b3ac
Upstream: p->downstream_error instead of closing connection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5745
diff
changeset
|
2688 |
35990c69b3ac
Upstream: p->downstream_error instead of closing connection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5745
diff
changeset
|
2689 u->pipe->downstream_error = 1; |
2701 | 2690 } |
2691 | |
573 | 2692 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
|
2693 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
|
2694 r->request_body->temp_file->file.fd = NGX_INVALID_FILE; |
563 | 2695 } |
2696 | |
581 | 2697 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
2698 | |
649 | 2699 if (!u->buffering) { |
581 | 2700 |
2701 if (u->input_filter == NULL) { | |
2702 u->input_filter_init = ngx_http_upstream_non_buffered_filter_init; | |
2703 u->input_filter = ngx_http_upstream_non_buffered_filter; | |
2704 u->input_filter_ctx = r; | |
2705 } | |
2706 | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2707 u->read_event_handler = ngx_http_upstream_process_non_buffered_upstream; |
581 | 2708 r->write_event_handler = |
2709 ngx_http_upstream_process_non_buffered_downstream; | |
2710 | |
2711 r->limit_rate = 0; | |
2712 | |
2713 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
|
2714 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
581 | 2715 return; |
2716 } | |
2717 | |
583 | 2718 if (clcf->tcp_nodelay && c->tcp_nodelay == NGX_TCP_NODELAY_UNSET) { |
2719 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "tcp_nodelay"); | |
2720 | |
2721 tcp_nodelay = 1; | |
2722 | |
2723 if (setsockopt(c->fd, IPPROTO_TCP, TCP_NODELAY, | |
2724 (const void *) &tcp_nodelay, sizeof(int)) == -1) | |
2725 { | |
2726 ngx_connection_error(c, ngx_socket_errno, | |
2727 "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
|
2728 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
583 | 2729 return; |
2730 } | |
2731 | |
2732 c->tcp_nodelay = NGX_TCP_NODELAY_SET; | |
2733 } | |
2734 | |
2402 | 2735 n = u->buffer.last - u->buffer.pos; |
2736 | |
2737 if (n) { | |
581 | 2738 u->buffer.last = u->buffer.pos; |
2739 | |
2402 | 2740 u->state->response_length += n; |
2741 | |
2742 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
|
2743 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
581 | 2744 return; |
2745 } | |
2746 | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2747 ngx_http_upstream_process_non_buffered_downstream(r); |
581 | 2748 |
2749 } else { | |
2750 u->buffer.pos = u->buffer.start; | |
2751 u->buffer.last = u->buffer.start; | |
2752 | |
2753 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
|
2754 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
581 | 2755 return; |
2756 } | |
1468
491e5059ea19
read EOF of header only responses in non-buffered proxying
Igor Sysoev <igor@sysoev.ru>
parents:
1397
diff
changeset
|
2757 |
4120
42135dd1f0ea
Upstream: keepalive flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4119
diff
changeset
|
2758 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
|
2759 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
|
2760 } |
581 | 2761 } |
2762 | |
2763 return; | |
2764 } | |
2765 | |
479 | 2766 /* TODO: preallocate event_pipe bufs, look "Content-Length" */ |
2767 | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2768 #if (NGX_HTTP_CACHE) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2769 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2770 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
|
2771 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
|
2772 r->cache->file.fd = NGX_INVALID_FILE; |
479 | 2773 } |
2774 | |
3699
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2775 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
|
2776 |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2777 case NGX_ERROR: |
5295
a489c31c9783
Upstream: ngx_http_upstream_finalize_request(NGX_ERROR) on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5294
diff
changeset
|
2778 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
|
2779 return; |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2780 |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2781 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
|
2782 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
|
2783 break; |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2784 |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2785 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
|
2786 |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2787 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
|
2788 |
5950
eaeecf00d5d7
Upstream: preset some cache configuration when bypassing.
Valentin Bartenev <vbart@nginx.com>
parents:
5949
diff
changeset
|
2789 /* create cache if previously bypassed */ |
3699
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2790 |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2791 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
|
2792 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
|
2793 return; |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2794 } |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2795 } |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2796 |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2797 break; |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2798 } |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2799 |
1565 | 2800 if (u->cacheable) { |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2801 time_t now, valid; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2802 |
2663
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
2803 now = ngx_time(); |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
2804 |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
2805 valid = r->cache->valid_sec; |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
2806 |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
2807 if (valid == 0) { |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
2808 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
|
2809 u->headers_in.status_n); |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
2810 if (valid) { |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
2811 r->cache->valid_sec = now + valid; |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
2812 } |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
2813 } |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
2814 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2815 if (valid) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2816 r->cache->date = now; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2817 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
|
2818 |
5935
1573fc7875fa
Cache: send conditional requests only for cached 200/206 responses.
Piotr Sikora <piotr@cloudflare.com>
parents:
5928
diff
changeset
|
2819 if (u->headers_in.status_n == NGX_HTTP_OK |
1573fc7875fa
Cache: send conditional requests only for cached 200/206 responses.
Piotr Sikora <piotr@cloudflare.com>
parents:
5928
diff
changeset
|
2820 || u->headers_in.status_n == NGX_HTTP_PARTIAL_CONTENT) |
1573fc7875fa
Cache: send conditional requests only for cached 200/206 responses.
Piotr Sikora <piotr@cloudflare.com>
parents:
5928
diff
changeset
|
2821 { |
1573fc7875fa
Cache: send conditional requests only for cached 200/206 responses.
Piotr Sikora <piotr@cloudflare.com>
parents:
5928
diff
changeset
|
2822 r->cache->last_modified = u->headers_in.last_modified_time; |
1573fc7875fa
Cache: send conditional requests only for cached 200/206 responses.
Piotr Sikora <piotr@cloudflare.com>
parents:
5928
diff
changeset
|
2823 |
1573fc7875fa
Cache: send conditional requests only for cached 200/206 responses.
Piotr Sikora <piotr@cloudflare.com>
parents:
5928
diff
changeset
|
2824 if (u->headers_in.etag) { |
1573fc7875fa
Cache: send conditional requests only for cached 200/206 responses.
Piotr Sikora <piotr@cloudflare.com>
parents:
5928
diff
changeset
|
2825 r->cache->etag = u->headers_in.etag->value; |
5992
174512857ccf
Cache: do not inherit last_modified and etag from stale response.
Roman Arutyunyan <arut@nginx.com>
parents:
5977
diff
changeset
|
2826 |
174512857ccf
Cache: do not inherit last_modified and etag from stale response.
Roman Arutyunyan <arut@nginx.com>
parents:
5977
diff
changeset
|
2827 } else { |
174512857ccf
Cache: do not inherit last_modified and etag from stale response.
Roman Arutyunyan <arut@nginx.com>
parents:
5977
diff
changeset
|
2828 ngx_str_null(&r->cache->etag); |
5935
1573fc7875fa
Cache: send conditional requests only for cached 200/206 responses.
Piotr Sikora <piotr@cloudflare.com>
parents:
5928
diff
changeset
|
2829 } |
5992
174512857ccf
Cache: do not inherit last_modified and etag from stale response.
Roman Arutyunyan <arut@nginx.com>
parents:
5977
diff
changeset
|
2830 |
174512857ccf
Cache: do not inherit last_modified and etag from stale response.
Roman Arutyunyan <arut@nginx.com>
parents:
5977
diff
changeset
|
2831 } else { |
174512857ccf
Cache: do not inherit last_modified and etag from stale response.
Roman Arutyunyan <arut@nginx.com>
parents:
5977
diff
changeset
|
2832 r->cache->last_modified = -1; |
174512857ccf
Cache: do not inherit last_modified and etag from stale response.
Roman Arutyunyan <arut@nginx.com>
parents:
5977
diff
changeset
|
2833 ngx_str_null(&r->cache->etag); |
5737
44b9ab7752e3
Cache: ETag now saved into cache header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5735
diff
changeset
|
2834 } |
44b9ab7752e3
Cache: ETag now saved into cache header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5735
diff
changeset
|
2835 |
5959
f7584d7c0ccb
Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents:
5951
diff
changeset
|
2836 if (ngx_http_file_cache_set_header(r, u->buffer.start) != NGX_OK) { |
f7584d7c0ccb
Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents:
5951
diff
changeset
|
2837 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
f7584d7c0ccb
Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents:
5951
diff
changeset
|
2838 return; |
f7584d7c0ccb
Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents:
5951
diff
changeset
|
2839 } |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2840 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2841 } else { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2842 u->cacheable = 0; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2843 } |
479 | 2844 } |
2845 | |
2690 | 2846 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, |
2847 "http cacheable: %d", u->cacheable); | |
2848 | |
3083
ffe8bfb38184
clean cache updating state if a response has uncacheable code or
Igor Sysoev <igor@sysoev.ru>
parents:
3056
diff
changeset
|
2849 if (u->cacheable == 0 && r->cache) { |
3711
ce6ba077c270
several changes in cache cleanup handling:
Igor Sysoev <igor@sysoev.ru>
parents:
3709
diff
changeset
|
2850 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
|
2851 } |
ffe8bfb38184
clean cache updating state if a response has uncacheable code or
Igor Sysoev <igor@sysoev.ru>
parents:
3056
diff
changeset
|
2852 |
479 | 2853 #endif |
2854 | |
581 | 2855 p = u->pipe; |
479 | 2856 |
2857 p->output_filter = (ngx_event_pipe_output_filter_pt) ngx_http_output_filter; | |
2858 p->output_ctx = r; | |
2859 p->tag = u->output.tag; | |
577 | 2860 p->bufs = u->conf->bufs; |
479 | 2861 p->busy_size = u->conf->busy_buffers_size; |
2862 p->upstream = u->peer.connection; | |
583 | 2863 p->downstream = c; |
479 | 2864 p->pool = r->pool; |
583 | 2865 p->log = c->log; |
5883
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
2866 p->limit_rate = u->conf->limit_rate; |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
2867 p->start_sec = ngx_time(); |
577 | 2868 |
1565 | 2869 p->cacheable = u->cacheable || u->store; |
479 | 2870 |
501 | 2871 p->temp_file = ngx_pcalloc(r->pool, sizeof(ngx_temp_file_t)); |
2872 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
|
2873 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
479 | 2874 return; |
2875 } | |
2876 | |
2877 p->temp_file->file.fd = NGX_INVALID_FILE; | |
583 | 2878 p->temp_file->file.log = c->log; |
479 | 2879 p->temp_file->path = u->conf->temp_path; |
2880 p->temp_file->pool = r->pool; | |
577 | 2881 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2882 if (p->cacheable) { |
479 | 2883 p->temp_file->persistent = 1; |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
2884 |
5960
e9effef98874
Upstream: use_temp_path parameter of proxy_cache_path and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5959
diff
changeset
|
2885 #if (NGX_HTTP_CACHE) |
5968
99639bfdfa2a
Cache: added temp_path to file cache.
Roman Arutyunyan <arut@nginx.com>
parents:
5964
diff
changeset
|
2886 if (r->cache && r->cache->file_cache->temp_path) { |
99639bfdfa2a
Cache: added temp_path to file cache.
Roman Arutyunyan <arut@nginx.com>
parents:
5964
diff
changeset
|
2887 p->temp_file->path = r->cache->file_cache->temp_path; |
5960
e9effef98874
Upstream: use_temp_path parameter of proxy_cache_path and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5959
diff
changeset
|
2888 } |
e9effef98874
Upstream: use_temp_path parameter of proxy_cache_path and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5959
diff
changeset
|
2889 #endif |
e9effef98874
Upstream: use_temp_path parameter of proxy_cache_path and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5959
diff
changeset
|
2890 |
479 | 2891 } else { |
667 | 2892 p->temp_file->log_level = NGX_LOG_WARN; |
479 | 2893 p->temp_file->warn = "an upstream response is buffered " |
2894 "to a temporary file"; | |
2895 } | |
2896 | |
2897 p->max_temp_file_size = u->conf->max_temp_file_size; | |
2898 p->temp_file_write_size = u->conf->temp_file_write_size; | |
2899 | |
501 | 2900 p->preread_bufs = ngx_alloc_chain_link(r->pool); |
2901 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
|
2902 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
479 | 2903 return; |
2904 } | |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
2905 |
581 | 2906 p->preread_bufs->buf = &u->buffer; |
479 | 2907 p->preread_bufs->next = NULL; |
581 | 2908 u->buffer.recycled = 1; |
2909 | |
2910 p->preread_size = u->buffer.last - u->buffer.pos; | |
479 | 2911 |
1565 | 2912 if (u->cacheable) { |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
2913 |
479 | 2914 p->buf_to_file = ngx_calloc_buf(r->pool); |
2915 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
|
2916 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
479 | 2917 return; |
2918 } | |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
2919 |
4895
508e61393b6c
Event pipe: fixed handling of buf_to_file data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4769
diff
changeset
|
2920 p->buf_to_file->start = u->buffer.start; |
581 | 2921 p->buf_to_file->pos = u->buffer.start; |
2922 p->buf_to_file->last = u->buffer.pos; | |
479 | 2923 p->buf_to_file->temporary = 1; |
2924 } | |
2925 | |
6125
4dc8e7b62216
Removed the obsolete aio module.
Ruslan Ermilov <ru@nginx.com>
parents:
6068
diff
changeset
|
2926 if (ngx_event_flags & NGX_USE_IOCP_EVENT) { |
4499
778ef9c3fd2d
Fixed spelling in single-line comments.
Ruslan Ermilov <ru@nginx.com>
parents:
4474
diff
changeset
|
2927 /* the posted aio operation may corrupt a shadow buffer */ |
479 | 2928 p->single_buf = 1; |
2929 } | |
2930 | |
2931 /* TODO: p->free_bufs = 0 if use ngx_create_chain_of_bufs() */ | |
2932 p->free_bufs = 1; | |
2933 | |
2934 /* | |
581 | 2935 * event_pipe would do u->buffer.last += p->preread_size |
479 | 2936 * as though these bytes were read |
2937 */ | |
581 | 2938 u->buffer.last = u->buffer.pos; |
479 | 2939 |
2940 if (u->conf->cyclic_temp_file) { | |
2941 | |
2942 /* | |
2943 * we need to disable the use of sendfile() if we use cyclic temp file | |
2944 * because the writing a new data may interfere with sendfile() | |
2945 * that uses the same kernel file pages (at least on FreeBSD) | |
2946 */ | |
2947 | |
2948 p->cyclic_temp_file = 1; | |
583 | 2949 c->sendfile = 0; |
479 | 2950 |
2951 } else { | |
2952 p->cyclic_temp_file = 0; | |
2953 } | |
2954 | |
2955 p->read_timeout = u->conf->read_timeout; | |
2956 p->send_timeout = clcf->send_timeout; | |
2957 p->send_lowat = clcf->send_lowat; | |
2958 | |
4119
b66712cde67d
Upstream: pipe length and input_filter_init in buffered mode.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4118
diff
changeset
|
2959 p->length = -1; |
b66712cde67d
Upstream: pipe length and input_filter_init in buffered mode.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4118
diff
changeset
|
2960 |
b66712cde67d
Upstream: pipe length and input_filter_init in buffered mode.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4118
diff
changeset
|
2961 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
|
2962 && 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
|
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); |
4119
b66712cde67d
Upstream: pipe length and input_filter_init in buffered mode.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4118
diff
changeset
|
2965 return; |
b66712cde67d
Upstream: pipe length and input_filter_init in buffered mode.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4118
diff
changeset
|
2966 } |
b66712cde67d
Upstream: pipe length and input_filter_init in buffered mode.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4118
diff
changeset
|
2967 |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2968 u->read_event_handler = ngx_http_upstream_process_upstream; |
509 | 2969 r->write_event_handler = ngx_http_upstream_process_downstream; |
479 | 2970 |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2971 ngx_http_upstream_process_upstream(r, u); |
479 | 2972 } |
2973 | |
2974 | |
487 | 2975 static void |
5072
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2976 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
|
2977 { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2978 int tcp_nodelay; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2979 ngx_connection_t *c; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2980 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
|
2981 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2982 c = r->connection; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2983 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
|
2984 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2985 /* 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
|
2986 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2987 r->keepalive = 0; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2988 c->log->action = "proxying upgraded connection"; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2989 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2990 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
|
2991 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
|
2992 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
|
2993 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
|
2994 |
5142
afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5132
diff
changeset
|
2995 if (clcf->tcp_nodelay) { |
5072
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2996 tcp_nodelay = 1; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2997 |
5142
afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5132
diff
changeset
|
2998 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
|
2999 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
|
3000 |
afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5132
diff
changeset
|
3001 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
|
3002 (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
|
3003 { |
afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5132
diff
changeset
|
3004 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
|
3005 "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
|
3006 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
|
3007 return; |
afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5132
diff
changeset
|
3008 } |
afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5132
diff
changeset
|
3009 |
afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5132
diff
changeset
|
3010 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
|
3011 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3012 |
5142
afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5132
diff
changeset
|
3013 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
|
3014 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
|
3015 "tcp_nodelay"); |
afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5132
diff
changeset
|
3016 |
afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5132
diff
changeset
|
3017 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
|
3018 (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
|
3019 { |
afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5132
diff
changeset
|
3020 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
|
3021 "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
|
3022 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
|
3023 return; |
afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5132
diff
changeset
|
3024 } |
afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5132
diff
changeset
|
3025 |
afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5132
diff
changeset
|
3026 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
|
3027 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3028 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3029 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3030 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
|
3031 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
|
3032 return; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3033 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3034 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3035 if (u->peer.connection->read->ready |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3036 || u->buffer.pos != u->buffer.last) |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3037 { |
5579
7586e7b2dbe9
Upstream: ngx_post_event() instead of upgraded call (ticket #503).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5557
diff
changeset
|
3038 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
|
3039 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
|
3040 return; |
5072
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3041 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3042 |
5532
17134d29782e
Upstream: reading from a client after connection upgrade.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5500
diff
changeset
|
3043 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
|
3044 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3045 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3046 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3047 static void |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3048 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
|
3049 { |
5073
52eb762c68a9
Proxy: fixed do_write handling in previous commit.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5072
diff
changeset
|
3050 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
|
3051 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3052 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3053 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3054 static void |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3055 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
|
3056 { |
5073
52eb762c68a9
Proxy: fixed do_write handling in previous commit.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5072
diff
changeset
|
3057 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
|
3058 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3059 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3060 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3061 static void |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3062 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
|
3063 ngx_http_upstream_t *u) |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3064 { |
5073
52eb762c68a9
Proxy: fixed do_write handling in previous commit.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5072
diff
changeset
|
3065 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
|
3066 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3067 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3068 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3069 static void |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3070 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
|
3071 ngx_http_upstream_t *u) |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3072 { |
5073
52eb762c68a9
Proxy: fixed do_write handling in previous commit.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5072
diff
changeset
|
3073 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
|
3074 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3075 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3076 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3077 static void |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3078 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
|
3079 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
|
3080 { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3081 size_t size; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3082 ssize_t n; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3083 ngx_buf_t *b; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3084 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
|
3085 ngx_http_upstream_t *u; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3086 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
|
3087 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3088 c = r->connection; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3089 u = r->upstream; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3090 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3091 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
|
3092 "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
|
3093 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3094 downstream = c; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3095 upstream = u->peer.connection; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3096 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3097 if (downstream->write->timedout) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3098 c->timedout = 1; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3099 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
|
3100 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
|
3101 return; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3102 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3103 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3104 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
|
3105 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
|
3106 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
|
3107 return; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3108 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3109 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3110 if (from_upstream) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3111 src = upstream; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3112 dst = downstream; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3113 b = &u->buffer; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3114 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3115 } else { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3116 src = downstream; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3117 dst = upstream; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3118 b = &u->from_client; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3119 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3120 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
|
3121 b = r->header_in; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3122 b->end = b->last; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3123 do_write = 1; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3124 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3125 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3126 if (b->start == NULL) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3127 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
|
3128 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
|
3129 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
|
3130 return; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3131 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3132 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3133 b->pos = b->start; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3134 b->last = b->start; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3135 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
|
3136 b->temporary = 1; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3137 b->tag = u->output.tag; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3138 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3139 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3140 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3141 for ( ;; ) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3142 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3143 if (do_write) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3144 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3145 size = b->last - b->pos; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3146 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3147 if (size && dst->write->ready) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3148 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3149 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
|
3150 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3151 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
|
3152 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
|
3153 return; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3154 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3155 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3156 if (n > 0) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3157 b->pos += n; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3158 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3159 if (b->pos == b->last) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3160 b->pos = b->start; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3161 b->last = b->start; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3162 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3163 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3164 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3165 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3166 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3167 size = b->end - b->last; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3168 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3169 if (size && src->read->ready) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3170 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3171 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
|
3172 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3173 if (n == NGX_AGAIN || n == 0) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3174 break; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3175 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3176 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3177 if (n > 0) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3178 do_write = 1; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3179 b->last += n; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3180 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3181 continue; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3182 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3183 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3184 if (n == NGX_ERROR) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3185 src->read->eof = 1; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3186 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3187 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3188 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3189 break; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3190 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3191 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3192 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
|
3193 || (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
|
3194 || (downstream->read->eof && upstream->read->eof)) |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3195 { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3196 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
|
3197 "http upstream upgraded done"); |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3198 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
|
3199 return; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3200 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3201 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3202 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
|
3203 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3204 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
|
3205 != NGX_OK) |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3206 { |
5295
a489c31c9783
Upstream: ngx_http_upstream_finalize_request(NGX_ERROR) on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5294
diff
changeset
|
3207 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
|
3208 return; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3209 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3210 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3211 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
|
3212 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
|
3213 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3214 } else if (upstream->write->timer_set) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3215 ngx_del_timer(upstream->write); |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3216 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3217 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3218 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
|
3219 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
|
3220 return; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3221 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3222 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3223 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
|
3224 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
|
3225 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3226 } else if (upstream->read->timer_set) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3227 ngx_del_timer(upstream->read); |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3228 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3229 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3230 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
|
3231 != NGX_OK) |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3232 { |
5295
a489c31c9783
Upstream: ngx_http_upstream_finalize_request(NGX_ERROR) on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5294
diff
changeset
|
3233 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
|
3234 return; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3235 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3236 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3237 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
|
3238 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
|
3239 return; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3240 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3241 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3242 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
|
3243 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
|
3244 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3245 } else if (downstream->write->timer_set) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3246 ngx_del_timer(downstream->write); |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3247 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3248 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3249 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3250 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3251 static void |
581 | 3252 ngx_http_upstream_process_non_buffered_downstream(ngx_http_request_t *r) |
3253 { | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3254 ngx_event_t *wev; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3255 ngx_connection_t *c; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3256 ngx_http_upstream_t *u; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3257 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3258 c = r->connection; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3259 u = r->upstream; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3260 wev = c->write; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3261 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3262 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
|
3263 "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
|
3264 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3265 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
|
3266 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3267 if (wev->timedout) { |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3268 c->timedout = 1; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3269 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
|
3270 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
|
3271 return; |
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 ngx_http_upstream_process_non_buffered_request(r, 1); |
581 | 3275 } |
3276 | |
3277 | |
3278 static void | |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
3279 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
|
3280 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
|
3281 { |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
3282 ngx_connection_t *c; |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
3283 |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
3284 c = u->peer.connection; |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3285 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3286 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
|
3287 "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
|
3288 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3289 c->log->action = "reading upstream"; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3290 |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
3291 if (c->read->timedout) { |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3292 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
|
3293 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
|
3294 return; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3295 } |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3296 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3297 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
|
3298 } |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3299 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3300 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3301 static void |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3302 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
|
3303 ngx_uint_t do_write) |
581 | 3304 { |
3305 size_t size; | |
3306 ssize_t n; | |
3307 ngx_buf_t *b; | |
583 | 3308 ngx_int_t rc; |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3309 ngx_connection_t *downstream, *upstream; |
581 | 3310 ngx_http_upstream_t *u; |
3311 ngx_http_core_loc_conf_t *clcf; | |
3312 | |
756
d904b5cb3bba
fix building introduced by previous commit
Igor Sysoev <igor@sysoev.ru>
parents:
755
diff
changeset
|
3313 u = r->upstream; |
884 | 3314 downstream = r->connection; |
3315 upstream = u->peer.connection; | |
581 | 3316 |
3317 b = &u->buffer; | |
3318 | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3319 do_write = do_write || u->length == 0; |
581 | 3320 |
3321 for ( ;; ) { | |
3322 | |
3323 if (do_write) { | |
3324 | |
3325 if (u->out_bufs || u->busy_bufs) { | |
583 | 3326 rc = ngx_http_output_filter(r, u->out_bufs); |
3327 | |
3328 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
|
3329 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
581 | 3330 return; |
3331 } | |
3332 | |
4114
5db098f97e0e
API change: ngx_chain_update_chains() now requires pool.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3976
diff
changeset
|
3333 ngx_chain_update_chains(r->pool, &u->free_bufs, &u->busy_bufs, |
581 | 3334 &u->out_bufs, u->output.tag); |
3335 } | |
3336 | |
3337 if (u->busy_bufs == NULL) { | |
3338 | |
3339 if (u->length == 0 | |
5301
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3340 || (upstream->read->eof && u->length == -1)) |
581 | 3341 { |
3342 ngx_http_upstream_finalize_request(r, u, 0); | |
3343 return; | |
3344 } | |
3345 | |
5301
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3346 if (upstream->read->eof) { |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3347 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
|
3348 "upstream prematurely closed connection"); |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3349 |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3350 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
|
3351 NGX_HTTP_BAD_GATEWAY); |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3352 return; |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3353 } |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3354 |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3355 if (upstream->read->error) { |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3356 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
|
3357 NGX_HTTP_BAD_GATEWAY); |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3358 return; |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3359 } |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3360 |
581 | 3361 b->pos = b->start; |
3362 b->last = b->start; | |
3363 } | |
3364 } | |
3365 | |
3366 size = b->end - b->last; | |
3367 | |
884 | 3368 if (size && upstream->read->ready) { |
3369 | |
3370 n = upstream->recv(upstream, b->last, size); | |
581 | 3371 |
3372 if (n == NGX_AGAIN) { | |
3373 break; | |
3374 } | |
3375 | |
3376 if (n > 0) { | |
2402 | 3377 u->state->response_length += n; |
3378 | |
581 | 3379 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
|
3380 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
581 | 3381 return; |
3382 } | |
3383 } | |
3384 | |
3385 do_write = 1; | |
3386 | |
3387 continue; | |
3388 } | |
3389 | |
3390 break; | |
3391 } | |
3392 | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3393 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
|
3394 |
884 | 3395 if (downstream->data == r) { |
3396 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
|
3397 != NGX_OK) |
583 | 3398 { |
5295
a489c31c9783
Upstream: ngx_http_upstream_finalize_request(NGX_ERROR) on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5294
diff
changeset
|
3399 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
583 | 3400 return; |
3401 } | |
581 | 3402 } |
3403 | |
1063
e2a6ecc5a3ae
a non-active client connection must not closed after send timeout
Igor Sysoev <igor@sysoev.ru>
parents:
1031
diff
changeset
|
3404 if (downstream->write->active && !downstream->write->ready) { |
884 | 3405 ngx_add_timer(downstream->write, clcf->send_timeout); |
3406 | |
3407 } else if (downstream->write->timer_set) { | |
3408 ngx_del_timer(downstream->write); | |
581 | 3409 } |
3410 | |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
3411 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
|
3412 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
581 | 3413 return; |
3414 } | |
3415 | |
1063
e2a6ecc5a3ae
a non-active client connection must not closed after send timeout
Igor Sysoev <igor@sysoev.ru>
parents:
1031
diff
changeset
|
3416 if (upstream->read->active && !upstream->read->ready) { |
884 | 3417 ngx_add_timer(upstream->read, u->conf->read_timeout); |
3418 | |
3419 } else if (upstream->read->timer_set) { | |
3420 ngx_del_timer(upstream->read); | |
581 | 3421 } |
3422 } | |
3423 | |
3424 | |
3425 static ngx_int_t | |
3426 ngx_http_upstream_non_buffered_filter_init(void *data) | |
3427 { | |
3428 return NGX_OK; | |
3429 } | |
3430 | |
3431 | |
3432 static ngx_int_t | |
3433 ngx_http_upstream_non_buffered_filter(void *data, ssize_t bytes) | |
3434 { | |
3435 ngx_http_request_t *r = data; | |
3436 | |
3437 ngx_buf_t *b; | |
3438 ngx_chain_t *cl, **ll; | |
3439 ngx_http_upstream_t *u; | |
3440 | |
3441 u = r->upstream; | |
3442 | |
3443 for (cl = u->out_bufs, ll = &u->out_bufs; cl; cl = cl->next) { | |
3444 ll = &cl->next; | |
3445 } | |
3446 | |
3447 cl = ngx_chain_get_free_buf(r->pool, &u->free_bufs); | |
3448 if (cl == NULL) { | |
3449 return NGX_ERROR; | |
3450 } | |
3451 | |
3452 *ll = cl; | |
3453 | |
3454 cl->buf->flush = 1; | |
3455 cl->buf->memory = 1; | |
3456 | |
3457 b = &u->buffer; | |
3458 | |
3459 cl->buf->pos = b->last; | |
3460 b->last += bytes; | |
3461 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
|
3462 cl->buf->tag = u->output.tag; |
581 | 3463 |
4118
dbddec65fdab
Upstream: r->upstream->length type change to off_t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4117
diff
changeset
|
3464 if (u->length == -1) { |
581 | 3465 return NGX_OK; |
3466 } | |
3467 | |
3468 u->length -= bytes; | |
3469 | |
3470 return NGX_OK; | |
3471 } | |
3472 | |
3473 | |
3474 static void | |
509 | 3475 ngx_http_upstream_process_downstream(ngx_http_request_t *r) |
3476 { | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3477 ngx_event_t *wev; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3478 ngx_connection_t *c; |
509 | 3479 ngx_event_pipe_t *p; |
479 | 3480 ngx_http_upstream_t *u; |
3481 | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3482 c = r->connection; |
479 | 3483 u = r->upstream; |
581 | 3484 p = u->pipe; |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3485 wev = c->write; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3486 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3487 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
|
3488 "http upstream process downstream"); |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3489 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3490 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
|
3491 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3492 if (wev->timedout) { |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3493 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3494 if (wev->delayed) { |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3495 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3496 wev->timedout = 0; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3497 wev->delayed = 0; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3498 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3499 if (!wev->ready) { |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3500 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
|
3501 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3502 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
|
3503 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
|
3504 } |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3505 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3506 return; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3507 } |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3508 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3509 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
|
3510 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
|
3511 return; |
527 | 3512 } |
479 | 3513 |
3514 } else { | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3515 p->downstream_error = 1; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3516 c->timedout = 1; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3517 ngx_connection_error(c, NGX_ETIMEDOUT, "client timed out"); |
479 | 3518 } |
3519 | |
3520 } else { | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3521 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3522 if (wev->delayed) { |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3523 |
527 | 3524 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, |
3525 "http downstream delayed"); | |
3526 | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3527 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
|
3528 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
527 | 3529 } |
3530 | |
3531 return; | |
3532 } | |
3533 | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3534 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
|
3535 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
479 | 3536 return; |
3537 } | |
3538 } | |
577 | 3539 |
5995
5f179f344096
Upstream: upstream argument in ngx_http_upstream_process_request().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5994
diff
changeset
|
3540 ngx_http_upstream_process_request(r, u); |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3541 } |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3542 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3543 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3544 static void |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
3545 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
|
3546 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
|
3547 { |
5883
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3548 ngx_event_t *rev; |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3549 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
|
3550 ngx_connection_t *c; |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
3551 |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
3552 c = u->peer.connection; |
5883
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3553 p = u->pipe; |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3554 rev = c->read; |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3555 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3556 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
|
3557 "http upstream process upstream"); |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3558 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3559 c->log->action = "reading upstream"; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3560 |
5883
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3561 if (rev->timedout) { |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3562 |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3563 if (rev->delayed) { |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3564 |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3565 rev->timedout = 0; |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3566 rev->delayed = 0; |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3567 |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3568 if (!rev->ready) { |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3569 ngx_add_timer(rev, p->read_timeout); |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3570 |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3571 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
|
3572 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
|
3573 } |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3574 |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3575 return; |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3576 } |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3577 |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3578 if (ngx_event_pipe(p, 0) == NGX_ABORT) { |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3579 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
|
3580 return; |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3581 } |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3582 |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3583 } else { |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3584 p->upstream_error = 1; |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3585 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
|
3586 } |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3587 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3588 } else { |
5883
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3589 |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3590 if (rev->delayed) { |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3591 |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3592 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
|
3593 "http upstream delayed"); |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3594 |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3595 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
|
3596 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
|
3597 } |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3598 |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3599 return; |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3600 } |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3601 |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3602 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
|
3603 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
|
3604 return; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3605 } |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3606 } |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3607 |
5995
5f179f344096
Upstream: upstream argument in ngx_http_upstream_process_request().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5994
diff
changeset
|
3608 ngx_http_upstream_process_request(r, u); |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3609 } |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3610 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3611 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3612 static void |
5995
5f179f344096
Upstream: upstream argument in ngx_http_upstream_process_request().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5994
diff
changeset
|
3613 ngx_http_upstream_process_request(ngx_http_request_t *r, |
5f179f344096
Upstream: upstream argument in ngx_http_upstream_process_request().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5994
diff
changeset
|
3614 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
|
3615 { |
5996 | 3616 ngx_temp_file_t *tf; |
3617 ngx_event_pipe_t *p; | |
5995
5f179f344096
Upstream: upstream argument in ngx_http_upstream_process_request().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5994
diff
changeset
|
3618 |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3619 p = u->pipe; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3620 |
479 | 3621 if (u->peer.connection) { |
3622 | |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3623 if (u->store) { |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3624 |
2463 | 3625 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
|
3626 |
5298
a7b2db9119e0
Upstream: replaced u->pipe->temp_file with p->temp_file.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5297
diff
changeset
|
3627 tf = p->temp_file; |
4469
24c0dca04eb9
Fix for proxy_store leaving temporary files for subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4464
diff
changeset
|
3628 |
2445
3c6af1fb7586
proxy/fastcgi_store did not delete incomplete files
Igor Sysoev <igor@sysoev.ru>
parents:
2441
diff
changeset
|
3629 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
|
3630 && (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
|
3631 && (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
|
3632 || 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
|
3633 { |
3c6af1fb7586
proxy/fastcgi_store did not delete incomplete files
Igor Sysoev <igor@sysoev.ru>
parents:
2441
diff
changeset
|
3634 ngx_http_upstream_store(r, u); |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3635 } |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3636 } |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3637 } |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3638 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3639 #if (NGX_HTTP_CACHE) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3640 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3641 if (u->cacheable) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3642 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3643 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
|
3644 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
|
3645 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3646 } else if (p->upstream_eof) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3647 |
5298
a7b2db9119e0
Upstream: replaced u->pipe->temp_file with p->temp_file.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5297
diff
changeset
|
3648 tf = p->temp_file; |
4298
186f02886bed
Upstream: don't cache unfinished responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4197
diff
changeset
|
3649 |
5299
b779728b180c
Upstream: fixed store/cache of unfinished responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5298
diff
changeset
|
3650 if (p->length == -1 |
b779728b180c
Upstream: fixed store/cache of unfinished responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5298
diff
changeset
|
3651 && (u->headers_in.content_length_n == -1 |
b779728b180c
Upstream: fixed store/cache of unfinished responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5298
diff
changeset
|
3652 || u->headers_in.content_length_n |
b779728b180c
Upstream: fixed store/cache of unfinished responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5298
diff
changeset
|
3653 == 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
|
3654 { |
186f02886bed
Upstream: don't cache unfinished responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4197
diff
changeset
|
3655 ngx_http_file_cache_update(r, tf); |
186f02886bed
Upstream: don't cache unfinished responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4197
diff
changeset
|
3656 |
186f02886bed
Upstream: don't cache unfinished responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4197
diff
changeset
|
3657 } else { |
186f02886bed
Upstream: don't cache unfinished responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4197
diff
changeset
|
3658 ngx_http_file_cache_free(r->cache, tf); |
186f02886bed
Upstream: don't cache unfinished responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4197
diff
changeset
|
3659 } |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3660 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3661 } 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
|
3662 ngx_http_file_cache_free(r->cache, p->temp_file); |
479 | 3663 } |
3664 } | |
3665 | |
3666 #endif | |
3667 | |
3668 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
|
3669 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
483 | 3670 "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
|
3671 |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3672 if (p->upstream_done |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3673 || (p->upstream_eof && p->length == -1)) |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3674 { |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3675 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
|
3676 return; |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3677 } |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3678 |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3679 if (p->upstream_eof) { |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3680 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
|
3681 "upstream prematurely closed connection"); |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3682 } |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3683 |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3684 ngx_http_upstream_finalize_request(r, u, NGX_HTTP_BAD_GATEWAY); |
479 | 3685 return; |
3686 } | |
3687 } | |
3688 | |
3689 if (p->downstream_error) { | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3690 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
483 | 3691 "http upstream downstream error"); |
479 | 3692 |
2757
9cc973b46af1
get a full response if the response is cacheable or storable even
Igor Sysoev <igor@sysoev.ru>
parents:
2708
diff
changeset
|
3693 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
|
3694 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
479 | 3695 } |
3696 } | |
3697 } | |
3698 | |
3699 | |
487 | 3700 static void |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3701 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
|
3702 { |
1947
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
3703 size_t root; |
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
3704 time_t lm; |
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
3705 ngx_str_t path; |
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
3706 ngx_temp_file_t *tf; |
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
3707 ngx_ext_rename_file_t ext; |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3708 |
1777 | 3709 tf = u->pipe->temp_file; |
3710 | |
3711 if (tf->file.fd == NGX_INVALID_FILE) { | |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3712 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3713 /* create file for empty 200 response */ |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3714 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3715 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
|
3716 if (tf == NULL) { |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3717 return; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3718 } |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3719 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3720 tf->file.fd = NGX_INVALID_FILE; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3721 tf->file.log = r->connection->log; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3722 tf->path = u->conf->temp_path; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3723 tf->pool = r->pool; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3724 tf->persistent = 1; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3725 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3726 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
|
3727 tf->persistent, tf->clean, tf->access) |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3728 != NGX_OK) |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3729 { |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3730 return; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3731 } |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3732 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3733 u->pipe->temp_file = tf; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3734 } |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3735 |
1947
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
3736 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
|
3737 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
|
3738 ext.time = -1; |
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
3739 ext.create_path = 1; |
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
3740 ext.delete_file = 1; |
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
3741 ext.log = r->connection->log; |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3742 |
1705 | 3743 if (u->headers_in.last_modified) { |
3744 | |
6180
8b6fa4842133
Moved ngx_http_parse_time() to core, renamed accordingly.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6147
diff
changeset
|
3745 lm = ngx_parse_http_time(u->headers_in.last_modified->value.data, |
1947
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
3746 u->headers_in.last_modified->value.len); |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3747 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3748 if (lm != NGX_ERROR) { |
1947
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
3749 ext.time = lm; |
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
3750 ext.fd = tf->file.fd; |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3751 } |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3752 } |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3753 |
1295
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
3754 if (u->conf->store_lengths == NULL) { |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
3755 |
5770
9de5820bb3e0
Upstream: ngx_http_upstream_store() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5757
diff
changeset
|
3756 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
|
3757 return; |
9de5820bb3e0
Upstream: ngx_http_upstream_store() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5757
diff
changeset
|
3758 } |
1295
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
3759 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
3760 } else { |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
3761 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
|
3762 u->conf->store_values->elts) |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
3763 == NULL) |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
3764 { |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
3765 return; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
3766 } |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
3767 } |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3768 |
3032
524ba56ba9f7
fix copy destination name length, introduced in r3025
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
3769 path.len--; |
524ba56ba9f7
fix copy destination name length, introduced in r3025
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
3770 |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3771 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
|
3772 "upstream stores \"%s\" to \"%s\"", |
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
3773 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
|
3774 |
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
3775 (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
|
3776 |
9de5820bb3e0
Upstream: ngx_http_upstream_store() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5757
diff
changeset
|
3777 u->store = 0; |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3778 } |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3779 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3780 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3781 static void |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
3782 ngx_http_upstream_dummy_handler(ngx_http_request_t *r, ngx_http_upstream_t *u) |
479 | 3783 { |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
3784 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
479 | 3785 "http upstream dummy handler"); |
3786 } | |
3787 | |
3788 | |
487 | 3789 static void |
3790 ngx_http_upstream_next(ngx_http_request_t *r, ngx_http_upstream_t *u, | |
3791 ngx_uint_t ft_type) | |
479 | 3792 { |
5832
d09b689911ac
Upstream: limited next_upstream time and tries (ticket #544).
Roman Arutyunyan <arut@nginx.com>
parents:
5827
diff
changeset
|
3793 ngx_msec_t timeout; |
884 | 3794 ngx_uint_t status, state; |
479 | 3795 |
3796 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
884 | 3797 "http next upstream, %xi", ft_type); |
479 | 3798 |
5132
9bcf89ca78d2
Upstream: only call peer.free() if peer.get() selected a peer.
Ruslan Ermilov <ru@nginx.com>
parents:
5121
diff
changeset
|
3799 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
|
3800 |
5231
05c53652e7b4
Upstream: http_403 support in proxy_next_upstream (and friends).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5217
diff
changeset
|
3801 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
|
3802 || 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
|
3803 { |
5132
9bcf89ca78d2
Upstream: only call peer.free() if peer.get() selected a peer.
Ruslan Ermilov <ru@nginx.com>
parents:
5121
diff
changeset
|
3804 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
|
3805 |
5132
9bcf89ca78d2
Upstream: only call peer.free() if peer.get() selected a peer.
Ruslan Ermilov <ru@nginx.com>
parents:
5121
diff
changeset
|
3806 } else { |
9bcf89ca78d2
Upstream: only call peer.free() if peer.get() selected a peer.
Ruslan Ermilov <ru@nginx.com>
parents:
5121
diff
changeset
|
3807 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
|
3808 } |
9bcf89ca78d2
Upstream: only call peer.free() if peer.get() selected a peer.
Ruslan Ermilov <ru@nginx.com>
parents:
5121
diff
changeset
|
3809 |
1378 | 3810 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
|
3811 u->peer.sockaddr = NULL; |
1378 | 3812 } |
525 | 3813 |
479 | 3814 if (ft_type == NGX_HTTP_UPSTREAM_FT_TIMEOUT) { |
3815 ngx_log_error(NGX_LOG_ERR, r->connection->log, NGX_ETIMEDOUT, | |
3816 "upstream timed out"); | |
3817 } | |
577 | 3818 |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
3819 if (u->peer.cached && ft_type == NGX_HTTP_UPSTREAM_FT_ERROR |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
3820 && (!u->request_sent || !r->request_body_no_buffering)) |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
3821 { |
479 | 3822 status = 0; |
3823 | |
4115
70a45a504905
Workaround for cpu hog on errors with cached connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4114
diff
changeset
|
3824 /* TODO: inform balancer instead */ |
70a45a504905
Workaround for cpu hog on errors with cached connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4114
diff
changeset
|
3825 |
70a45a504905
Workaround for cpu hog on errors with cached connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4114
diff
changeset
|
3826 u->peer.tries++; |
70a45a504905
Workaround for cpu hog on errors with cached connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4114
diff
changeset
|
3827 |
479 | 3828 } else { |
5757
c5ec6944de98
Style: add whitespace between control statement and parentheses.
Piotr Sikora <piotr@cloudflare.com>
parents:
5746
diff
changeset
|
3829 switch (ft_type) { |
479 | 3830 |
3831 case NGX_HTTP_UPSTREAM_FT_TIMEOUT: | |
3832 status = NGX_HTTP_GATEWAY_TIME_OUT; | |
3833 break; | |
3834 | |
3835 case NGX_HTTP_UPSTREAM_FT_HTTP_500: | |
3836 status = NGX_HTTP_INTERNAL_SERVER_ERROR; | |
3837 break; | |
3838 | |
5231
05c53652e7b4
Upstream: http_403 support in proxy_next_upstream (and friends).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5217
diff
changeset
|
3839 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
|
3840 status = NGX_HTTP_FORBIDDEN; |
05c53652e7b4
Upstream: http_403 support in proxy_next_upstream (and friends).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5217
diff
changeset
|
3841 break; |
05c53652e7b4
Upstream: http_403 support in proxy_next_upstream (and friends).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5217
diff
changeset
|
3842 |
479 | 3843 case NGX_HTTP_UPSTREAM_FT_HTTP_404: |
3844 status = NGX_HTTP_NOT_FOUND; | |
3845 break; | |
3846 | |
3847 /* | |
3848 * NGX_HTTP_UPSTREAM_FT_BUSY_LOCK and NGX_HTTP_UPSTREAM_FT_MAX_WAITING | |
3849 * never reach here | |
3850 */ | |
3851 | |
3852 default: | |
3853 status = NGX_HTTP_BAD_GATEWAY; | |
3854 } | |
3855 } | |
3856 | |
583 | 3857 if (r->connection->error) { |
479 | 3858 ngx_http_upstream_finalize_request(r, u, |
3859 NGX_HTTP_CLIENT_CLOSED_REQUEST); | |
3860 return; | |
3861 } | |
3862 | |
3863 if (status) { | |
3864 u->state->status = status; | |
5832
d09b689911ac
Upstream: limited next_upstream time and tries (ticket #544).
Roman Arutyunyan <arut@nginx.com>
parents:
5827
diff
changeset
|
3865 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
|
3866 |
d09b689911ac
Upstream: limited next_upstream time and tries (ticket #544).
Roman Arutyunyan <arut@nginx.com>
parents:
5827
diff
changeset
|
3867 if (u->peer.tries == 0 |
d09b689911ac
Upstream: limited next_upstream time and tries (ticket #544).
Roman Arutyunyan <arut@nginx.com>
parents:
5827
diff
changeset
|
3868 || !(u->conf->next_upstream & ft_type) |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
3869 || (u->request_sent && r->request_body_no_buffering) |
5832
d09b689911ac
Upstream: limited next_upstream time and tries (ticket #544).
Roman Arutyunyan <arut@nginx.com>
parents:
5827
diff
changeset
|
3870 || (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
|
3871 { |
479 | 3872 #if (NGX_HTTP_CACHE) |
3873 | |
2952 | 3874 if (u->cache_status == NGX_HTTP_CACHE_EXPIRED |
3875 && (u->conf->cache_use_stale & ft_type)) | |
3876 { | |
2805
60551422e150
reinit proxy/fastcgi header parser before ngx_http_upstream_cache_send()
Igor Sysoev <igor@sysoev.ru>
parents:
2804
diff
changeset
|
3877 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
|
3878 |
60551422e150
reinit proxy/fastcgi header parser before ngx_http_upstream_cache_send()
Igor Sysoev <igor@sysoev.ru>
parents:
2804
diff
changeset
|
3879 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
|
3880 |
60551422e150
reinit proxy/fastcgi header parser before ngx_http_upstream_cache_send()
Igor Sysoev <igor@sysoev.ru>
parents:
2804
diff
changeset
|
3881 if (rc == NGX_OK) { |
2952 | 3882 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
|
3883 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
|
3884 } |
60551422e150
reinit proxy/fastcgi header parser before ngx_http_upstream_cache_send()
Igor Sysoev <igor@sysoev.ru>
parents:
2804
diff
changeset
|
3885 |
60551422e150
reinit proxy/fastcgi header parser before ngx_http_upstream_cache_send()
Igor Sysoev <igor@sysoev.ru>
parents:
2804
diff
changeset
|
3886 ngx_http_upstream_finalize_request(r, u, rc); |
479 | 3887 return; |
3888 } | |
3889 #endif | |
3890 | |
3891 ngx_http_upstream_finalize_request(r, u, status); | |
3892 return; | |
3893 } | |
3894 } | |
3895 | |
3896 if (u->peer.connection) { | |
3897 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
3898 "close http upstream connection: %d", | |
3899 u->peer.connection->fd); | |
577 | 3900 #if (NGX_HTTP_SSL) |
884 | 3901 |
577 | 3902 if (u->peer.connection->ssl) { |
884 | 3903 u->peer.connection->ssl->no_wait_shutdown = 1; |
3904 u->peer.connection->ssl->no_send_shutdown = 1; | |
3905 | |
3906 (void) ngx_ssl_shutdown(u->peer.connection); | |
577 | 3907 } |
3908 #endif | |
884 | 3909 |
4138
70e1ee2307f9
Fix of separate pool for upstream connections (r4117).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4124
diff
changeset
|
3910 if (u->peer.connection->pool) { |
70e1ee2307f9
Fix of separate pool for upstream connections (r4117).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4124
diff
changeset
|
3911 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
|
3912 } |
70e1ee2307f9
Fix of separate pool for upstream connections (r4117).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4124
diff
changeset
|
3913 |
479 | 3914 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
|
3915 u->peer.connection = NULL; |
479 | 3916 } |
3917 | |
3918 ngx_http_upstream_connect(r, u); | |
3919 } | |
3920 | |
3921 | |
487 | 3922 static void |
569 | 3923 ngx_http_upstream_cleanup(void *data) |
3924 { | |
3925 ngx_http_request_t *r = data; | |
3926 | |
3927 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
3928 "cleanup http upstream request: \"%V\"", &r->uri); | |
3929 | |
5167
85ee9d858dcb
Upstream: removed surplus ngx_resolve_name_done() call.
Valentin Bartenev <vbart@nginx.com>
parents:
5142
diff
changeset
|
3930 ngx_http_upstream_finalize_request(r, r->upstream, NGX_DONE); |
569 | 3931 } |
3932 | |
3933 | |
3934 static void | |
487 | 3935 ngx_http_upstream_finalize_request(ngx_http_request_t *r, |
3936 ngx_http_upstream_t *u, ngx_int_t rc) | |
479 | 3937 { |
6146
59fc60585f1e
Upstream: times to obtain header/response are stored as ngx_msec_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6125
diff
changeset
|
3938 ngx_uint_t flush; |
563 | 3939 |
483 | 3940 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
3941 "finalize http upstream request: %i", rc); | |
479 | 3942 |
5994
5abf5af257a7
Upstream: avoid duplicate finalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5992
diff
changeset
|
3943 if (u->cleanup == NULL) { |
5abf5af257a7
Upstream: avoid duplicate finalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5992
diff
changeset
|
3944 /* the request was already finalized */ |
5abf5af257a7
Upstream: avoid duplicate finalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5992
diff
changeset
|
3945 ngx_http_finalize_request(r, NGX_DONE); |
5abf5af257a7
Upstream: avoid duplicate finalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5992
diff
changeset
|
3946 return; |
5abf5af257a7
Upstream: avoid duplicate finalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5992
diff
changeset
|
3947 } |
5abf5af257a7
Upstream: avoid duplicate finalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5992
diff
changeset
|
3948 |
5abf5af257a7
Upstream: avoid duplicate finalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5992
diff
changeset
|
3949 *u->cleanup = NULL; |
5abf5af257a7
Upstream: avoid duplicate finalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5992
diff
changeset
|
3950 u->cleanup = NULL; |
569 | 3951 |
3169
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
3952 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
|
3953 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
|
3954 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
|
3955 } |
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
3956 |
6146
59fc60585f1e
Upstream: times to obtain header/response are stored as ngx_msec_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6125
diff
changeset
|
3957 if (u->state && u->state->response_time) { |
59fc60585f1e
Upstream: times to obtain header/response are stored as ngx_msec_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6125
diff
changeset
|
3958 u->state->response_time = ngx_current_msec - u->state->response_time; |
2402 | 3959 |
5169
f6bbe77794aa
Upstream: fixed $upstream_response_length without buffering.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5167
diff
changeset
|
3960 if (u->pipe && u->pipe->read_length) { |
2402 | 3961 u->state->response_length = u->pipe->read_length; |
3962 } | |
563 | 3963 } |
3964 | |
479 | 3965 u->finalize_request(r, rc); |
3966 | |
5132
9bcf89ca78d2
Upstream: only call peer.free() if peer.get() selected a peer.
Ruslan Ermilov <ru@nginx.com>
parents:
5121
diff
changeset
|
3967 if (u->peer.free && u->peer.sockaddr) { |
1658 | 3968 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
|
3969 u->peer.sockaddr = NULL; |
1658 | 3970 } |
884 | 3971 |
479 | 3972 if (u->peer.connection) { |
884 | 3973 |
577 | 3974 #if (NGX_HTTP_SSL) |
3975 | |
3976 /* TODO: do not shutdown persistent connection */ | |
3977 | |
3978 if (u->peer.connection->ssl) { | |
884 | 3979 |
3980 /* | |
3981 * We send the "close notify" shutdown alert to the upstream only | |
3982 * and do not wait its "close notify" shutdown alert. | |
3983 * It is acceptable according to the TLS standard. | |
3984 */ | |
3985 | |
3986 u->peer.connection->ssl->no_wait_shutdown = 1; | |
3987 | |
3988 (void) ngx_ssl_shutdown(u->peer.connection); | |
577 | 3989 } |
3990 #endif | |
884 | 3991 |
3992 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
3993 "close http upstream connection: %d", | |
3994 u->peer.connection->fd); | |
3995 | |
4138
70e1ee2307f9
Fix of separate pool for upstream connections (r4117).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4124
diff
changeset
|
3996 if (u->peer.connection->pool) { |
70e1ee2307f9
Fix of separate pool for upstream connections (r4117).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4124
diff
changeset
|
3997 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
|
3998 } |
70e1ee2307f9
Fix of separate pool for upstream connections (r4117).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4124
diff
changeset
|
3999 |
479 | 4000 ngx_close_connection(u->peer.connection); |
4001 } | |
4002 | |
483 | 4003 u->peer.connection = NULL; |
4004 | |
581 | 4005 if (u->pipe && u->pipe->temp_file) { |
479 | 4006 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
4007 "http upstream temp fd: %d", | |
581 | 4008 u->pipe->temp_file->file.fd); |
479 | 4009 } |
4010 | |
4469
24c0dca04eb9
Fix for proxy_store leaving temporary files for subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4464
diff
changeset
|
4011 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
|
4012 && 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
|
4013 { |
24c0dca04eb9
Fix for proxy_store leaving temporary files for subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4464
diff
changeset
|
4014 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
|
4015 == NGX_FILE_ERROR) |
24c0dca04eb9
Fix for proxy_store leaving temporary files for subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4464
diff
changeset
|
4016 { |
24c0dca04eb9
Fix for proxy_store leaving temporary files for subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4464
diff
changeset
|
4017 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
|
4018 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
|
4019 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
|
4020 } |
24c0dca04eb9
Fix for proxy_store leaving temporary files for subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4464
diff
changeset
|
4021 } |
24c0dca04eb9
Fix for proxy_store leaving temporary files for subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4464
diff
changeset
|
4022 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4023 #if (NGX_HTTP_CACHE) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4024 |
3940
22f3e9197096
revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents:
3934
diff
changeset
|
4025 if (r->cache) { |
22f3e9197096
revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents:
3934
diff
changeset
|
4026 |
22f3e9197096
revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents:
3934
diff
changeset
|
4027 if (u->cacheable) { |
22f3e9197096
revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents:
3934
diff
changeset
|
4028 |
22f3e9197096
revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents:
3934
diff
changeset
|
4029 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
|
4030 time_t valid; |
22f3e9197096
revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents:
3934
diff
changeset
|
4031 |
22f3e9197096
revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents:
3934
diff
changeset
|
4032 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
|
4033 |
22f3e9197096
revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents:
3934
diff
changeset
|
4034 if (valid) { |
22f3e9197096
revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents:
3934
diff
changeset
|
4035 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
|
4036 r->cache->error = rc; |
22f3e9197096
revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents:
3934
diff
changeset
|
4037 } |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4038 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4039 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4040 |
3711
ce6ba077c270
several changes in cache cleanup handling:
Igor Sysoev <igor@sysoev.ru>
parents:
3709
diff
changeset
|
4041 ngx_http_file_cache_free(r->cache, u->pipe->temp_file); |
479 | 4042 } |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4043 |
479 | 4044 #endif |
4045 | |
5392
f1caf7b8ae1d
Upstream: subrequest_in_memory fix.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5373
diff
changeset
|
4046 if (r->subrequest_in_memory |
f1caf7b8ae1d
Upstream: subrequest_in_memory fix.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5373
diff
changeset
|
4047 && u->headers_in.status_n >= NGX_HTTP_SPECIAL_RESPONSE) |
f1caf7b8ae1d
Upstream: subrequest_in_memory fix.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5373
diff
changeset
|
4048 { |
f1caf7b8ae1d
Upstream: subrequest_in_memory fix.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5373
diff
changeset
|
4049 u->buffer.last = u->buffer.pos; |
f1caf7b8ae1d
Upstream: subrequest_in_memory fix.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5373
diff
changeset
|
4050 } |
f1caf7b8ae1d
Upstream: subrequest_in_memory fix.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5373
diff
changeset
|
4051 |
515 | 4052 if (rc == NGX_DECLINED) { |
4053 return; | |
4054 } | |
4055 | |
483 | 4056 r->connection->log->action = "sending to client"; |
4057 | |
5303
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
4058 if (!u->header_sent |
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
4059 || rc == NGX_HTTP_REQUEST_TIME_OUT |
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
4060 || rc == NGX_HTTP_CLIENT_CLOSED_REQUEST) |
4151
3549db8ceaf2
Cache: fix for sending of stale responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4143
diff
changeset
|
4061 { |
5303
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
4062 ngx_http_finalize_request(r, rc); |
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
4063 return; |
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
4064 } |
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
4065 |
5304
d3eab5e2df5f
Upstream: no last buffer on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5303
diff
changeset
|
4066 flush = 0; |
d3eab5e2df5f
Upstream: no last buffer on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5303
diff
changeset
|
4067 |
d3eab5e2df5f
Upstream: no last buffer on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5303
diff
changeset
|
4068 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) { |
d3eab5e2df5f
Upstream: no last buffer on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5303
diff
changeset
|
4069 rc = NGX_ERROR; |
d3eab5e2df5f
Upstream: no last buffer on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5303
diff
changeset
|
4070 flush = 1; |
5303
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
4071 } |
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
4072 |
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
4073 if (r->header_only) { |
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
4074 ngx_http_finalize_request(r, rc); |
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
4075 return; |
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
4076 } |
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
4077 |
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
4078 if (rc == 0) { |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
4079 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
|
4080 |
d3eab5e2df5f
Upstream: no last buffer on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5303
diff
changeset
|
4081 } else if (flush) { |
d3eab5e2df5f
Upstream: no last buffer on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5303
diff
changeset
|
4082 r->keepalive = 0; |
d3eab5e2df5f
Upstream: no last buffer on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5303
diff
changeset
|
4083 rc = ngx_http_send_special(r, NGX_HTTP_FLUSH); |
479 | 4084 } |
4085 | |
4086 ngx_http_finalize_request(r, rc); | |
4087 } | |
4088 | |
4089 | |
509 | 4090 static ngx_int_t |
4091 ngx_http_upstream_process_header_line(ngx_http_request_t *r, ngx_table_elt_t *h, | |
4092 ngx_uint_t offset) | |
577 | 4093 { |
509 | 4094 ngx_table_elt_t **ph; |
577 | 4095 |
509 | 4096 ph = (ngx_table_elt_t **) ((char *) &r->upstream->headers_in + offset); |
4097 | |
4098 if (*ph == NULL) { | |
4099 *ph = h; | |
4100 } | |
4101 | |
4102 return NGX_OK; | |
4103 } | |
4104 | |
4105 | |
4106 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
|
4107 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
|
4108 ngx_uint_t offset) |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4109 { |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4110 return NGX_OK; |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4111 } |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4112 |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4113 |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4114 static ngx_int_t |
4117
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
4115 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
|
4116 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
|
4117 { |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
4118 ngx_http_upstream_t *u; |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
4119 |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
4120 u = r->upstream; |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
4121 |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
4122 u->headers_in.content_length = h; |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
4123 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
|
4124 |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
4125 return NGX_OK; |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
4126 } |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
4127 |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
4128 |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
4129 static ngx_int_t |
5732
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
4130 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
|
4131 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
|
4132 { |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
4133 ngx_http_upstream_t *u; |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
4134 |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
4135 u = r->upstream; |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
4136 |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
4137 u->headers_in.last_modified = h; |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
4138 |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
4139 #if (NGX_HTTP_CACHE) |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
4140 |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
4141 if (u->cacheable) { |
6180
8b6fa4842133
Moved ngx_http_parse_time() to core, renamed accordingly.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6147
diff
changeset
|
4142 u->headers_in.last_modified_time = ngx_parse_http_time(h->value.data, |
5732
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
4143 h->value.len); |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
4144 } |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
4145 |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
4146 #endif |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
4147 |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
4148 return NGX_OK; |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
4149 } |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
4150 |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
4151 |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
4152 static ngx_int_t |
3669
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
4153 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
|
4154 ngx_uint_t offset) |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
4155 { |
5677
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4156 ngx_array_t *pa; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4157 ngx_table_elt_t **ph; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4158 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
|
4159 |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
4160 u = r->upstream; |
5677
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4161 pa = &u->headers_in.cookies; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4162 |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4163 if (pa->elts == NULL) { |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4164 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
|
4165 { |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4166 return NGX_ERROR; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4167 } |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4168 } |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4169 |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4170 ph = ngx_array_push(pa); |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4171 if (ph == NULL) { |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4172 return NGX_ERROR; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4173 } |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4174 |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4175 *ph = h; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4176 |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4177 #if (NGX_HTTP_CACHE) |
3669
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
4178 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
|
4179 u->cacheable = 0; |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
4180 } |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
4181 #endif |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
4182 |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
4183 return NGX_OK; |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
4184 } |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
4185 |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
4186 |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
4187 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
|
4188 ngx_http_upstream_process_cache_control(ngx_http_request_t *r, |
509 | 4189 ngx_table_elt_t *h, ngx_uint_t offset) |
4190 { | |
2786
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4191 ngx_array_t *pa; |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4192 ngx_table_elt_t **ph; |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4193 ngx_http_upstream_t *u; |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4194 |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4195 u = r->upstream; |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4196 pa = &u->headers_in.cache_control; |
509 | 4197 |
4198 if (pa->elts == NULL) { | |
4199 if (ngx_array_init(pa, r->pool, 2, sizeof(ngx_table_elt_t *)) != NGX_OK) | |
4200 { | |
4201 return NGX_ERROR; | |
4202 } | |
4203 } | |
4204 | |
4205 ph = ngx_array_push(pa); | |
4206 if (ph == NULL) { | |
4207 return NGX_ERROR; | |
4208 } | |
4209 | |
4210 *ph = h; | |
4211 | |
2708
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
4212 #if (NGX_HTTP_CACHE) |
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
4213 { |
5911
88d55e5934f7
Cache: add support for Cache-Control's s-maxage response directive.
Piotr Sikora <piotr@cloudflare.com>
parents:
5905
diff
changeset
|
4214 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
|
4215 ngx_int_t n; |
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
4216 |
2786
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4217 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
|
4218 return NGX_OK; |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4219 } |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4220 |
2669
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4221 if (r->cache == NULL) { |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4222 return NGX_OK; |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4223 } |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4224 |
5500
6a3ab6fdd70f
Upstream: Cache-Control preferred over Expires.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5489
diff
changeset
|
4225 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
|
4226 return NGX_OK; |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4227 } |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4228 |
5911
88d55e5934f7
Cache: add support for Cache-Control's s-maxage response directive.
Piotr Sikora <piotr@cloudflare.com>
parents:
5905
diff
changeset
|
4229 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
|
4230 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
|
4231 |
88d55e5934f7
Cache: add support for Cache-Control's s-maxage response directive.
Piotr Sikora <piotr@cloudflare.com>
parents:
5905
diff
changeset
|
4232 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
|
4233 || 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
|
4234 || 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
|
4235 { |
2786
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4236 u->cacheable = 0; |
2669
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4237 return NGX_OK; |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4238 } |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4239 |
5911
88d55e5934f7
Cache: add support for Cache-Control's s-maxage response directive.
Piotr Sikora <piotr@cloudflare.com>
parents:
5905
diff
changeset
|
4240 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
|
4241 offset = 9; |
88d55e5934f7
Cache: add support for Cache-Control's s-maxage response directive.
Piotr Sikora <piotr@cloudflare.com>
parents:
5905
diff
changeset
|
4242 |
88d55e5934f7
Cache: add support for Cache-Control's s-maxage response directive.
Piotr Sikora <piotr@cloudflare.com>
parents:
5905
diff
changeset
|
4243 if (p == NULL) { |
88d55e5934f7
Cache: add support for Cache-Control's s-maxage response directive.
Piotr Sikora <piotr@cloudflare.com>
parents:
5905
diff
changeset
|
4244 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
|
4245 offset = 8; |
88d55e5934f7
Cache: add support for Cache-Control's s-maxage response directive.
Piotr Sikora <piotr@cloudflare.com>
parents:
5905
diff
changeset
|
4246 } |
2669
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4247 |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4248 if (p == NULL) { |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4249 return NGX_OK; |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4250 } |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4251 |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4252 n = 0; |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4253 |
5911
88d55e5934f7
Cache: add support for Cache-Control's s-maxage response directive.
Piotr Sikora <piotr@cloudflare.com>
parents:
5905
diff
changeset
|
4254 for (p += offset; p < last; p++) { |
3198
48bfb7dc981b
test comma separator in "Cache-Control"
Igor Sysoev <igor@sysoev.ru>
parents:
3195
diff
changeset
|
4255 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
|
4256 break; |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4257 } |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4258 |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4259 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
|
4260 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
|
4261 continue; |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4262 } |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4263 |
2786
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4264 u->cacheable = 0; |
2669
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4265 return NGX_OK; |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4266 } |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4267 |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4268 if (n == 0) { |
2786
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4269 u->cacheable = 0; |
2669
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4270 return NGX_OK; |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4271 } |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4272 |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4273 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
|
4274 } |
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
4275 #endif |
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
4276 |
509 | 4277 return NGX_OK; |
4278 } | |
4279 | |
4280 | |
4281 static ngx_int_t | |
2666 | 4282 ngx_http_upstream_process_expires(ngx_http_request_t *r, ngx_table_elt_t *h, |
4283 ngx_uint_t offset) | |
4284 { | |
2786
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4285 ngx_http_upstream_t *u; |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4286 |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4287 u = r->upstream; |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4288 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
|
4289 |
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
4290 #if (NGX_HTTP_CACHE) |
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
4291 { |
2666 | 4292 time_t expires; |
4293 | |
2786
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4294 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
|
4295 return NGX_OK; |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4296 } |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4297 |
2666 | 4298 if (r->cache == NULL) { |
4299 return NGX_OK; | |
4300 } | |
4301 | |
4302 if (r->cache->valid_sec != 0) { | |
4303 return NGX_OK; | |
4304 } | |
4305 | |
6180
8b6fa4842133
Moved ngx_http_parse_time() to core, renamed accordingly.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6147
diff
changeset
|
4306 expires = ngx_parse_http_time(h->value.data, h->value.len); |
2666 | 4307 |
4308 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
|
4309 u->cacheable = 0; |
2666 | 4310 return NGX_OK; |
4311 } | |
4312 | |
4313 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
|
4314 } |
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
4315 #endif |
2666 | 4316 |
4317 return NGX_OK; | |
4318 } | |
4319 | |
4320 | |
4321 static ngx_int_t | |
2663
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4322 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
|
4323 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
|
4324 { |
2786
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4325 ngx_http_upstream_t *u; |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4326 |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4327 u = r->upstream; |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4328 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
|
4329 |
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
4330 #if (NGX_HTTP_CACHE) |
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
4331 { |
2663
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4332 u_char *p; |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4333 size_t len; |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4334 ngx_int_t n; |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4335 |
2786
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4336 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
|
4337 return NGX_OK; |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4338 } |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4339 |
2663
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4340 if (r->cache == NULL) { |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4341 return NGX_OK; |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4342 } |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4343 |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4344 len = h->value.len; |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4345 p = h->value.data; |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4346 |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4347 if (p[0] != '@') { |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4348 n = ngx_atoi(p, len); |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4349 |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4350 switch (n) { |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4351 case 0: |
2786
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4352 u->cacheable = 0; |
4546
4988fa232629
For the sake of case/switch code readability, 'fall through'
Maxim Konovalov <maxim@nginx.com>
parents:
4499
diff
changeset
|
4353 /* fall through */ |
4988fa232629
For the sake of case/switch code readability, 'fall through'
Maxim Konovalov <maxim@nginx.com>
parents:
4499
diff
changeset
|
4354 |
2663
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4355 case NGX_ERROR: |
2667 | 4356 return NGX_OK; |
2663
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4357 |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4358 default: |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4359 r->cache->valid_sec = ngx_time() + n; |
2667 | 4360 return NGX_OK; |
2663
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4361 } |
2667 | 4362 } |
4363 | |
4364 p++; | |
4365 len--; | |
4366 | |
4367 n = ngx_atoi(p, len); | |
4368 | |
4369 if (n != NGX_ERROR) { | |
4370 r->cache->valid_sec = n; | |
2663
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4371 } |
2708
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
4372 } |
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
4373 #endif |
2663
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4374 |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4375 return NGX_OK; |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4376 } |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4377 |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4378 |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4379 static ngx_int_t |
527 | 4380 ngx_http_upstream_process_limit_rate(ngx_http_request_t *r, ngx_table_elt_t *h, |
4381 ngx_uint_t offset) | |
577 | 4382 { |
4197
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4383 ngx_int_t n; |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4384 ngx_http_upstream_t *u; |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4385 |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4386 u = r->upstream; |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4387 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
|
4388 |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4389 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
|
4390 return NGX_OK; |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4391 } |
527 | 4392 |
4393 n = ngx_atoi(h->value.data, h->value.len); | |
4394 | |
4395 if (n != NGX_ERROR) { | |
4396 r->limit_rate = (size_t) n; | |
4397 } | |
4398 | |
4399 return NGX_OK; | |
4400 } | |
4401 | |
4402 | |
4403 static ngx_int_t | |
649 | 4404 ngx_http_upstream_process_buffering(ngx_http_request_t *r, ngx_table_elt_t *h, |
4405 ngx_uint_t offset) | |
4406 { | |
4197
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4407 u_char c0, c1, c2; |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4408 ngx_http_upstream_t *u; |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4409 |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4410 u = r->upstream; |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4411 |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4412 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
|
4413 return NGX_OK; |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4414 } |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4415 |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4416 if (u->conf->change_buffering) { |
649 | 4417 |
4418 if (h->value.len == 2) { | |
4419 c0 = ngx_tolower(h->value.data[0]); | |
4420 c1 = ngx_tolower(h->value.data[1]); | |
4421 | |
4422 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
|
4423 u->buffering = 0; |
649 | 4424 } |
4425 | |
4426 } else if (h->value.len == 3) { | |
4427 c0 = ngx_tolower(h->value.data[0]); | |
4428 c1 = ngx_tolower(h->value.data[1]); | |
4429 c2 = ngx_tolower(h->value.data[2]); | |
4430 | |
4431 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
|
4432 u->buffering = 1; |
649 | 4433 } |
4434 } | |
4435 } | |
4436 | |
4437 return NGX_OK; | |
4438 } | |
4439 | |
4440 | |
4441 static ngx_int_t | |
657 | 4442 ngx_http_upstream_process_charset(ngx_http_request_t *r, ngx_table_elt_t *h, |
4443 ngx_uint_t offset) | |
4444 { | |
4197
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4445 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
|
4446 return NGX_OK; |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4447 } |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4448 |
657 | 4449 r->headers_out.override_charset = &h->value; |
4450 | |
4451 return NGX_OK; | |
4452 } | |
4453 | |
4454 | |
4455 static ngx_int_t | |
4124
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4456 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
|
4457 ngx_uint_t offset) |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4458 { |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4459 r->upstream->headers_in.connection = h; |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4460 |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4461 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
|
4462 (u_char *) "close", 5 - 1) |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4463 != NULL) |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4464 { |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4465 r->upstream->headers_in.connection_close = 1; |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4466 } |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4467 |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4468 return NGX_OK; |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4469 } |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4470 |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4471 |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4472 static ngx_int_t |
4123
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4473 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
|
4474 ngx_table_elt_t *h, ngx_uint_t offset) |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4475 { |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4476 r->upstream->headers_in.transfer_encoding = h; |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4477 |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4478 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
|
4479 (u_char *) "chunked", 7 - 1) |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4480 != NULL) |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4481 { |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4482 r->upstream->headers_in.chunked = 1; |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4483 } |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4484 |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4485 return NGX_OK; |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4486 } |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4487 |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4488 |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4489 static ngx_int_t |
5877
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4490 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
|
4491 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
|
4492 { |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4493 ngx_http_upstream_t *u; |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4494 |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4495 u = r->upstream; |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4496 u->headers_in.vary = h; |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4497 |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4498 #if (NGX_HTTP_CACHE) |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4499 |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4500 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
|
4501 return NGX_OK; |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4502 } |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4503 |
5878
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5877
diff
changeset
|
4504 if (r->cache == NULL) { |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5877
diff
changeset
|
4505 return NGX_OK; |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5877
diff
changeset
|
4506 } |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5877
diff
changeset
|
4507 |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5877
diff
changeset
|
4508 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
|
4509 || (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
|
4510 { |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5877
diff
changeset
|
4511 u->cacheable = 0; |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5877
diff
changeset
|
4512 } |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5877
diff
changeset
|
4513 |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5877
diff
changeset
|
4514 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
|
4515 |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4516 #endif |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4517 |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4518 return NGX_OK; |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4519 } |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4520 |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4521 |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4522 static ngx_int_t |
509 | 4523 ngx_http_upstream_copy_header_line(ngx_http_request_t *r, ngx_table_elt_t *h, |
4524 ngx_uint_t offset) | |
4525 { | |
573 | 4526 ngx_table_elt_t *ho, **ph; |
509 | 4527 |
4528 ho = ngx_list_push(&r->headers_out.headers); | |
4529 if (ho == NULL) { | |
4530 return NGX_ERROR; | |
4531 } | |
4532 | |
4533 *ho = *h; | |
4534 | |
573 | 4535 if (offset) { |
4536 ph = (ngx_table_elt_t **) ((char *) &r->headers_out + offset); | |
4537 *ph = ho; | |
4538 } | |
4539 | |
509 | 4540 return NGX_OK; |
4541 } | |
4542 | |
4543 | |
4544 static ngx_int_t | |
4545 ngx_http_upstream_copy_multi_header_lines(ngx_http_request_t *r, | |
4546 ngx_table_elt_t *h, ngx_uint_t offset) | |
4547 { | |
4548 ngx_array_t *pa; | |
4549 ngx_table_elt_t *ho, **ph; | |
4550 | |
4551 pa = (ngx_array_t *) ((char *) &r->headers_out + offset); | |
4552 | |
4553 if (pa->elts == NULL) { | |
4554 if (ngx_array_init(pa, r->pool, 2, sizeof(ngx_table_elt_t *)) != NGX_OK) | |
4555 { | |
4556 return NGX_ERROR; | |
4557 } | |
4558 } | |
4559 | |
4560 ph = ngx_array_push(pa); | |
4561 if (ph == NULL) { | |
4562 return NGX_ERROR; | |
4563 } | |
4564 | |
4565 ho = ngx_list_push(&r->headers_out.headers); | |
4566 if (ho == NULL) { | |
4567 return NGX_ERROR; | |
4568 } | |
4569 | |
4570 *ho = *h; | |
4571 *ph = ho; | |
4572 | |
4573 return NGX_OK; | |
4574 } | |
4575 | |
4576 | |
4577 static ngx_int_t | |
4578 ngx_http_upstream_copy_content_type(ngx_http_request_t *r, ngx_table_elt_t *h, | |
4579 ngx_uint_t offset) | |
4580 { | |
657 | 4581 u_char *p, *last; |
4582 | |
4583 r->headers_out.content_type_len = h->value.len; | |
509 | 4584 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
|
4585 r->headers_out.content_type_lowcase = NULL; |
509 | 4586 |
657 | 4587 for (p = h->value.data; *p; p++) { |
4588 | |
4589 if (*p != ';') { | |
4590 continue; | |
4591 } | |
4592 | |
4593 last = p; | |
4594 | |
4595 while (*++p == ' ') { /* void */ } | |
4596 | |
1968 | 4597 if (*p == '\0') { |
4598 return NGX_OK; | |
4599 } | |
4600 | |
1107
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1098
diff
changeset
|
4601 if (ngx_strncasecmp(p, (u_char *) "charset=", 8) != 0) { |
657 | 4602 continue; |
4603 } | |
4604 | |
4605 p += 8; | |
4606 | |
4607 r->headers_out.content_type_len = last - h->value.data; | |
4608 | |
2244 | 4609 if (*p == '"') { |
4610 p++; | |
4611 } | |
4612 | |
4613 last = h->value.data + h->value.len; | |
4614 | |
4615 if (*(last - 1) == '"') { | |
4616 last--; | |
4617 } | |
4618 | |
4619 r->headers_out.charset.len = last - p; | |
657 | 4620 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
|
4621 |
c6c42497106c
fix segfault if upstream sends trailing ";" in "charset="
Igor Sysoev <igor@sysoev.ru>
parents:
1109
diff
changeset
|
4622 return NGX_OK; |
657 | 4623 } |
4624 | |
509 | 4625 return NGX_OK; |
4626 } | |
4627 | |
4628 | |
4629 static ngx_int_t | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4630 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
|
4631 ngx_uint_t offset) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4632 { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4633 ngx_table_elt_t *ho; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4634 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4635 ho = ngx_list_push(&r->headers_out.headers); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4636 if (ho == NULL) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4637 return NGX_ERROR; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4638 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4639 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4640 *ho = *h; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4641 |
3004
4121acaf7a04
fix handling "Last-Modified" and "Accept-Ranges" for upstream responses
Igor Sysoev <igor@sysoev.ru>
parents:
3003
diff
changeset
|
4642 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
|
4643 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4644 #if (NGX_HTTP_CACHE) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4645 |
2952 | 4646 if (r->upstream->cacheable) { |
5732
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
4647 r->headers_out.last_modified_time = |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
4648 r->upstream->headers_in.last_modified_time; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4649 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4650 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4651 #endif |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4652 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4653 return NGX_OK; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4654 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4655 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4656 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4657 static ngx_int_t |
509 | 4658 ngx_http_upstream_rewrite_location(ngx_http_request_t *r, ngx_table_elt_t *h, |
4659 ngx_uint_t offset) | |
4660 { | |
4661 ngx_int_t rc; | |
4662 ngx_table_elt_t *ho; | |
4663 | |
4664 ho = ngx_list_push(&r->headers_out.headers); | |
4665 if (ho == NULL) { | |
4666 return NGX_ERROR; | |
4667 } | |
4668 | |
4669 *ho = *h; | |
4670 | |
4671 if (r->upstream->rewrite_redirect) { | |
4672 rc = r->upstream->rewrite_redirect(r, ho, 0); | |
4673 | |
529 | 4674 if (rc == NGX_DECLINED) { |
4675 return NGX_OK; | |
4676 } | |
4677 | |
509 | 4678 if (rc == NGX_OK) { |
4679 r->headers_out.location = ho; | |
4680 | |
4681 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
4682 "rewritten location: \"%V\"", &ho->value); | |
4683 } | |
4684 | |
4685 return rc; | |
4686 } | |
4687 | |
1653
ea681a6a0c61
set r->headers_out.location for non-local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
4688 if (ho->value.data[0] != '/') { |
ea681a6a0c61
set r->headers_out.location for non-local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
4689 r->headers_out.location = ho; |
ea681a6a0c61
set r->headers_out.location for non-local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
4690 } |
ea681a6a0c61
set r->headers_out.location for non-local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
4691 |
509 | 4692 /* |
4693 * we do not set r->headers_out.location here to avoid the handling | |
4694 * the local redirects without a host name by ngx_http_header_filter() | |
4695 */ | |
4696 | |
4697 return NGX_OK; | |
4698 } | |
4699 | |
4700 | |
4701 static ngx_int_t | |
4702 ngx_http_upstream_rewrite_refresh(ngx_http_request_t *r, ngx_table_elt_t *h, | |
4703 ngx_uint_t offset) | |
4704 { | |
4705 u_char *p; | |
4706 ngx_int_t rc; | |
4707 ngx_table_elt_t *ho; | |
4708 | |
4709 ho = ngx_list_push(&r->headers_out.headers); | |
4710 if (ho == NULL) { | |
4711 return NGX_ERROR; | |
4712 } | |
4713 | |
4714 *ho = *h; | |
4715 | |
4716 if (r->upstream->rewrite_redirect) { | |
4717 | |
1549 | 4718 p = ngx_strcasestrn(ho->value.data, "url=", 4 - 1); |
509 | 4719 |
4720 if (p) { | |
4721 rc = r->upstream->rewrite_redirect(r, ho, p + 4 - ho->value.data); | |
4722 | |
4723 } else { | |
4724 return NGX_OK; | |
4725 } | |
4726 | |
529 | 4727 if (rc == NGX_DECLINED) { |
4728 return NGX_OK; | |
4729 } | |
4730 | |
509 | 4731 if (rc == NGX_OK) { |
1654 | 4732 r->headers_out.refresh = ho; |
4733 | |
509 | 4734 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
4735 "rewritten refresh: \"%V\"", &ho->value); | |
4736 } | |
4737 | |
4738 return rc; | |
4739 } | |
4740 | |
1654 | 4741 r->headers_out.refresh = ho; |
4742 | |
509 | 4743 return NGX_OK; |
4744 } | |
4745 | |
4746 | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4747 static ngx_int_t |
4464
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
4748 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
|
4749 ngx_uint_t offset) |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
4750 { |
4650
b38fea6f9a15
Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents:
4572
diff
changeset
|
4751 ngx_int_t rc; |
4464
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
4752 ngx_table_elt_t *ho; |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
4753 |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
4754 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
|
4755 if (ho == NULL) { |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
4756 return NGX_ERROR; |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
4757 } |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
4758 |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
4759 *ho = *h; |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
4760 |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
4761 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
|
4762 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
|
4763 |
b38fea6f9a15
Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents:
4572
diff
changeset
|
4764 if (rc == NGX_DECLINED) { |
b38fea6f9a15
Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents:
4572
diff
changeset
|
4765 return NGX_OK; |
b38fea6f9a15
Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents:
4572
diff
changeset
|
4766 } |
b38fea6f9a15
Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents:
4572
diff
changeset
|
4767 |
b38fea6f9a15
Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents:
4572
diff
changeset
|
4768 #if (NGX_DEBUG) |
b38fea6f9a15
Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents:
4572
diff
changeset
|
4769 if (rc == NGX_OK) { |
b38fea6f9a15
Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents:
4572
diff
changeset
|
4770 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
|
4771 "rewritten cookie: \"%V\"", &ho->value); |
b38fea6f9a15
Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents:
4572
diff
changeset
|
4772 } |
b38fea6f9a15
Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents:
4572
diff
changeset
|
4773 #endif |
b38fea6f9a15
Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents:
4572
diff
changeset
|
4774 |
b38fea6f9a15
Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents:
4572
diff
changeset
|
4775 return rc; |
4464
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
4776 } |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
4777 |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
4778 return NGX_OK; |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
4779 } |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
4780 |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
4781 |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
4782 static ngx_int_t |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4783 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
|
4784 ngx_table_elt_t *h, ngx_uint_t offset) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4785 { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4786 ngx_table_elt_t *ho; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4787 |
5874
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
4788 if (r->upstream->conf->force_ranges) { |
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
4789 return NGX_OK; |
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
4790 } |
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
4791 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4792 #if (NGX_HTTP_CACHE) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4793 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4794 if (r->cached) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4795 r->allow_ranges = 1; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4796 return NGX_OK; |
5621
345e4fd4bb64
Range filter: single_range flag in request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5581
diff
changeset
|
4797 } |
345e4fd4bb64
Range filter: single_range flag in request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5581
diff
changeset
|
4798 |
345e4fd4bb64
Range filter: single_range flag in request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5581
diff
changeset
|
4799 if (r->upstream->cacheable) { |
345e4fd4bb64
Range filter: single_range flag in request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5581
diff
changeset
|
4800 r->allow_ranges = 1; |
345e4fd4bb64
Range filter: single_range flag in request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5581
diff
changeset
|
4801 r->single_range = 1; |
345e4fd4bb64
Range filter: single_range flag in request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5581
diff
changeset
|
4802 return NGX_OK; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4803 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4804 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4805 #endif |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4806 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4807 ho = ngx_list_push(&r->headers_out.headers); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4808 if (ho == NULL) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4809 return NGX_ERROR; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4810 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4811 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4812 *ho = *h; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4813 |
3004
4121acaf7a04
fix handling "Last-Modified" and "Accept-Ranges" for upstream responses
Igor Sysoev <igor@sysoev.ru>
parents:
3003
diff
changeset
|
4814 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
|
4815 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4816 return NGX_OK; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4817 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4818 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4819 |
509 | 4820 #if (NGX_HTTP_GZIP) |
4821 | |
4822 static ngx_int_t | |
4823 ngx_http_upstream_copy_content_encoding(ngx_http_request_t *r, | |
4824 ngx_table_elt_t *h, ngx_uint_t offset) | |
4825 { | |
4826 ngx_table_elt_t *ho; | |
4827 | |
4828 ho = ngx_list_push(&r->headers_out.headers); | |
4829 if (ho == NULL) { | |
4830 return NGX_ERROR; | |
4831 } | |
4832 | |
4833 *ho = *h; | |
4834 | |
4835 r->headers_out.content_encoding = ho; | |
4836 | |
4837 return NGX_OK; | |
4838 } | |
4839 | |
4840 #endif | |
4841 | |
4842 | |
487 | 4843 static ngx_int_t |
573 | 4844 ngx_http_upstream_add_variables(ngx_conf_t *cf) |
479 | 4845 { |
880 | 4846 ngx_http_variable_t *var, *v; |
479 | 4847 |
573 | 4848 for (v = ngx_http_upstream_vars; v->name.len; v++) { |
4849 var = ngx_http_add_variable(cf, &v->name, v->flags); | |
4850 if (var == NULL) { | |
4851 return NGX_ERROR; | |
4852 } | |
4853 | |
637 | 4854 var->get_handler = v->get_handler; |
573 | 4855 var->data = v->data; |
4856 } | |
4857 | |
479 | 4858 return NGX_OK; |
4859 } | |
509 | 4860 |
4861 | |
573 | 4862 static ngx_int_t |
1181 | 4863 ngx_http_upstream_addr_variable(ngx_http_request_t *r, |
4864 ngx_http_variable_value_t *v, uintptr_t data) | |
4865 { | |
4866 u_char *p; | |
4867 size_t len; | |
4868 ngx_uint_t i; | |
4869 ngx_http_upstream_state_t *state; | |
4870 | |
4871 v->valid = 1; | |
1565 | 4872 v->no_cacheable = 0; |
1181 | 4873 v->not_found = 0; |
4874 | |
4875 if (r->upstream_states == NULL || r->upstream_states->nelts == 0) { | |
4876 v->not_found = 1; | |
4877 return NGX_OK; | |
4878 } | |
4879 | |
4880 len = 0; | |
4881 state = r->upstream_states->elts; | |
4882 | |
4883 for (i = 0; i < r->upstream_states->nelts; i++) { | |
4884 if (state[i].peer) { | |
4885 len += state[i].peer->len + 2; | |
4886 | |
4887 } else { | |
4888 len += 3; | |
4889 } | |
4890 } | |
4891 | |
2049 | 4892 p = ngx_pnalloc(r->pool, len); |
1181 | 4893 if (p == NULL) { |
4894 return NGX_ERROR; | |
4895 } | |
4896 | |
4897 v->data = p; | |
4898 | |
4899 i = 0; | |
4900 | |
4901 for ( ;; ) { | |
4902 if (state[i].peer) { | |
4903 p = ngx_cpymem(p, state[i].peer->data, state[i].peer->len); | |
4904 } | |
4905 | |
4906 if (++i == r->upstream_states->nelts) { | |
4907 break; | |
4908 } | |
4909 | |
4910 if (state[i].peer) { | |
4911 *p++ = ','; | |
4912 *p++ = ' '; | |
4913 | |
4914 } else { | |
4915 *p++ = ' '; | |
4916 *p++ = ':'; | |
4917 *p++ = ' '; | |
4918 | |
4919 if (++i == r->upstream_states->nelts) { | |
4920 break; | |
4921 } | |
4922 | |
4923 continue; | |
4924 } | |
4925 } | |
4926 | |
4927 v->len = p - v->data; | |
4928 | |
4929 return NGX_OK; | |
4930 } | |
4931 | |
4932 | |
4933 static ngx_int_t | |
573 | 4934 ngx_http_upstream_status_variable(ngx_http_request_t *r, |
4935 ngx_http_variable_value_t *v, uintptr_t data) | |
4936 { | |
4937 u_char *p; | |
4938 size_t len; | |
4939 ngx_uint_t i; | |
4940 ngx_http_upstream_state_t *state; | |
4941 | |
4942 v->valid = 1; | |
1565 | 4943 v->no_cacheable = 0; |
573 | 4944 v->not_found = 0; |
4945 | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
4946 if (r->upstream_states == NULL || r->upstream_states->nelts == 0) { |
573 | 4947 v->not_found = 1; |
4948 return NGX_OK; | |
4949 } | |
4950 | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
4951 len = r->upstream_states->nelts * (3 + 2); |
573 | 4952 |
2049 | 4953 p = ngx_pnalloc(r->pool, len); |
573 | 4954 if (p == NULL) { |
4955 return NGX_ERROR; | |
4956 } | |
4957 | |
4958 v->data = p; | |
4959 | |
4960 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
|
4961 state = r->upstream_states->elts; |
573 | 4962 |
4963 for ( ;; ) { | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
4964 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
|
4965 p = ngx_sprintf(p, "%ui", state[i].status); |
573 | 4966 |
4967 } else { | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
4968 *p++ = '-'; |
573 | 4969 } |
4970 | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
4971 if (++i == r->upstream_states->nelts) { |
573 | 4972 break; |
4973 } | |
4974 | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
4975 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
|
4976 *p++ = ','; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
4977 *p++ = ' '; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
4978 |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
4979 } else { |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
4980 *p++ = ' '; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
4981 *p++ = ':'; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
4982 *p++ = ' '; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
4983 |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
4984 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
|
4985 break; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
4986 } |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
4987 |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
4988 continue; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
4989 } |
573 | 4990 } |
4991 | |
4992 v->len = p - v->data; | |
4993 | |
4994 return NGX_OK; | |
4995 } | |
4996 | |
4997 | |
4998 static ngx_int_t | |
4999 ngx_http_upstream_response_time_variable(ngx_http_request_t *r, | |
5000 ngx_http_variable_value_t *v, uintptr_t data) | |
5001 { | |
5002 u_char *p; | |
5003 size_t len; | |
5004 ngx_uint_t i; | |
889
a9a7e4b1a72b
the previous fix does not actually fix overflow
Igor Sysoev <igor@sysoev.ru>
parents:
888
diff
changeset
|
5005 ngx_msec_int_t ms; |
573 | 5006 ngx_http_upstream_state_t *state; |
5007 | |
5008 v->valid = 1; | |
1565 | 5009 v->no_cacheable = 0; |
573 | 5010 v->not_found = 0; |
5011 | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5012 if (r->upstream_states == NULL || r->upstream_states->nelts == 0) { |
573 | 5013 v->not_found = 1; |
5014 return NGX_OK; | |
5015 } | |
5016 | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5017 len = r->upstream_states->nelts * (NGX_TIME_T_LEN + 4 + 2); |
573 | 5018 |
2049 | 5019 p = ngx_pnalloc(r->pool, len); |
573 | 5020 if (p == NULL) { |
5021 return NGX_ERROR; | |
5022 } | |
5023 | |
5024 v->data = p; | |
5025 | |
5026 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
|
5027 state = r->upstream_states->elts; |
573 | 5028 |
5029 for ( ;; ) { | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5030 if (state[i].status) { |
5964
0a198a517eaf
Upstream: $upstream_header_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
5960
diff
changeset
|
5031 |
6147
74b6ef56ea56
Upstream: $upstream_connect_time.
Ruslan Ermilov <ru@nginx.com>
parents:
6146
diff
changeset
|
5032 if (data == 1 && state[i].header_time != (ngx_msec_t) -1) { |
6146
59fc60585f1e
Upstream: times to obtain header/response are stored as ngx_msec_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6125
diff
changeset
|
5033 ms = state[i].header_time; |
5964
0a198a517eaf
Upstream: $upstream_header_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
5960
diff
changeset
|
5034 |
6147
74b6ef56ea56
Upstream: $upstream_connect_time.
Ruslan Ermilov <ru@nginx.com>
parents:
6146
diff
changeset
|
5035 } else if (data == 2 && state[i].connect_time != (ngx_msec_t) -1) { |
74b6ef56ea56
Upstream: $upstream_connect_time.
Ruslan Ermilov <ru@nginx.com>
parents:
6146
diff
changeset
|
5036 ms = state[i].connect_time; |
74b6ef56ea56
Upstream: $upstream_connect_time.
Ruslan Ermilov <ru@nginx.com>
parents:
6146
diff
changeset
|
5037 |
5964
0a198a517eaf
Upstream: $upstream_header_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
5960
diff
changeset
|
5038 } else { |
6146
59fc60585f1e
Upstream: times to obtain header/response are stored as ngx_msec_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6125
diff
changeset
|
5039 ms = state[i].response_time; |
5964
0a198a517eaf
Upstream: $upstream_header_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
5960
diff
changeset
|
5040 } |
0a198a517eaf
Upstream: $upstream_header_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
5960
diff
changeset
|
5041 |
3515 | 5042 ms = ngx_max(ms, 0); |
5368
cd46297325bd
Upstream: fixed $upstream_response_time format specifiers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5353
diff
changeset
|
5043 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
|
5044 |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5045 } else { |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5046 *p++ = '-'; |
573 | 5047 } |
5048 | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5049 if (++i == r->upstream_states->nelts) { |
573 | 5050 break; |
5051 } | |
5052 | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5053 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
|
5054 *p++ = ','; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5055 *p++ = ' '; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5056 |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5057 } else { |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5058 *p++ = ' '; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5059 *p++ = ':'; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5060 *p++ = ' '; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5061 |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5062 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
|
5063 break; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5064 } |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5065 |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5066 continue; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5067 } |
573 | 5068 } |
5069 | |
5070 v->len = p - v->data; | |
5071 | |
5072 return NGX_OK; | |
5073 } | |
5074 | |
5075 | |
2402 | 5076 static ngx_int_t |
5077 ngx_http_upstream_response_length_variable(ngx_http_request_t *r, | |
5078 ngx_http_variable_value_t *v, uintptr_t data) | |
5079 { | |
5080 u_char *p; | |
5081 size_t len; | |
5082 ngx_uint_t i; | |
5083 ngx_http_upstream_state_t *state; | |
5084 | |
5085 v->valid = 1; | |
5086 v->no_cacheable = 0; | |
5087 v->not_found = 0; | |
5088 | |
5089 if (r->upstream_states == NULL || r->upstream_states->nelts == 0) { | |
5090 v->not_found = 1; | |
5091 return NGX_OK; | |
5092 } | |
5093 | |
5094 len = r->upstream_states->nelts * (NGX_OFF_T_LEN + 2); | |
5095 | |
5096 p = ngx_pnalloc(r->pool, len); | |
5097 if (p == NULL) { | |
5098 return NGX_ERROR; | |
5099 } | |
5100 | |
5101 v->data = p; | |
5102 | |
5103 i = 0; | |
5104 state = r->upstream_states->elts; | |
5105 | |
5106 for ( ;; ) { | |
5107 p = ngx_sprintf(p, "%O", state[i].response_length); | |
5108 | |
5109 if (++i == r->upstream_states->nelts) { | |
5110 break; | |
5111 } | |
5112 | |
5113 if (state[i].peer) { | |
5114 *p++ = ','; | |
5115 *p++ = ' '; | |
5116 | |
5117 } else { | |
5118 *p++ = ' '; | |
5119 *p++ = ':'; | |
5120 *p++ = ' '; | |
5121 | |
5122 if (++i == r->upstream_states->nelts) { | |
5123 break; | |
5124 } | |
5125 | |
5126 continue; | |
5127 } | |
5128 } | |
5129 | |
5130 v->len = p - v->data; | |
5131 | |
5132 return NGX_OK; | |
5133 } | |
5134 | |
5135 | |
1162 | 5136 ngx_int_t |
5137 ngx_http_upstream_header_variable(ngx_http_request_t *r, | |
5138 ngx_http_variable_value_t *v, uintptr_t data) | |
5139 { | |
5140 if (r->upstream == NULL) { | |
5141 v->not_found = 1; | |
5142 return NGX_OK; | |
5143 } | |
5144 | |
5145 return ngx_http_variable_unknown_header(v, (ngx_str_t *) data, | |
5146 &r->upstream->headers_in.headers.part, | |
5147 sizeof("upstream_http_") - 1); | |
5148 } | |
5149 | |
5150 | |
5677
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5151 ngx_int_t |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5152 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
|
5153 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
|
5154 { |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5155 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
|
5156 |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5157 ngx_str_t cookie, s; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5158 |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5159 if (r->upstream == NULL) { |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5160 v->not_found = 1; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5161 return NGX_OK; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5162 } |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5163 |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5164 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
|
5165 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
|
5166 |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5167 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
|
5168 &s, &cookie) |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5169 == NGX_DECLINED) |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5170 { |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5171 v->not_found = 1; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5172 return NGX_OK; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5173 } |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5174 |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5175 v->len = cookie.len; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5176 v->valid = 1; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5177 v->no_cacheable = 0; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5178 v->not_found = 0; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5179 v->data = cookie.data; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5180 |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5181 return NGX_OK; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5182 } |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5183 |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5184 |
2952 | 5185 #if (NGX_HTTP_CACHE) |
5186 | |
5187 ngx_int_t | |
5188 ngx_http_upstream_cache_status(ngx_http_request_t *r, | |
5189 ngx_http_variable_value_t *v, uintptr_t data) | |
5190 { | |
5191 ngx_uint_t n; | |
5192 | |
5193 if (r->upstream == NULL || r->upstream->cache_status == 0) { | |
5194 v->not_found = 1; | |
5195 return NGX_OK; | |
5196 } | |
5197 | |
5198 n = r->upstream->cache_status - 1; | |
5199 | |
5200 v->valid = 1; | |
5201 v->no_cacheable = 0; | |
5202 v->not_found = 0; | |
5203 v->len = ngx_http_cache_status[n].len; | |
5204 v->data = ngx_http_cache_status[n].data; | |
5205 | |
5206 return NGX_OK; | |
5207 } | |
5208 | |
5441
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5209 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5210 static ngx_int_t |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5211 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
|
5212 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
|
5213 { |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5214 u_char *p; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5215 |
5453
b7b8e2fa7ebd
Fixed null pointer dereference with $upstream_cache_last_modified.
Ruslan Ermilov <ru@nginx.com>
parents:
5441
diff
changeset
|
5216 if (r->upstream == NULL |
b7b8e2fa7ebd
Fixed null pointer dereference with $upstream_cache_last_modified.
Ruslan Ermilov <ru@nginx.com>
parents:
5441
diff
changeset
|
5217 || !r->upstream->conf->cache_revalidate |
5441
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5218 || r->upstream->cache_status != NGX_HTTP_CACHE_EXPIRED |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5219 || r->cache->last_modified == -1) |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5220 { |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5221 v->not_found = 1; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5222 return NGX_OK; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5223 } |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5224 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5225 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
|
5226 if (p == NULL) { |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5227 return NGX_ERROR; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5228 } |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5229 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5230 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
|
5231 v->valid = 1; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5232 v->no_cacheable = 0; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5233 v->not_found = 0; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5234 v->data = p; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5235 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5236 return NGX_OK; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5237 } |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5238 |
5738
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5239 |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5240 static ngx_int_t |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5241 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
|
5242 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
|
5243 { |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5244 if (r->upstream == NULL |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5245 || !r->upstream->conf->cache_revalidate |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5246 || 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
|
5247 || r->cache->etag.len == 0) |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5248 { |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5249 v->not_found = 1; |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5250 return NGX_OK; |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5251 } |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5252 |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5253 v->valid = 1; |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5254 v->no_cacheable = 0; |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5255 v->not_found = 0; |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5256 v->len = r->cache->etag.len; |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5257 v->data = r->cache->etag.data; |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5258 |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5259 return NGX_OK; |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5260 } |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5261 |
2952 | 5262 #endif |
5263 | |
5264 | |
651 | 5265 static char * |
5266 ngx_http_upstream(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy) | |
5267 { | |
884 | 5268 char *rv; |
5269 void *mconf; | |
5270 ngx_str_t *value; | |
5271 ngx_url_t u; | |
5272 ngx_uint_t m; | |
5273 ngx_conf_t pcf; | |
5274 ngx_http_module_t *module; | |
5275 ngx_http_conf_ctx_t *ctx, *http_ctx; | |
5276 ngx_http_upstream_srv_conf_t *uscf; | |
5277 | |
5278 ngx_memzero(&u, sizeof(ngx_url_t)); | |
5279 | |
5280 value = cf->args->elts; | |
5281 u.host = value[1]; | |
5282 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
|
5283 u.no_port = 1; |
884 | 5284 |
5285 uscf = ngx_http_upstream_add(cf, &u, NGX_HTTP_UPSTREAM_CREATE | |
5286 |NGX_HTTP_UPSTREAM_WEIGHT | |
5287 |NGX_HTTP_UPSTREAM_MAX_FAILS | |
5288 |NGX_HTTP_UPSTREAM_FAIL_TIMEOUT | |
5289 |NGX_HTTP_UPSTREAM_DOWN | |
5290 |NGX_HTTP_UPSTREAM_BACKUP); | |
5291 if (uscf == NULL) { | |
5292 return NGX_CONF_ERROR; | |
5293 } | |
5294 | |
651 | 5295 |
5296 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)); | |
5297 if (ctx == NULL) { | |
5298 return NGX_CONF_ERROR; | |
5299 } | |
5300 | |
884 | 5301 http_ctx = cf->ctx; |
5302 ctx->main_conf = http_ctx->main_conf; | |
651 | 5303 |
5304 /* the upstream{}'s srv_conf */ | |
5305 | |
5306 ctx->srv_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module); | |
5307 if (ctx->srv_conf == NULL) { | |
5308 return NGX_CONF_ERROR; | |
5309 } | |
5310 | |
5311 ctx->srv_conf[ngx_http_upstream_module.ctx_index] = uscf; | |
5312 | |
884 | 5313 uscf->srv_conf = ctx->srv_conf; |
5314 | |
651 | 5315 |
5316 /* the upstream{}'s loc_conf */ | |
5317 | |
5318 ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module); | |
5319 if (ctx->loc_conf == NULL) { | |
5320 return NGX_CONF_ERROR; | |
5321 } | |
5322 | |
5323 for (m = 0; ngx_modules[m]; m++) { | |
5324 if (ngx_modules[m]->type != NGX_HTTP_MODULE) { | |
5325 continue; | |
5326 } | |
5327 | |
5328 module = ngx_modules[m]->ctx; | |
5329 | |
884 | 5330 if (module->create_srv_conf) { |
5331 mconf = module->create_srv_conf(cf); | |
5332 if (mconf == NULL) { | |
5333 return NGX_CONF_ERROR; | |
5334 } | |
5335 | |
5336 ctx->srv_conf[ngx_modules[m]->ctx_index] = mconf; | |
5337 } | |
5338 | |
651 | 5339 if (module->create_loc_conf) { |
5340 mconf = module->create_loc_conf(cf); | |
5341 if (mconf == NULL) { | |
5342 return NGX_CONF_ERROR; | |
5343 } | |
5344 | |
5345 ctx->loc_conf[ngx_modules[m]->ctx_index] = mconf; | |
5346 } | |
5347 } | |
5348 | |
5728
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5349 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
|
5350 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
|
5351 if (uscf->servers == NULL) { |
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5352 return NGX_CONF_ERROR; |
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5353 } |
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5354 |
651 | 5355 |
5356 /* parse inside upstream{} */ | |
5357 | |
5358 pcf = *cf; | |
5359 cf->ctx = ctx; | |
5360 cf->cmd_type = NGX_HTTP_UPS_CONF; | |
5361 | |
5362 rv = ngx_conf_parse(cf, NULL); | |
5363 | |
5364 *cf = pcf; | |
5365 | |
5366 if (rv != NGX_CONF_OK) { | |
5367 return rv; | |
5368 } | |
5369 | |
5728
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5370 if (uscf->servers->nelts == 0) { |
651 | 5371 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
5372 "no servers are inside upstream"); | |
5373 return NGX_CONF_ERROR; | |
5374 } | |
5375 | |
5376 return rv; | |
5377 } | |
5378 | |
5379 | |
5380 static char * | |
5381 ngx_http_upstream_server(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
5382 { | |
5383 ngx_http_upstream_srv_conf_t *uscf = conf; | |
5384 | |
884 | 5385 time_t fail_timeout; |
5386 ngx_str_t *value, s; | |
5387 ngx_url_t u; | |
5388 ngx_int_t weight, max_fails; | |
5389 ngx_uint_t i; | |
5390 ngx_http_upstream_server_t *us; | |
651 | 5391 |
884 | 5392 us = ngx_array_push(uscf->servers); |
5393 if (us == NULL) { | |
651 | 5394 return NGX_CONF_ERROR; |
5395 } | |
5396 | |
884 | 5397 ngx_memzero(us, sizeof(ngx_http_upstream_server_t)); |
5398 | |
651 | 5399 value = cf->args->elts; |
5400 | |
663 | 5401 weight = 1; |
884 | 5402 max_fails = 1; |
5403 fail_timeout = 10; | |
5404 | |
5405 for (i = 2; i < cf->args->nelts; i++) { | |
5406 | |
5407 if (ngx_strncmp(value[i].data, "weight=", 7) == 0) { | |
5408 | |
5409 if (!(uscf->flags & NGX_HTTP_UPSTREAM_WEIGHT)) { | |
5818
fe8bafab5b49
Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents:
5774
diff
changeset
|
5410 goto not_supported; |
884 | 5411 } |
5412 | |
5413 weight = ngx_atoi(&value[i].data[7], value[i].len - 7); | |
663 | 5414 |
5415 if (weight == NGX_ERROR || weight == 0) { | |
5416 goto invalid; | |
5417 } | |
5418 | |
884 | 5419 continue; |
5420 } | |
5421 | |
5422 if (ngx_strncmp(value[i].data, "max_fails=", 10) == 0) { | |
5423 | |
5424 if (!(uscf->flags & NGX_HTTP_UPSTREAM_MAX_FAILS)) { | |
5818
fe8bafab5b49
Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents:
5774
diff
changeset
|
5425 goto not_supported; |
884 | 5426 } |
5427 | |
5428 max_fails = ngx_atoi(&value[i].data[10], value[i].len - 10); | |
5429 | |
5430 if (max_fails == NGX_ERROR) { | |
5431 goto invalid; | |
5432 } | |
5433 | |
5434 continue; | |
663 | 5435 } |
884 | 5436 |
5437 if (ngx_strncmp(value[i].data, "fail_timeout=", 13) == 0) { | |
5438 | |
5439 if (!(uscf->flags & NGX_HTTP_UPSTREAM_FAIL_TIMEOUT)) { | |
5818
fe8bafab5b49
Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents:
5774
diff
changeset
|
5440 goto not_supported; |
884 | 5441 } |
5442 | |
5443 s.len = value[i].len - 13; | |
5444 s.data = &value[i].data[13]; | |
5445 | |
5446 fail_timeout = ngx_parse_time(&s, 1); | |
5447 | |
4474 | 5448 if (fail_timeout == (time_t) NGX_ERROR) { |
884 | 5449 goto invalid; |
5450 } | |
5451 | |
5452 continue; | |
5453 } | |
5454 | |
5410
16b68c724438
Upstream: fixed "down" and "backup" parsing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5392
diff
changeset
|
5455 if (ngx_strcmp(value[i].data, "backup") == 0) { |
1378 | 5456 |
5457 if (!(uscf->flags & NGX_HTTP_UPSTREAM_BACKUP)) { | |
5818
fe8bafab5b49
Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents:
5774
diff
changeset
|
5458 goto not_supported; |
1378 | 5459 } |
5460 | |
5461 us->backup = 1; | |
5462 | |
5463 continue; | |
5464 } | |
5465 | |
5410
16b68c724438
Upstream: fixed "down" and "backup" parsing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5392
diff
changeset
|
5466 if (ngx_strcmp(value[i].data, "down") == 0) { |
884 | 5467 |
5468 if (!(uscf->flags & NGX_HTTP_UPSTREAM_DOWN)) { | |
5818
fe8bafab5b49
Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents:
5774
diff
changeset
|
5469 goto not_supported; |
884 | 5470 } |
5471 | |
5472 us->down = 1; | |
5473 | |
5474 continue; | |
5475 } | |
5476 | |
5477 goto invalid; | |
663 | 5478 } |
5479 | |
5728
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5480 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
|
5481 |
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5482 u.url = value[1]; |
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5483 u.default_port = 80; |
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5484 |
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5485 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
|
5486 if (u.err) { |
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5487 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
|
5488 "%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
|
5489 } |
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5490 |
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5491 return NGX_CONF_ERROR; |
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5492 } |
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5493 |
5717
efc84a5723b3
Upstream: generic hash module.
Roman Arutyunyan <arut@nginx.com>
parents:
5682
diff
changeset
|
5494 us->name = u.url; |
884 | 5495 us->addrs = u.addrs; |
5496 us->naddrs = u.naddrs; | |
5497 us->weight = weight; | |
5498 us->max_fails = max_fails; | |
5499 us->fail_timeout = fail_timeout; | |
651 | 5500 |
5501 return NGX_CONF_OK; | |
663 | 5502 |
5503 invalid: | |
5504 | |
884 | 5505 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
5506 "invalid parameter \"%V\"", &value[i]); | |
663 | 5507 |
5508 return NGX_CONF_ERROR; | |
5818
fe8bafab5b49
Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents:
5774
diff
changeset
|
5509 |
fe8bafab5b49
Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents:
5774
diff
changeset
|
5510 not_supported: |
fe8bafab5b49
Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents:
5774
diff
changeset
|
5511 |
fe8bafab5b49
Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents:
5774
diff
changeset
|
5512 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
fe8bafab5b49
Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents:
5774
diff
changeset
|
5513 "balancing method does not support parameter \"%V\"", |
fe8bafab5b49
Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents:
5774
diff
changeset
|
5514 &value[i]); |
fe8bafab5b49
Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents:
5774
diff
changeset
|
5515 |
fe8bafab5b49
Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents:
5774
diff
changeset
|
5516 return NGX_CONF_ERROR; |
651 | 5517 } |
5518 | |
5519 | |
5520 ngx_http_upstream_srv_conf_t * | |
884 | 5521 ngx_http_upstream_add(ngx_conf_t *cf, ngx_url_t *u, ngx_uint_t flags) |
651 | 5522 { |
5523 ngx_uint_t i; | |
884 | 5524 ngx_http_upstream_server_t *us; |
651 | 5525 ngx_http_upstream_srv_conf_t *uscf, **uscfp; |
5526 ngx_http_upstream_main_conf_t *umcf; | |
5527 | |
884 | 5528 if (!(flags & NGX_HTTP_UPSTREAM_CREATE)) { |
5529 | |
1559
fe11e2a3946d
use pool instead of ngx_conf_t
Igor Sysoev <igor@sysoev.ru>
parents:
1558
diff
changeset
|
5530 if (ngx_parse_url(cf->pool, u) != NGX_OK) { |
651 | 5531 if (u->err) { |
5532 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
5533 "%s in upstream \"%V\"", u->err, &u->url); | |
5534 } | |
5535 | |
5536 return NULL; | |
5537 } | |
5538 } | |
5539 | |
5540 umcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_upstream_module); | |
5541 | |
5542 uscfp = umcf->upstreams.elts; | |
5543 | |
5544 for (i = 0; i < umcf->upstreams.nelts; i++) { | |
906 | 5545 |
5546 if (uscfp[i]->host.len != u->host.len | |
884 | 5547 || ngx_strncasecmp(uscfp[i]->host.data, u->host.data, u->host.len) |
5548 != 0) | |
5549 { | |
651 | 5550 continue; |
5551 } | |
5552 | |
884 | 5553 if ((flags & NGX_HTTP_UPSTREAM_CREATE) |
5554 && (uscfp[i]->flags & NGX_HTTP_UPSTREAM_CREATE)) | |
651 | 5555 { |
884 | 5556 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
5557 "duplicate upstream \"%V\"", &u->host); | |
5558 return NULL; | |
651 | 5559 } |
884 | 5560 |
5005
c9059bd5445b
Fixed "proxy_pass" with IP address and no port (ticket #276).
Ruslan Ermilov <ru@nginx.com>
parents:
4990
diff
changeset
|
5561 if ((uscfp[i]->flags & NGX_HTTP_UPSTREAM_CREATE) && !u->no_port) { |
884 | 5562 ngx_conf_log_error(NGX_LOG_WARN, cf, 0, |
906 | 5563 "upstream \"%V\" may not have port %d", |
5564 &u->host, u->port); | |
5565 return NULL; | |
5566 } | |
5567 | |
5005
c9059bd5445b
Fixed "proxy_pass" with IP address and no port (ticket #276).
Ruslan Ermilov <ru@nginx.com>
parents:
4990
diff
changeset
|
5568 if ((flags & NGX_HTTP_UPSTREAM_CREATE) && !uscfp[i]->no_port) { |
906 | 5569 ngx_log_error(NGX_LOG_WARN, cf->log, 0, |
5570 "upstream \"%V\" may not have port %d in %s:%ui", | |
5571 &u->host, uscfp[i]->port, | |
1489
56f1ea5baabb
u_char* is enough to keep file name
Igor Sysoev <igor@sysoev.ru>
parents:
1469
diff
changeset
|
5572 uscfp[i]->file_name, uscfp[i]->line); |
906 | 5573 return NULL; |
5574 } | |
5575 | |
5005
c9059bd5445b
Fixed "proxy_pass" with IP address and no port (ticket #276).
Ruslan Ermilov <ru@nginx.com>
parents:
4990
diff
changeset
|
5576 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
|
5577 && 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
|
5578 { |
906 | 5579 continue; |
884 | 5580 } |
5581 | |
1340 | 5582 if (uscfp[i]->default_port && u->default_port |
5583 && uscfp[i]->default_port != u->default_port) | |
5584 { | |
5585 continue; | |
5586 } | |
5587 | |
4152
65c1c241d70e
Better handling of late upstream creation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4151
diff
changeset
|
5588 if (flags & NGX_HTTP_UPSTREAM_CREATE) { |
65c1c241d70e
Better handling of late upstream creation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4151
diff
changeset
|
5589 uscfp[i]->flags = flags; |
65c1c241d70e
Better handling of late upstream creation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4151
diff
changeset
|
5590 } |
65c1c241d70e
Better handling of late upstream creation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4151
diff
changeset
|
5591 |
884 | 5592 return uscfp[i]; |
651 | 5593 } |
5594 | |
5595 uscf = ngx_pcalloc(cf->pool, sizeof(ngx_http_upstream_srv_conf_t)); | |
5596 if (uscf == NULL) { | |
5597 return NULL; | |
5598 } | |
5599 | |
884 | 5600 uscf->flags = flags; |
651 | 5601 uscf->host = u->host; |
1489
56f1ea5baabb
u_char* is enough to keep file name
Igor Sysoev <igor@sysoev.ru>
parents:
1469
diff
changeset
|
5602 uscf->file_name = cf->conf_file->file.name.data; |
651 | 5603 uscf->line = cf->conf_file->line; |
906 | 5604 uscf->port = u->port; |
5605 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
|
5606 uscf->no_port = u->no_port; |
884 | 5607 |
5977
26c127bab5ef
Upstream: detect port absence in fastcgi_pass with IP literal.
Ruslan Ermilov <ru@nginx.com>
parents:
5968
diff
changeset
|
5608 if (u->naddrs == 1 && (u->port || u->family == AF_UNIX)) { |
884 | 5609 uscf->servers = ngx_array_create(cf->pool, 1, |
5610 sizeof(ngx_http_upstream_server_t)); | |
5611 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
|
5612 return NULL; |
884 | 5613 } |
5614 | |
5615 us = ngx_array_push(uscf->servers); | |
5616 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
|
5617 return NULL; |
884 | 5618 } |
5619 | |
5620 ngx_memzero(us, sizeof(ngx_http_upstream_server_t)); | |
5621 | |
5622 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
|
5623 us->naddrs = 1; |
884 | 5624 } |
651 | 5625 |
5626 uscfp = ngx_array_push(&umcf->upstreams); | |
5627 if (uscfp == NULL) { | |
5628 return NULL; | |
5629 } | |
5630 | |
5631 *uscfp = uscf; | |
5632 | |
5633 return uscf; | |
5634 } | |
5635 | |
5636 | |
3271
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3198
diff
changeset
|
5637 char * |
3399 | 5638 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
|
5639 void *conf) |
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3198
diff
changeset
|
5640 { |
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3198
diff
changeset
|
5641 char *p = conf; |
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3198
diff
changeset
|
5642 |
5008
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5643 ngx_int_t rc; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5644 ngx_str_t *value; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5645 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
|
5646 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
|
5647 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
|
5648 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5649 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
|
5650 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5651 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
|
5652 return "is duplicate"; |
3271
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3198
diff
changeset
|
5653 } |
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3198
diff
changeset
|
5654 |
3272
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3271
diff
changeset
|
5655 value = cf->args->elts; |
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3271
diff
changeset
|
5656 |
5008
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5657 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
|
5658 *plocal = NULL; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5659 return NGX_CONF_OK; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5660 } |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5661 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5662 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
|
5663 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5664 ccv.cf = cf; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5665 ccv.value = &value[1]; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5666 ccv.complex_value = &cv; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5667 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5668 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
|
5669 return NGX_CONF_ERROR; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5670 } |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5671 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5672 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
|
5673 if (local == NULL) { |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5674 return NGX_CONF_ERROR; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5675 } |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5676 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5677 *plocal = local; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5678 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5679 if (cv.lengths) { |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5680 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
|
5681 if (local->value == NULL) { |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5682 return NGX_CONF_ERROR; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5683 } |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5684 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5685 *local->value = cv; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5686 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5687 return NGX_CONF_OK; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5688 } |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5689 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5690 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
|
5691 if (local->addr == NULL) { |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5692 return NGX_CONF_ERROR; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5693 } |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5694 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5695 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
|
5696 |
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3271
diff
changeset
|
5697 switch (rc) { |
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3271
diff
changeset
|
5698 case NGX_OK: |
5008
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5699 local->addr->name = value[1]; |
3272
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3271
diff
changeset
|
5700 return NGX_CONF_OK; |
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3271
diff
changeset
|
5701 |
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3271
diff
changeset
|
5702 case NGX_DECLINED: |
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3271
diff
changeset
|
5703 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3271
diff
changeset
|
5704 "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
|
5705 /* fall through */ |
4988fa232629
For the sake of case/switch code readability, 'fall through'
Maxim Konovalov <maxim@nginx.com>
parents:
4499
diff
changeset
|
5706 |
3272
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3271
diff
changeset
|
5707 default: |
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3271
diff
changeset
|
5708 return NGX_CONF_ERROR; |
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3271
diff
changeset
|
5709 } |
3271
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3198
diff
changeset
|
5710 } |
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3198
diff
changeset
|
5711 |
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3198
diff
changeset
|
5712 |
5008
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5713 static ngx_addr_t * |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5714 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
|
5715 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
|
5716 { |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5717 ngx_int_t rc; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5718 ngx_str_t val; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5719 ngx_addr_t *addr; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5720 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5721 if (local == NULL) { |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5722 return NULL; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5723 } |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5724 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5725 if (local->value == NULL) { |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5726 return local->addr; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5727 } |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5728 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5729 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
|
5730 return NULL; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5731 } |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5732 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5733 if (val.len == 0) { |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5734 return NULL; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5735 } |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5736 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5737 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
|
5738 if (addr == NULL) { |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5739 return NULL; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5740 } |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5741 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5742 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
|
5743 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5744 switch (rc) { |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5745 case NGX_OK: |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5746 addr->name = val; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5747 return addr; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5748 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5749 case NGX_DECLINED: |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5750 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
|
5751 "invalid local address \"%V\"", &val); |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5752 /* fall through */ |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5753 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5754 default: |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5755 return NULL; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5756 } |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5757 } |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5758 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
5759 |
4328
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5760 char * |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5761 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
|
5762 void *conf) |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5763 { |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5764 char *p = conf; |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5765 |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5766 ngx_str_t *value; |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5767 ngx_array_t **a; |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5768 ngx_http_upstream_param_t *param; |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5769 |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5770 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
|
5771 |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5772 if (*a == NULL) { |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5773 *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
|
5774 if (*a == NULL) { |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5775 return NGX_CONF_ERROR; |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5776 } |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5777 } |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5778 |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5779 param = ngx_array_push(*a); |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5780 if (param == NULL) { |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5781 return NGX_CONF_ERROR; |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5782 } |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5783 |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5784 value = cf->args->elts; |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5785 |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5786 param->key = value[1]; |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5787 param->value = value[2]; |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5788 param->skip_empty = 0; |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5789 |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5790 if (cf->args->nelts == 4) { |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5791 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
|
5792 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
|
5793 "invalid parameter \"%V\"", &value[3]); |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5794 return NGX_CONF_ERROR; |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5795 } |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5796 |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5797 param->skip_empty = 1; |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5798 } |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5799 |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5800 return NGX_CONF_OK; |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5801 } |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5802 |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
5803 |
1701
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5804 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
|
5805 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
|
5806 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
|
5807 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
|
5808 { |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5809 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
|
5810 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
|
5811 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
|
5812 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
|
5813 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5814 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
|
5815 && 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
|
5816 { |
4769
f88555d76886
Upstream: hide_headers/pass_headers inheritance fix.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4766
diff
changeset
|
5817 conf->hide_headers = prev->hide_headers; |
f88555d76886
Upstream: hide_headers/pass_headers inheritance fix.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4766
diff
changeset
|
5818 conf->pass_headers = prev->pass_headers; |
f88555d76886
Upstream: hide_headers/pass_headers inheritance fix.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4766
diff
changeset
|
5819 |
1701
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5820 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
|
5821 |
2929
37b7cd336fdf
inherit proxy_set_header, proxy_hide_header, and fastcgi_hide_header
Igor Sysoev <igor@sysoev.ru>
parents:
2927
diff
changeset
|
5822 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
|
5823 #if (NGX_HTTP_CACHE) |
5949
634da79665d3
Upstream: refactored proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5947
diff
changeset
|
5824 && ((conf->cache == 0) == (prev->cache == 0)) |
2949
fe484c0be7c0
fix building --without-http-cache, broken in r2930
Igor Sysoev <igor@sysoev.ru>
parents:
2929
diff
changeset
|
5825 #endif |
fe484c0be7c0
fix building --without-http-cache, broken in r2930
Igor Sysoev <igor@sysoev.ru>
parents:
2929
diff
changeset
|
5826 ) |
2929
37b7cd336fdf
inherit proxy_set_header, proxy_hide_header, and fastcgi_hide_header
Igor Sysoev <igor@sysoev.ru>
parents:
2927
diff
changeset
|
5827 { |
1701
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5828 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
|
5829 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5830 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5831 } else { |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5832 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
|
5833 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
|
5834 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5835 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5836 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
|
5837 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
|
5838 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5839 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5840 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5841 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
|
5842 != NGX_OK) |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5843 { |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5844 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
|
5845 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5846 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5847 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
|
5848 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
|
5849 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
|
5850 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
|
5851 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5852 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5853 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
|
5854 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
|
5855 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
|
5856 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5857 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5858 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
|
5859 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5860 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
|
5861 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5862 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
|
5863 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5864 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
|
5865 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5866 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
|
5867 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
|
5868 goto exist; |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5869 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5870 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5871 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5872 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
|
5873 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
|
5874 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
|
5875 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5876 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5877 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
|
5878 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
|
5879 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
|
5880 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5881 exist: |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5882 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5883 continue; |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5884 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5885 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5886 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5887 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
|
5888 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5889 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
|
5890 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
|
5891 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5892 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
|
5893 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
|
5894 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5895 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
|
5896 continue; |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5897 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5898 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5899 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
|
5900 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
|
5901 break; |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5902 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5903 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5904 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5905 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5906 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5907 hash->hash = &conf->hide_headers_hash; |
1706
9242e21d2f8d
style fix: remove trailing spaces
Igor Sysoev <igor@sysoev.ru>
parents:
1705
diff
changeset
|
5908 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
|
5909 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
|
5910 hash->temp_pool = NULL; |
1706
9242e21d2f8d
style fix: remove trailing spaces
Igor Sysoev <igor@sysoev.ru>
parents:
1705
diff
changeset
|
5911 |
1701
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5912 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
|
5913 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5914 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
5915 |
509 | 5916 static void * |
5917 ngx_http_upstream_create_main_conf(ngx_conf_t *cf) | |
5918 { | |
5919 ngx_http_upstream_main_conf_t *umcf; | |
5920 | |
5921 umcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_upstream_main_conf_t)); | |
5922 if (umcf == NULL) { | |
5923 return NULL; | |
5924 } | |
5925 | |
651 | 5926 if (ngx_array_init(&umcf->upstreams, cf->pool, 4, |
5927 sizeof(ngx_http_upstream_srv_conf_t *)) | |
5928 != NGX_OK) | |
5929 { | |
2912
c7d57b539248
return NULL instead of NGX_CONF_ERROR on a create conf failure
Igor Sysoev <igor@sysoev.ru>
parents:
2882
diff
changeset
|
5930 return NULL; |
651 | 5931 } |
5932 | |
509 | 5933 return umcf; |
5934 } | |
5935 | |
5936 | |
5937 static char * | |
651 | 5938 ngx_http_upstream_init_main_conf(ngx_conf_t *cf, void *conf) |
509 | 5939 { |
5940 ngx_http_upstream_main_conf_t *umcf = conf; | |
5941 | |
651 | 5942 ngx_uint_t i; |
5943 ngx_array_t headers_in; | |
5944 ngx_hash_key_t *hk; | |
5945 ngx_hash_init_t hash; | |
884 | 5946 ngx_http_upstream_init_pt init; |
651 | 5947 ngx_http_upstream_header_t *header; |
5948 ngx_http_upstream_srv_conf_t **uscfp; | |
5949 | |
5950 uscfp = umcf->upstreams.elts; | |
5951 | |
5952 for (i = 0; i < umcf->upstreams.nelts; i++) { | |
884 | 5953 |
5954 init = uscfp[i]->peer.init_upstream ? uscfp[i]->peer.init_upstream: | |
5955 ngx_http_upstream_init_round_robin; | |
5956 | |
5957 if (init(cf, uscfp[i]) != NGX_OK) { | |
651 | 5958 return NGX_CONF_ERROR; |
5959 } | |
5960 } | |
649 | 5961 |
663 | 5962 |
884 | 5963 /* upstream_headers_in_hash */ |
5964 | |
649 | 5965 if (ngx_array_init(&headers_in, cf->temp_pool, 32, sizeof(ngx_hash_key_t)) |
5966 != NGX_OK) | |
509 | 5967 { |
5968 return NGX_CONF_ERROR; | |
5969 } | |
5970 | |
649 | 5971 for (header = ngx_http_upstream_headers_in; header->name.len; header++) { |
5972 hk = ngx_array_push(&headers_in); | |
5973 if (hk == NULL) { | |
5974 return NGX_CONF_ERROR; | |
5975 } | |
5976 | |
5977 hk->key = header->name; | |
5978 hk->key_hash = ngx_hash_key_lc(header->name.data, header->name.len); | |
5979 hk->value = header; | |
5980 } | |
5981 | |
5982 hash.hash = &umcf->headers_in_hash; | |
5983 hash.key = ngx_hash_key_lc; | |
5984 hash.max_size = 512; | |
751
bae59a740c40
align hash bucket size to cache line
Igor Sysoev <igor@sysoev.ru>
parents:
750
diff
changeset
|
5985 hash.bucket_size = ngx_align(64, ngx_cacheline_size); |
649 | 5986 hash.name = "upstream_headers_in_hash"; |
5987 hash.pool = cf->pool; | |
5988 hash.temp_pool = NULL; | |
5989 | |
5990 if (ngx_hash_init(&hash, headers_in.elts, headers_in.nelts) != NGX_OK) { | |
5991 return NGX_CONF_ERROR; | |
5992 } | |
509 | 5993 |
5994 return NGX_CONF_OK; | |
5995 } |