Mercurial > hg > nginx-quic
annotate src/http/ngx_http_upstream.c @ 8383:385d511b5064 quic
QUIC: fixed udp buffer initialization.
The start field is used to check if the QUIC packet is first in the datagram.
This fixes stateless reset detection.
author | Vladimir Homutov <vl@nginx.com> |
---|---|
date | Tue, 30 Mar 2021 14:33:43 +0300 |
parents | f1986657fc26 |
children | d514f88053e5 |
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); |
6906
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
20 static ngx_int_t ngx_http_upstream_cache_background_update( |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
21 ngx_http_request_t *r, ngx_http_upstream_t *u); |
6793
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
22 static ngx_int_t ngx_http_upstream_cache_check_range(ngx_http_request_t *r, |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
23 ngx_http_upstream_t *u); |
2952 | 24 static ngx_int_t ngx_http_upstream_cache_status(ngx_http_request_t *r, |
25 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
|
26 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
|
27 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
|
28 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
|
29 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
|
30 #endif |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
31 |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
32 static void ngx_http_upstream_init_request(ngx_http_request_t *r); |
1658 | 33 static void ngx_http_upstream_resolve_handler(ngx_resolver_ctx_t *ctx); |
509 | 34 static void ngx_http_upstream_rd_check_broken_connection(ngx_http_request_t *r); |
35 static void ngx_http_upstream_wr_check_broken_connection(ngx_http_request_t *r); | |
36 static void ngx_http_upstream_check_broken_connection(ngx_http_request_t *r, | |
37 ngx_event_t *ev); | |
479 | 38 static void ngx_http_upstream_connect(ngx_http_request_t *r, |
487 | 39 ngx_http_upstream_t *u); |
509 | 40 static ngx_int_t ngx_http_upstream_reinit(ngx_http_request_t *r, |
487 | 41 ngx_http_upstream_t *u); |
479 | 42 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
|
43 ngx_http_upstream_t *u, ngx_uint_t do_write); |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
44 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
|
45 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
|
46 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
|
47 ngx_http_upstream_t *u); |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
48 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
|
49 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
|
50 ngx_http_upstream_t *u); |
2268
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
51 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
|
52 ngx_http_upstream_t *u); |
2267
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
53 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
|
54 ngx_http_upstream_t *u); |
1153
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
55 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
|
56 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
|
57 ngx_http_upstream_t *u); |
7230
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
58 static ngx_int_t ngx_http_upstream_process_trailers(ngx_http_request_t *r, |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
59 ngx_http_upstream_t *u); |
479 | 60 static void ngx_http_upstream_send_response(ngx_http_request_t *r, |
487 | 61 ngx_http_upstream_t *u); |
5072
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
62 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
|
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_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
|
65 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
|
66 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
|
67 ngx_http_upstream_t *u); |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
68 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
|
69 ngx_http_upstream_t *u); |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
70 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
|
71 ngx_uint_t from_upstream, ngx_uint_t do_write); |
581 | 72 static void |
73 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
|
74 static void |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
75 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
|
76 ngx_http_upstream_t *u); |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
77 static void |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
78 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
|
79 ngx_uint_t do_write); |
6443
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
80 #if (NGX_THREADS) |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
81 static ngx_int_t ngx_http_upstream_thread_handler(ngx_thread_task_t *task, |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
82 ngx_file_t *file); |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
83 static void ngx_http_upstream_thread_event_handler(ngx_event_t *ev); |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
84 #endif |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
85 static ngx_int_t ngx_http_upstream_output_filter(void *data, |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
86 ngx_chain_t *chain); |
509 | 87 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
|
88 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
|
89 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
|
90 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
|
91 ngx_http_upstream_t *u); |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
92 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
|
93 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
|
94 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
|
95 ngx_http_upstream_t *u); |
479 | 96 static void ngx_http_upstream_next(ngx_http_request_t *r, |
487 | 97 ngx_http_upstream_t *u, ngx_uint_t ft_type); |
569 | 98 static void ngx_http_upstream_cleanup(void *data); |
479 | 99 static void ngx_http_upstream_finalize_request(ngx_http_request_t *r, |
487 | 100 ngx_http_upstream_t *u, ngx_int_t rc); |
479 | 101 |
509 | 102 static ngx_int_t ngx_http_upstream_process_header_line(ngx_http_request_t *r, |
103 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
|
104 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
|
105 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
|
106 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
|
107 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
|
108 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
|
109 ngx_table_elt_t *h, ngx_uint_t offset); |
509 | 110 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
|
111 ngx_http_upstream_process_cache_control(ngx_http_request_t *r, |
509 | 112 ngx_table_elt_t *h, ngx_uint_t offset); |
113 static ngx_int_t ngx_http_upstream_ignore_header_line(ngx_http_request_t *r, | |
114 ngx_table_elt_t *h, ngx_uint_t offset); | |
2666 | 115 static ngx_int_t ngx_http_upstream_process_expires(ngx_http_request_t *r, |
116 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
|
117 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
|
118 ngx_table_elt_t *h, ngx_uint_t offset); |
527 | 119 static ngx_int_t ngx_http_upstream_process_limit_rate(ngx_http_request_t *r, |
120 ngx_table_elt_t *h, ngx_uint_t offset); | |
649 | 121 static ngx_int_t ngx_http_upstream_process_buffering(ngx_http_request_t *r, |
509 | 122 ngx_table_elt_t *h, ngx_uint_t offset); |
657 | 123 static ngx_int_t ngx_http_upstream_process_charset(ngx_http_request_t *r, |
124 ngx_table_elt_t *h, ngx_uint_t offset); | |
4124
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
125 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
|
126 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
|
127 static ngx_int_t |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
128 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
|
129 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
|
130 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
|
131 ngx_table_elt_t *h, ngx_uint_t offset); |
649 | 132 static ngx_int_t ngx_http_upstream_copy_header_line(ngx_http_request_t *r, |
509 | 133 ngx_table_elt_t *h, ngx_uint_t offset); |
134 static ngx_int_t | |
135 ngx_http_upstream_copy_multi_header_lines(ngx_http_request_t *r, | |
136 ngx_table_elt_t *h, ngx_uint_t offset); | |
137 static ngx_int_t ngx_http_upstream_copy_content_type(ngx_http_request_t *r, | |
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_last_modified(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); |
509 | 141 static ngx_int_t ngx_http_upstream_rewrite_location(ngx_http_request_t *r, |
142 ngx_table_elt_t *h, ngx_uint_t offset); | |
143 static ngx_int_t ngx_http_upstream_rewrite_refresh(ngx_http_request_t *r, | |
144 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
|
145 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
|
146 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
|
147 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
|
148 ngx_table_elt_t *h, ngx_uint_t offset); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
149 |
509 | 150 #if (NGX_HTTP_GZIP) |
151 static ngx_int_t ngx_http_upstream_copy_content_encoding(ngx_http_request_t *r, | |
152 ngx_table_elt_t *h, ngx_uint_t offset); | |
153 #endif | |
154 | |
573 | 155 static ngx_int_t ngx_http_upstream_add_variables(ngx_conf_t *cf); |
1181 | 156 static ngx_int_t ngx_http_upstream_addr_variable(ngx_http_request_t *r, |
157 ngx_http_variable_value_t *v, uintptr_t data); | |
573 | 158 static ngx_int_t ngx_http_upstream_status_variable(ngx_http_request_t *r, |
159 ngx_http_variable_value_t *v, uintptr_t data); | |
160 static ngx_int_t ngx_http_upstream_response_time_variable(ngx_http_request_t *r, | |
161 ngx_http_variable_value_t *v, uintptr_t data); | |
2402 | 162 static ngx_int_t ngx_http_upstream_response_length_variable( |
163 ngx_http_request_t *r, ngx_http_variable_value_t *v, uintptr_t data); | |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6876
diff
changeset
|
164 static ngx_int_t ngx_http_upstream_header_variable(ngx_http_request_t *r, |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6876
diff
changeset
|
165 ngx_http_variable_value_t *v, uintptr_t data); |
7230
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
166 static ngx_int_t ngx_http_upstream_trailer_variable(ngx_http_request_t *r, |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
167 ngx_http_variable_value_t *v, uintptr_t data); |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6876
diff
changeset
|
168 static ngx_int_t ngx_http_upstream_cookie_variable(ngx_http_request_t *r, |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6876
diff
changeset
|
169 ngx_http_variable_value_t *v, uintptr_t data); |
573 | 170 |
651 | 171 static char *ngx_http_upstream(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy); |
172 static char *ngx_http_upstream_server(ngx_conf_t *cf, ngx_command_t *cmd, | |
173 void *conf); | |
174 | |
6528
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
175 static ngx_int_t ngx_http_upstream_set_local(ngx_http_request_t *r, |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
176 ngx_http_upstream_t *u, ngx_http_upstream_local_t *local); |
5008
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
177 |
509 | 178 static void *ngx_http_upstream_create_main_conf(ngx_conf_t *cf); |
651 | 179 static char *ngx_http_upstream_init_main_conf(ngx_conf_t *cf, void *conf); |
509 | 180 |
577 | 181 #if (NGX_HTTP_SSL) |
591 | 182 static void ngx_http_upstream_ssl_init_connection(ngx_http_request_t *, |
183 ngx_http_upstream_t *u, ngx_connection_t *c); | |
7042
bd2f97a3aecc
Upstream: introduced ngx_http_upstream_ssl_handshake_handler().
Maxim Dounin <mdounin@mdounin.ru>
parents:
7041
diff
changeset
|
184 static void ngx_http_upstream_ssl_handshake_handler(ngx_connection_t *c); |
bd2f97a3aecc
Upstream: introduced ngx_http_upstream_ssl_handshake_handler().
Maxim Dounin <mdounin@mdounin.ru>
parents:
7041
diff
changeset
|
185 static void ngx_http_upstream_ssl_handshake(ngx_http_request_t *, |
bd2f97a3aecc
Upstream: introduced ngx_http_upstream_ssl_handshake_handler().
Maxim Dounin <mdounin@mdounin.ru>
parents:
7041
diff
changeset
|
186 ngx_http_upstream_t *u, ngx_connection_t *c); |
7320
696df3ac27ac
SSL: save sessions for upstream peers using a callback function.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7307
diff
changeset
|
187 static void ngx_http_upstream_ssl_save_session(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
|
188 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
|
189 ngx_http_upstream_t *u, ngx_connection_t *c); |
577 | 190 #endif |
191 | |
509 | 192 |
6922
a72886067bbb
Added missing static specifiers.
Eran Kornblau <erankor@gmail.com>
parents:
6909
diff
changeset
|
193 static ngx_http_upstream_header_t ngx_http_upstream_headers_in[] = { |
509 | 194 |
195 { ngx_string("Status"), | |
196 ngx_http_upstream_process_header_line, | |
197 offsetof(ngx_http_upstream_headers_in_t, status), | |
649 | 198 ngx_http_upstream_copy_header_line, 0, 0 }, |
509 | 199 |
200 { ngx_string("Content-Type"), | |
201 ngx_http_upstream_process_header_line, | |
202 offsetof(ngx_http_upstream_headers_in_t, content_type), | |
673 | 203 ngx_http_upstream_copy_content_type, 0, 1 }, |
509 | 204 |
205 { ngx_string("Content-Length"), | |
5731
02674312be45
Upstream: removed unused offset to content_length.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5730
diff
changeset
|
206 ngx_http_upstream_process_content_length, 0, |
4117
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
207 ngx_http_upstream_ignore_header_line, 0, 0 }, |
509 | 208 |
209 { ngx_string("Date"), | |
210 ngx_http_upstream_process_header_line, | |
211 offsetof(ngx_http_upstream_headers_in_t, date), | |
649 | 212 ngx_http_upstream_copy_header_line, |
213 offsetof(ngx_http_headers_out_t, date), 0 }, | |
509 | 214 |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
215 { ngx_string("Last-Modified"), |
5732
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
216 ngx_http_upstream_process_last_modified, 0, |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
217 ngx_http_upstream_copy_last_modified, 0, 0 }, |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
218 |
3037 | 219 { ngx_string("ETag"), |
220 ngx_http_upstream_process_header_line, | |
221 offsetof(ngx_http_upstream_headers_in_t, etag), | |
222 ngx_http_upstream_copy_header_line, | |
223 offsetof(ngx_http_headers_out_t, etag), 0 }, | |
224 | |
509 | 225 { ngx_string("Server"), |
226 ngx_http_upstream_process_header_line, | |
227 offsetof(ngx_http_upstream_headers_in_t, server), | |
649 | 228 ngx_http_upstream_copy_header_line, |
229 offsetof(ngx_http_headers_out_t, server), 0 }, | |
509 | 230 |
529 | 231 { ngx_string("WWW-Authenticate"), |
232 ngx_http_upstream_process_header_line, | |
233 offsetof(ngx_http_upstream_headers_in_t, www_authenticate), | |
234 ngx_http_upstream_copy_header_line, 0, 0 }, | |
235 | |
509 | 236 { ngx_string("Location"), |
2140
dce5ddef5af9
if upstream sent a location header without status use 302
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
237 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
|
238 offsetof(ngx_http_upstream_headers_in_t, location), |
515 | 239 ngx_http_upstream_rewrite_location, 0, 0 }, |
509 | 240 |
241 { ngx_string("Refresh"), | |
242 ngx_http_upstream_ignore_header_line, 0, | |
515 | 243 ngx_http_upstream_rewrite_refresh, 0, 0 }, |
244 | |
245 { ngx_string("Set-Cookie"), | |
5677
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
246 ngx_http_upstream_process_set_cookie, |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
247 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
|
248 ngx_http_upstream_rewrite_set_cookie, 0, 1 }, |
531 | 249 |
250 { ngx_string("Content-Disposition"), | |
251 ngx_http_upstream_ignore_header_line, 0, | |
252 ngx_http_upstream_copy_header_line, 0, 1 }, | |
509 | 253 |
254 { 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
|
255 ngx_http_upstream_process_cache_control, 0, |
509 | 256 ngx_http_upstream_copy_multi_header_lines, |
515 | 257 offsetof(ngx_http_headers_out_t, cache_control), 1 }, |
509 | 258 |
573 | 259 { ngx_string("Expires"), |
2666 | 260 ngx_http_upstream_process_expires, 0, |
573 | 261 ngx_http_upstream_copy_header_line, |
262 offsetof(ngx_http_headers_out_t, expires), 1 }, | |
263 | |
577 | 264 { ngx_string("Accept-Ranges"), |
265 ngx_http_upstream_process_header_line, | |
266 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
|
267 ngx_http_upstream_copy_allow_ranges, |
577 | 268 offsetof(ngx_http_headers_out_t, accept_ranges), 1 }, |
269 | |
6316
f44de0d12143
Upstream: fill r->headers_out.content_range from upstream response.
Roman Arutyunyan <arut@nginx.com>
parents:
6313
diff
changeset
|
270 { ngx_string("Content-Range"), |
f44de0d12143
Upstream: fill r->headers_out.content_range from upstream response.
Roman Arutyunyan <arut@nginx.com>
parents:
6313
diff
changeset
|
271 ngx_http_upstream_ignore_header_line, 0, |
f44de0d12143
Upstream: fill r->headers_out.content_range from upstream response.
Roman Arutyunyan <arut@nginx.com>
parents:
6313
diff
changeset
|
272 ngx_http_upstream_copy_header_line, |
f44de0d12143
Upstream: fill r->headers_out.content_range from upstream response.
Roman Arutyunyan <arut@nginx.com>
parents:
6313
diff
changeset
|
273 offsetof(ngx_http_headers_out_t, content_range), 0 }, |
f44de0d12143
Upstream: fill r->headers_out.content_range from upstream response.
Roman Arutyunyan <arut@nginx.com>
parents:
6313
diff
changeset
|
274 |
509 | 275 { ngx_string("Connection"), |
4124
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
276 ngx_http_upstream_process_connection, 0, |
515 | 277 ngx_http_upstream_ignore_header_line, 0, 0 }, |
509 | 278 |
641 | 279 { ngx_string("Keep-Alive"), |
280 ngx_http_upstream_ignore_header_line, 0, | |
281 ngx_http_upstream_ignore_header_line, 0, 0 }, | |
282 | |
5877
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
283 { ngx_string("Vary"), |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
284 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
|
285 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
|
286 |
7199
6ba68ad8b24c
Basic support of the Link response header.
Ruslan Ermilov <ru@nginx.com>
parents:
7194
diff
changeset
|
287 { ngx_string("Link"), |
6ba68ad8b24c
Basic support of the Link response header.
Ruslan Ermilov <ru@nginx.com>
parents:
7194
diff
changeset
|
288 ngx_http_upstream_ignore_header_line, 0, |
6ba68ad8b24c
Basic support of the Link response header.
Ruslan Ermilov <ru@nginx.com>
parents:
7194
diff
changeset
|
289 ngx_http_upstream_copy_multi_header_lines, |
6ba68ad8b24c
Basic support of the Link response header.
Ruslan Ermilov <ru@nginx.com>
parents:
7194
diff
changeset
|
290 offsetof(ngx_http_headers_out_t, link), 0 }, |
6ba68ad8b24c
Basic support of the Link response header.
Ruslan Ermilov <ru@nginx.com>
parents:
7194
diff
changeset
|
291 |
509 | 292 { ngx_string("X-Accel-Expires"), |
2664 | 293 ngx_http_upstream_process_accel_expires, 0, |
649 | 294 ngx_http_upstream_copy_header_line, 0, 0 }, |
515 | 295 |
296 { ngx_string("X-Accel-Redirect"), | |
297 ngx_http_upstream_process_header_line, | |
298 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
|
299 ngx_http_upstream_copy_header_line, 0, 0 }, |
509 | 300 |
527 | 301 { ngx_string("X-Accel-Limit-Rate"), |
302 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
|
303 ngx_http_upstream_copy_header_line, 0, 0 }, |
527 | 304 |
649 | 305 { ngx_string("X-Accel-Buffering"), |
306 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
|
307 ngx_http_upstream_copy_header_line, 0, 0 }, |
649 | 308 |
657 | 309 { ngx_string("X-Accel-Charset"), |
310 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
|
311 ngx_http_upstream_copy_header_line, 0, 0 }, |
657 | 312 |
4123
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
313 { ngx_string("Transfer-Encoding"), |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
314 ngx_http_upstream_process_transfer_encoding, 0, |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
315 ngx_http_upstream_ignore_header_line, 0, 0 }, |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
316 |
509 | 317 #if (NGX_HTTP_GZIP) |
318 { ngx_string("Content-Encoding"), | |
319 ngx_http_upstream_process_header_line, | |
320 offsetof(ngx_http_upstream_headers_in_t, content_encoding), | |
515 | 321 ngx_http_upstream_copy_content_encoding, 0, 0 }, |
509 | 322 #endif |
323 | |
515 | 324 { ngx_null_string, NULL, 0, NULL, 0, 0 } |
509 | 325 }; |
479 | 326 |
327 | |
651 | 328 static ngx_command_t ngx_http_upstream_commands[] = { |
329 | |
330 { ngx_string("upstream"), | |
331 NGX_HTTP_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_TAKE1, | |
332 ngx_http_upstream, | |
333 0, | |
334 0, | |
335 NULL }, | |
336 | |
337 { ngx_string("server"), | |
884 | 338 NGX_HTTP_UPS_CONF|NGX_CONF_1MORE, |
651 | 339 ngx_http_upstream_server, |
340 NGX_HTTP_SRV_CONF_OFFSET, | |
341 0, | |
342 NULL }, | |
343 | |
344 ngx_null_command | |
345 }; | |
346 | |
347 | |
348 static ngx_http_module_t ngx_http_upstream_module_ctx = { | |
573 | 349 ngx_http_upstream_add_variables, /* preconfiguration */ |
509 | 350 NULL, /* postconfiguration */ |
351 | |
352 ngx_http_upstream_create_main_conf, /* create main configuration */ | |
651 | 353 ngx_http_upstream_init_main_conf, /* init main configuration */ |
479 | 354 |
355 NULL, /* create server configuration */ | |
356 NULL, /* merge server configuration */ | |
357 | |
358 NULL, /* create location configuration */ | |
359 NULL /* merge location configuration */ | |
360 }; | |
577 | 361 |
479 | 362 |
363 ngx_module_t ngx_http_upstream_module = { | |
509 | 364 NGX_MODULE_V1, |
479 | 365 &ngx_http_upstream_module_ctx, /* module context */ |
651 | 366 ngx_http_upstream_commands, /* module directives */ |
479 | 367 NGX_HTTP_MODULE, /* module type */ |
541 | 368 NULL, /* init master */ |
479 | 369 NULL, /* init module */ |
541 | 370 NULL, /* init process */ |
371 NULL, /* init thread */ | |
372 NULL, /* exit thread */ | |
373 NULL, /* exit process */ | |
374 NULL, /* exit master */ | |
375 NGX_MODULE_V1_PADDING | |
479 | 376 }; |
377 | |
378 | |
573 | 379 static ngx_http_variable_t ngx_http_upstream_vars[] = { |
380 | |
1181 | 381 { 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
|
382 ngx_http_upstream_addr_variable, 0, |
3898
bd1222fb0192
allow to use $upstream_... variables in SSI
Igor Sysoev <igor@sysoev.ru>
parents:
3879
diff
changeset
|
383 NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
1181 | 384 |
637 | 385 { 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
|
386 ngx_http_upstream_status_variable, 0, |
3898
bd1222fb0192
allow to use $upstream_... variables in SSI
Igor Sysoev <igor@sysoev.ru>
parents:
3879
diff
changeset
|
387 NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
573 | 388 |
6147
74b6ef56ea56
Upstream: $upstream_connect_time.
Ruslan Ermilov <ru@nginx.com>
parents:
6146
diff
changeset
|
389 { ngx_string("upstream_connect_time"), NULL, |
74b6ef56ea56
Upstream: $upstream_connect_time.
Ruslan Ermilov <ru@nginx.com>
parents:
6146
diff
changeset
|
390 ngx_http_upstream_response_time_variable, 2, |
74b6ef56ea56
Upstream: $upstream_connect_time.
Ruslan Ermilov <ru@nginx.com>
parents:
6146
diff
changeset
|
391 NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
74b6ef56ea56
Upstream: $upstream_connect_time.
Ruslan Ermilov <ru@nginx.com>
parents:
6146
diff
changeset
|
392 |
5964
0a198a517eaf
Upstream: $upstream_header_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
5960
diff
changeset
|
393 { ngx_string("upstream_header_time"), NULL, |
0a198a517eaf
Upstream: $upstream_header_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
5960
diff
changeset
|
394 ngx_http_upstream_response_time_variable, 1, |
0a198a517eaf
Upstream: $upstream_header_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
5960
diff
changeset
|
395 NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
0a198a517eaf
Upstream: $upstream_header_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
5960
diff
changeset
|
396 |
637 | 397 { 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
|
398 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
|
399 NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
573 | 400 |
2402 | 401 { ngx_string("upstream_response_length"), NULL, |
402 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
|
403 NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
2402 | 404 |
6654
c131f20c9562
Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6594
diff
changeset
|
405 { ngx_string("upstream_bytes_received"), NULL, |
c131f20c9562
Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6594
diff
changeset
|
406 ngx_http_upstream_response_length_variable, 1, |
c131f20c9562
Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6594
diff
changeset
|
407 NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
c131f20c9562
Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6594
diff
changeset
|
408 |
7429
e573d74299a0
Upstream: implemented $upstream_bytes_sent.
Ruslan Ermilov <ru@nginx.com>
parents:
7397
diff
changeset
|
409 { ngx_string("upstream_bytes_sent"), NULL, |
e573d74299a0
Upstream: implemented $upstream_bytes_sent.
Ruslan Ermilov <ru@nginx.com>
parents:
7397
diff
changeset
|
410 ngx_http_upstream_response_length_variable, 2, |
e573d74299a0
Upstream: implemented $upstream_bytes_sent.
Ruslan Ermilov <ru@nginx.com>
parents:
7397
diff
changeset
|
411 NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
e573d74299a0
Upstream: implemented $upstream_bytes_sent.
Ruslan Ermilov <ru@nginx.com>
parents:
7397
diff
changeset
|
412 |
2957
b4f39842523b
fix building --without-http-cache, broken in r2953
Igor Sysoev <igor@sysoev.ru>
parents:
2953
diff
changeset
|
413 #if (NGX_HTTP_CACHE) |
b4f39842523b
fix building --without-http-cache, broken in r2953
Igor Sysoev <igor@sysoev.ru>
parents:
2953
diff
changeset
|
414 |
2952 | 415 { ngx_string("upstream_cache_status"), NULL, |
416 ngx_http_upstream_cache_status, 0, | |
3898
bd1222fb0192
allow to use $upstream_... variables in SSI
Igor Sysoev <igor@sysoev.ru>
parents:
3879
diff
changeset
|
417 NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
2952 | 418 |
5441
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
419 { ngx_string("upstream_cache_last_modified"), NULL, |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
420 ngx_http_upstream_cache_last_modified, 0, |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
421 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
|
422 |
5738
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
423 { ngx_string("upstream_cache_etag"), NULL, |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
424 ngx_http_upstream_cache_etag, 0, |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
425 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
|
426 |
2957
b4f39842523b
fix building --without-http-cache, broken in r2953
Igor Sysoev <igor@sysoev.ru>
parents:
2953
diff
changeset
|
427 #endif |
b4f39842523b
fix building --without-http-cache, broken in r2953
Igor Sysoev <igor@sysoev.ru>
parents:
2953
diff
changeset
|
428 |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6876
diff
changeset
|
429 { ngx_string("upstream_http_"), NULL, ngx_http_upstream_header_variable, |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6876
diff
changeset
|
430 0, NGX_HTTP_VAR_NOCACHEABLE|NGX_HTTP_VAR_PREFIX, 0 }, |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6876
diff
changeset
|
431 |
7230
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
432 { ngx_string("upstream_trailer_"), NULL, ngx_http_upstream_trailer_variable, |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
433 0, NGX_HTTP_VAR_NOCACHEABLE|NGX_HTTP_VAR_PREFIX, 0 }, |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
434 |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6876
diff
changeset
|
435 { ngx_string("upstream_cookie_"), NULL, ngx_http_upstream_cookie_variable, |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6876
diff
changeset
|
436 0, NGX_HTTP_VAR_NOCACHEABLE|NGX_HTTP_VAR_PREFIX, 0 }, |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6876
diff
changeset
|
437 |
7077
2a288909abc6
Variables: macros for null variables.
Ruslan Ermilov <ru@nginx.com>
parents:
7070
diff
changeset
|
438 ngx_http_null_variable |
573 | 439 }; |
440 | |
441 | |
2268
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
442 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
|
443 { 500, NGX_HTTP_UPSTREAM_FT_HTTP_500 }, |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
444 { 502, NGX_HTTP_UPSTREAM_FT_HTTP_502 }, |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
445 { 503, NGX_HTTP_UPSTREAM_FT_HTTP_503 }, |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
446 { 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
|
447 { 403, NGX_HTTP_UPSTREAM_FT_HTTP_403 }, |
2268
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
448 { 404, NGX_HTTP_UPSTREAM_FT_HTTP_404 }, |
6966
fa56ab75cffc
Upstream: allow recovery from "429 Too Many Requests" response.
Piotr Sikora <piotrsikora@google.com>
parents:
6961
diff
changeset
|
449 { 429, NGX_HTTP_UPSTREAM_FT_HTTP_429 }, |
2268
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
450 { 0, 0 } |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
451 }; |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
452 |
2875
6e1941b321b7
proxy_cache_methods and fastcgi_cache_methods
Igor Sysoev <igor@sysoev.ru>
parents:
2874
diff
changeset
|
453 |
6e1941b321b7
proxy_cache_methods and fastcgi_cache_methods
Igor Sysoev <igor@sysoev.ru>
parents:
2874
diff
changeset
|
454 ngx_conf_bitmask_t ngx_http_upstream_cache_method_mask[] = { |
6439 | 455 { ngx_string("GET"), NGX_HTTP_GET }, |
456 { ngx_string("HEAD"), NGX_HTTP_HEAD }, | |
457 { ngx_string("POST"), NGX_HTTP_POST }, | |
458 { ngx_null_string, 0 } | |
2875
6e1941b321b7
proxy_cache_methods and fastcgi_cache_methods
Igor Sysoev <igor@sysoev.ru>
parents:
2874
diff
changeset
|
459 }; |
6e1941b321b7
proxy_cache_methods and fastcgi_cache_methods
Igor Sysoev <igor@sysoev.ru>
parents:
2874
diff
changeset
|
460 |
6e1941b321b7
proxy_cache_methods and fastcgi_cache_methods
Igor Sysoev <igor@sysoev.ru>
parents:
2874
diff
changeset
|
461 |
3667
12bd9e26fadb
use shared ngx_http_upstream_ignore_headers_masks[]
Igor Sysoev <igor@sysoev.ru>
parents:
3527
diff
changeset
|
462 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
|
463 { 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
|
464 { 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
|
465 { 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
|
466 { 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
|
467 { 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
|
468 { 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
|
469 { 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
|
470 { 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
|
471 { 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
|
472 { ngx_null_string, 0 } |
12bd9e26fadb
use shared ngx_http_upstream_ignore_headers_masks[]
Igor Sysoev <igor@sysoev.ru>
parents:
3527
diff
changeset
|
473 }; |
12bd9e26fadb
use shared ngx_http_upstream_ignore_headers_masks[]
Igor Sysoev <igor@sysoev.ru>
parents:
3527
diff
changeset
|
474 |
12bd9e26fadb
use shared ngx_http_upstream_ignore_headers_masks[]
Igor Sysoev <igor@sysoev.ru>
parents:
3527
diff
changeset
|
475 |
3006
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
476 ngx_int_t |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
477 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
|
478 { |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
479 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
|
480 |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
481 u = r->upstream; |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
482 |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
483 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
|
484 r->main->count++; |
3006
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
485 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
|
486 } |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
487 |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
488 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
|
489 if (u == NULL) { |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
490 return NGX_ERROR; |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
491 } |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
492 |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
493 r->upstream = u; |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
494 |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
495 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
|
496 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
|
497 |
3056
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
498 #if (NGX_HTTP_CACHE) |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
499 r->cache = NULL; |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
500 #endif |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
501 |
4117
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
502 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
|
503 u->headers_in.last_modified_time = -1; |
4117
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
504 |
3006
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
505 return NGX_OK; |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
506 } |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
507 |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
508 |
487 | 509 void |
510 ngx_http_upstream_init(ngx_http_request_t *r) | |
479 | 511 { |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
512 ngx_connection_t *c; |
479 | 513 |
514 c = r->connection; | |
515 | |
516 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
517 "http init upstream, client timer: %d", c->read->timer_set); | |
518 | |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
6242
diff
changeset
|
519 #if (NGX_HTTP_V2) |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
6242
diff
changeset
|
520 if (r->stream) { |
5121
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
5113
diff
changeset
|
521 ngx_http_upstream_init_request(r); |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
5113
diff
changeset
|
522 return; |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
5113
diff
changeset
|
523 } |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
5113
diff
changeset
|
524 #endif |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
5113
diff
changeset
|
525 |
8143
474706351c09
QUIC: fixed ngx_http_upstream_init() much like HTTP/2 connections.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8127
diff
changeset
|
526 #if (NGX_HTTP_QUIC) |
8200
279ad36f2f4b
QUIC: renamed c->qs to c->quic.
Roman Arutyunyan <arut@nginx.com>
parents:
8143
diff
changeset
|
527 if (c->quic) { |
8143
474706351c09
QUIC: fixed ngx_http_upstream_init() much like HTTP/2 connections.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8127
diff
changeset
|
528 ngx_http_upstream_init_request(r); |
474706351c09
QUIC: fixed ngx_http_upstream_init() much like HTTP/2 connections.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8127
diff
changeset
|
529 return; |
474706351c09
QUIC: fixed ngx_http_upstream_init() much like HTTP/2 connections.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8127
diff
changeset
|
530 } |
474706351c09
QUIC: fixed ngx_http_upstream_init() much like HTTP/2 connections.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8127
diff
changeset
|
531 #endif |
474706351c09
QUIC: fixed ngx_http_upstream_init() much like HTTP/2 connections.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8127
diff
changeset
|
532 |
479 | 533 if (c->read->timer_set) { |
534 ngx_del_timer(c->read); | |
535 } | |
536 | |
537 if (ngx_event_flags & NGX_USE_CLEAR_EVENT) { | |
538 | |
539 if (!c->write->active) { | |
531 | 540 if (ngx_add_event(c->write, NGX_WRITE_EVENT, NGX_CLEAR_EVENT) |
541 == NGX_ERROR) | |
479 | 542 { |
543 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | |
544 return; | |
545 } | |
546 } | |
547 } | |
548 | |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
549 ngx_http_upstream_init_request(r); |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
550 } |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
551 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
552 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
553 static void |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
554 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
|
555 { |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
556 ngx_str_t *host; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
557 ngx_uint_t i; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
558 ngx_resolver_ctx_t *ctx, temp; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
559 ngx_http_cleanup_t *cln; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
560 ngx_http_upstream_t *u; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
561 ngx_http_core_loc_conf_t *clcf; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
562 ngx_http_upstream_srv_conf_t *uscf, **uscfp; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
563 ngx_http_upstream_main_conf_t *umcf; |
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 (r->aio) { |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
566 return; |
537 | 567 } |
509 | 568 |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
569 u = r->upstream; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
570 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
571 #if (NGX_HTTP_CACHE) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
572 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
573 if (u->conf->cache) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
574 ngx_int_t rc; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
575 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
576 rc = ngx_http_upstream_cache(r, u); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
577 |
3055
92b6cfaa3c27
fix sending a cached file using AIO
Igor Sysoev <igor@sysoev.ru>
parents:
3053
diff
changeset
|
578 if (rc == NGX_BUSY) { |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
579 r->write_event_handler = ngx_http_upstream_init_request; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
580 return; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
581 } |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
582 |
3055
92b6cfaa3c27
fix sending a cached file using AIO
Igor Sysoev <igor@sysoev.ru>
parents:
3053
diff
changeset
|
583 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
|
584 |
5827
54e9b83d00f0
Upstream: avoided directly terminating the connection.
FengGu <flygoast@126.com>
parents:
5818
diff
changeset
|
585 if (rc == NGX_ERROR) { |
54e9b83d00f0
Upstream: avoided directly terminating the connection.
FengGu <flygoast@126.com>
parents:
5818
diff
changeset
|
586 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
|
587 return; |
54e9b83d00f0
Upstream: avoided directly terminating the connection.
FengGu <flygoast@126.com>
parents:
5818
diff
changeset
|
588 } |
54e9b83d00f0
Upstream: avoided directly terminating the connection.
FengGu <flygoast@126.com>
parents:
5818
diff
changeset
|
589 |
6242
0e3a45ec2a3a
Upstream: fixed cache send error handling.
Roman Arutyunyan <arut@nginx.com>
parents:
6180
diff
changeset
|
590 if (rc == NGX_OK) { |
0e3a45ec2a3a
Upstream: fixed cache send error handling.
Roman Arutyunyan <arut@nginx.com>
parents:
6180
diff
changeset
|
591 rc = ngx_http_upstream_cache_send(r, u); |
0e3a45ec2a3a
Upstream: fixed cache send error handling.
Roman Arutyunyan <arut@nginx.com>
parents:
6180
diff
changeset
|
592 |
0e3a45ec2a3a
Upstream: fixed cache send error handling.
Roman Arutyunyan <arut@nginx.com>
parents:
6180
diff
changeset
|
593 if (rc == NGX_DONE) { |
0e3a45ec2a3a
Upstream: fixed cache send error handling.
Roman Arutyunyan <arut@nginx.com>
parents:
6180
diff
changeset
|
594 return; |
0e3a45ec2a3a
Upstream: fixed cache send error handling.
Roman Arutyunyan <arut@nginx.com>
parents:
6180
diff
changeset
|
595 } |
0e3a45ec2a3a
Upstream: fixed cache send error handling.
Roman Arutyunyan <arut@nginx.com>
parents:
6180
diff
changeset
|
596 |
0e3a45ec2a3a
Upstream: fixed cache send error handling.
Roman Arutyunyan <arut@nginx.com>
parents:
6180
diff
changeset
|
597 if (rc == NGX_HTTP_UPSTREAM_INVALID_HEADER) { |
0e3a45ec2a3a
Upstream: fixed cache send error handling.
Roman Arutyunyan <arut@nginx.com>
parents:
6180
diff
changeset
|
598 rc = NGX_DECLINED; |
0e3a45ec2a3a
Upstream: fixed cache send error handling.
Roman Arutyunyan <arut@nginx.com>
parents:
6180
diff
changeset
|
599 r->cached = 0; |
7116
46ddff109e72
Upstream: better handling of invalid headers in cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7093
diff
changeset
|
600 u->buffer.start = NULL; |
46ddff109e72
Upstream: better handling of invalid headers in cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7093
diff
changeset
|
601 u->cache_status = NGX_HTTP_CACHE_MISS; |
7125
b8fc701daf8e
Upstream: even better handling of invalid headers in cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7117
diff
changeset
|
602 u->request_sent = 1; |
6242
0e3a45ec2a3a
Upstream: fixed cache send error handling.
Roman Arutyunyan <arut@nginx.com>
parents:
6180
diff
changeset
|
603 } |
0e3a45ec2a3a
Upstream: fixed cache send error handling.
Roman Arutyunyan <arut@nginx.com>
parents:
6180
diff
changeset
|
604 } |
0e3a45ec2a3a
Upstream: fixed cache send error handling.
Roman Arutyunyan <arut@nginx.com>
parents:
6180
diff
changeset
|
605 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
606 if (rc != NGX_DECLINED) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
607 ngx_http_finalize_request(r, rc); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
608 return; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
609 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
610 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
611 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
612 #endif |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
613 |
5947
d9025ea1f5a5
Upstream: simplified proxy_store and friends configuration code.
Valentin Bartenev <vbart@nginx.com>
parents:
5935
diff
changeset
|
614 u->store = u->conf->store; |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
615 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
616 if (!u->store && !r->post_action && !u->conf->ignore_client_abort) { |
8373
1bf8ab7063de
Upstream: fixed broken connection check with eventport.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8372
diff
changeset
|
617 |
8374
1ebd78df4ce7
Fixed handling of already closed connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8373
diff
changeset
|
618 if (r->connection->read->ready) { |
1ebd78df4ce7
Fixed handling of already closed connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8373
diff
changeset
|
619 ngx_post_event(r->connection->read, &ngx_posted_events); |
1ebd78df4ce7
Fixed handling of already closed connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8373
diff
changeset
|
620 |
1ebd78df4ce7
Fixed handling of already closed connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8373
diff
changeset
|
621 } else { |
1ebd78df4ce7
Fixed handling of already closed connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8373
diff
changeset
|
622 if (ngx_handle_read_event(r->connection->read, 0) != NGX_OK) { |
1ebd78df4ce7
Fixed handling of already closed connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8373
diff
changeset
|
623 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); |
1ebd78df4ce7
Fixed handling of already closed connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8373
diff
changeset
|
624 return; |
1ebd78df4ce7
Fixed handling of already closed connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8373
diff
changeset
|
625 } |
8373
1bf8ab7063de
Upstream: fixed broken connection check with eventport.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8372
diff
changeset
|
626 } |
1bf8ab7063de
Upstream: fixed broken connection check with eventport.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8372
diff
changeset
|
627 |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
628 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
|
629 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
|
630 } |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
631 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
632 if (r->request_body) { |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
633 u->request_bufs = r->request_body->bufs; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
634 } |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
635 |
537 | 636 if (u->create_request(r) != NGX_OK) { |
479 | 637 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); |
638 return; | |
639 } | |
640 | |
6528
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
641 if (ngx_http_upstream_set_local(r, u, u->conf->local) != NGX_OK) { |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
642 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
643 return; |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
644 } |
3271
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3198
diff
changeset
|
645 |
7371
8b68d50090e4
Upstream: proxy_socket_keepalive and friends.
Vladimir Homutov <vl@nginx.com>
parents:
7341
diff
changeset
|
646 if (u->conf->socket_keepalive) { |
8b68d50090e4
Upstream: proxy_socket_keepalive and friends.
Vladimir Homutov <vl@nginx.com>
parents:
7341
diff
changeset
|
647 u->peer.so_keepalive = 1; |
8b68d50090e4
Upstream: proxy_socket_keepalive and friends.
Vladimir Homutov <vl@nginx.com>
parents:
7341
diff
changeset
|
648 } |
8b68d50090e4
Upstream: proxy_socket_keepalive and friends.
Vladimir Homutov <vl@nginx.com>
parents:
7341
diff
changeset
|
649 |
509 | 650 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
479 | 651 |
3053 | 652 u->output.alignment = clcf->directio_alignment; |
479 | 653 u->output.pool = r->pool; |
654 u->output.bufs.num = 1; | |
509 | 655 u->output.bufs.size = clcf->client_body_buffer_size; |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
656 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
657 if (u->output.output_filter == NULL) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
658 u->output.output_filter = ngx_chain_writer; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
659 u->output.filter_ctx = &u->writer; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
660 } |
479 | 661 |
662 u->writer.pool = r->pool; | |
663 | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
664 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
|
665 |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
666 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
|
667 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
|
668 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
|
669 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
|
670 return; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
671 } |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
672 |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
673 } else { |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
674 |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
675 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
|
676 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
|
677 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
|
678 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
|
679 return; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
680 } |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
681 |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
682 ngx_memzero(u->state, sizeof(ngx_http_upstream_state_t)); |
479 | 683 } |
684 | |
593 | 685 cln = ngx_http_cleanup_add(r, 0); |
569 | 686 if (cln == NULL) { |
687 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | |
688 return; | |
689 } | |
690 | |
691 cln->handler = ngx_http_upstream_cleanup; | |
692 cln->data = r; | |
693 u->cleanup = &cln->handler; | |
694 | |
1658 | 695 if (u->resolved == NULL) { |
696 | |
697 uscf = u->conf->upstream; | |
698 | |
699 } else { | |
700 | |
5660
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
701 #if (NGX_HTTP_SSL) |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
702 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
|
703 #endif |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
704 |
6303
a93345ee8f52
Upstream: fixed "no port" detection in evaluated upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6290
diff
changeset
|
705 host = &u->resolved->host; |
a93345ee8f52
Upstream: fixed "no port" detection in evaluated upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6290
diff
changeset
|
706 |
6786
906ac20234ed
Upstream: do not unnecessarily create per-request upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6777
diff
changeset
|
707 umcf = ngx_http_get_module_main_conf(r, ngx_http_upstream_module); |
906ac20234ed
Upstream: do not unnecessarily create per-request upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6777
diff
changeset
|
708 |
906ac20234ed
Upstream: do not unnecessarily create per-request upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6777
diff
changeset
|
709 uscfp = umcf->upstreams.elts; |
906ac20234ed
Upstream: do not unnecessarily create per-request upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6777
diff
changeset
|
710 |
906ac20234ed
Upstream: do not unnecessarily create per-request upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6777
diff
changeset
|
711 for (i = 0; i < umcf->upstreams.nelts; i++) { |
906ac20234ed
Upstream: do not unnecessarily create per-request upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6777
diff
changeset
|
712 |
906ac20234ed
Upstream: do not unnecessarily create per-request upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6777
diff
changeset
|
713 uscf = uscfp[i]; |
906ac20234ed
Upstream: do not unnecessarily create per-request upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6777
diff
changeset
|
714 |
906ac20234ed
Upstream: do not unnecessarily create per-request upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6777
diff
changeset
|
715 if (uscf->host.len == host->len |
906ac20234ed
Upstream: do not unnecessarily create per-request upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6777
diff
changeset
|
716 && ((uscf->port == 0 && u->resolved->no_port) |
906ac20234ed
Upstream: do not unnecessarily create per-request upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6777
diff
changeset
|
717 || uscf->port == u->resolved->port) |
906ac20234ed
Upstream: do not unnecessarily create per-request upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6777
diff
changeset
|
718 && ngx_strncasecmp(uscf->host.data, host->data, host->len) == 0) |
906ac20234ed
Upstream: do not unnecessarily create per-request upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6777
diff
changeset
|
719 { |
906ac20234ed
Upstream: do not unnecessarily create per-request upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6777
diff
changeset
|
720 goto found; |
906ac20234ed
Upstream: do not unnecessarily create per-request upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6777
diff
changeset
|
721 } |
906ac20234ed
Upstream: do not unnecessarily create per-request upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6777
diff
changeset
|
722 } |
906ac20234ed
Upstream: do not unnecessarily create per-request upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6777
diff
changeset
|
723 |
2422
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2413
diff
changeset
|
724 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
|
725 |
6326
705c356ce664
Fixed fastcgi_pass with UNIX socket and variables (ticket #855).
Ruslan Ermilov <ru@nginx.com>
parents:
6316
diff
changeset
|
726 if (u->resolved->port == 0 |
705c356ce664
Fixed fastcgi_pass with UNIX socket and variables (ticket #855).
Ruslan Ermilov <ru@nginx.com>
parents:
6316
diff
changeset
|
727 && u->resolved->sockaddr->sa_family != AF_UNIX) |
705c356ce664
Fixed fastcgi_pass with UNIX socket and variables (ticket #855).
Ruslan Ermilov <ru@nginx.com>
parents:
6316
diff
changeset
|
728 { |
6303
a93345ee8f52
Upstream: fixed "no port" detection in evaluated upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6290
diff
changeset
|
729 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
|
730 "no port in upstream \"%V\"", host); |
a93345ee8f52
Upstream: fixed "no port" detection in evaluated upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6290
diff
changeset
|
731 ngx_http_upstream_finalize_request(r, u, |
6313 | 732 NGX_HTTP_INTERNAL_SERVER_ERROR); |
6303
a93345ee8f52
Upstream: fixed "no port" detection in evaluated upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6290
diff
changeset
|
733 return; |
a93345ee8f52
Upstream: fixed "no port" detection in evaluated upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6290
diff
changeset
|
734 } |
a93345ee8f52
Upstream: fixed "no port" detection in evaluated upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6290
diff
changeset
|
735 |
2422
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2413
diff
changeset
|
736 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
|
737 != NGX_OK) |
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2413
diff
changeset
|
738 { |
3169
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
739 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
|
740 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
|
741 return; |
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2413
diff
changeset
|
742 } |
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2413
diff
changeset
|
743 |
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2413
diff
changeset
|
744 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
|
745 |
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2413
diff
changeset
|
746 return; |
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2413
diff
changeset
|
747 } |
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2413
diff
changeset
|
748 |
3879
502a6b0acf3f
fix case when a host in fastcgi_pass, scgi_pass, and uwsgi_pass
Igor Sysoev <igor@sysoev.ru>
parents:
3713
diff
changeset
|
749 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
|
750 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
|
751 "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
|
752 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
|
753 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
|
754 return; |
502a6b0acf3f
fix case when a host in fastcgi_pass, scgi_pass, and uwsgi_pass
Igor Sysoev <igor@sysoev.ru>
parents:
3713
diff
changeset
|
755 } |
502a6b0acf3f
fix case when a host in fastcgi_pass, scgi_pass, and uwsgi_pass
Igor Sysoev <igor@sysoev.ru>
parents:
3713
diff
changeset
|
756 |
1658 | 757 temp.name = *host; |
758 | |
759 ctx = ngx_resolve_start(clcf->resolver, &temp); | |
760 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
|
761 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
|
762 NGX_HTTP_INTERNAL_SERVER_ERROR); |
1658 | 763 return; |
764 } | |
765 | |
1683
1e0b028055ec
allow to use IP addresses without defined resolver
Igor Sysoev <igor@sysoev.ru>
parents:
1658
diff
changeset
|
766 if (ctx == NGX_NO_RESOLVER) { |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
767 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
|
768 "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
|
769 |
3169
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
770 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
|
771 return; |
1e0b028055ec
allow to use IP addresses without defined resolver
Igor Sysoev <igor@sysoev.ru>
parents:
1658
diff
changeset
|
772 } |
1e0b028055ec
allow to use IP addresses without defined resolver
Igor Sysoev <igor@sysoev.ru>
parents:
1658
diff
changeset
|
773 |
1658 | 774 ctx->name = *host; |
775 ctx->handler = ngx_http_upstream_resolve_handler; | |
776 ctx->data = r; | |
777 ctx->timeout = clcf->resolver_timeout; | |
778 | |
1959
4f16186f5603
quick resolving handles u->resolved->ctx by itself
Igor Sysoev <igor@sysoev.ru>
parents:
1958
diff
changeset
|
779 u->resolved->ctx = ctx; |
4f16186f5603
quick resolving handles u->resolved->ctx by itself
Igor Sysoev <igor@sysoev.ru>
parents:
1958
diff
changeset
|
780 |
1658 | 781 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
|
782 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
|
783 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
|
784 NGX_HTTP_INTERNAL_SERVER_ERROR); |
1658 | 785 return; |
786 } | |
787 | |
788 return; | |
789 } | |
790 | |
791 found: | |
792 | |
4964
2464ccebdb52
Upstream: fixed SIGSEGV with the "if" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4916
diff
changeset
|
793 if (uscf == NULL) { |
2464ccebdb52
Upstream: fixed SIGSEGV with the "if" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4916
diff
changeset
|
794 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
|
795 "no upstream configuration"); |
2464ccebdb52
Upstream: fixed SIGSEGV with the "if" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4916
diff
changeset
|
796 ngx_http_upstream_finalize_request(r, u, |
2464ccebdb52
Upstream: fixed SIGSEGV with the "if" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4916
diff
changeset
|
797 NGX_HTTP_INTERNAL_SERVER_ERROR); |
2464ccebdb52
Upstream: fixed SIGSEGV with the "if" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4916
diff
changeset
|
798 return; |
2464ccebdb52
Upstream: fixed SIGSEGV with the "if" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4916
diff
changeset
|
799 } |
2464ccebdb52
Upstream: fixed SIGSEGV with the "if" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4916
diff
changeset
|
800 |
6703
edcd9303a4d3
Upstream: introduced u->upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6699
diff
changeset
|
801 u->upstream = uscf; |
edcd9303a4d3
Upstream: introduced u->upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6699
diff
changeset
|
802 |
5682
110b50657d77
Upstream: restored workaround for "if".
Maxim Dounin <mdounin@mdounin.ru>
parents:
5677
diff
changeset
|
803 #if (NGX_HTTP_SSL) |
110b50657d77
Upstream: restored workaround for "if".
Maxim Dounin <mdounin@mdounin.ru>
parents:
5677
diff
changeset
|
804 u->ssl_name = uscf->host; |
110b50657d77
Upstream: restored workaround for "if".
Maxim Dounin <mdounin@mdounin.ru>
parents:
5677
diff
changeset
|
805 #endif |
110b50657d77
Upstream: restored workaround for "if".
Maxim Dounin <mdounin@mdounin.ru>
parents:
5677
diff
changeset
|
806 |
1658 | 807 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
|
808 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
|
809 NGX_HTTP_INTERNAL_SERVER_ERROR); |
1658 | 810 return; |
811 } | |
812 | |
5832
d09b689911ac
Upstream: limited next_upstream time and tries (ticket #544).
Roman Arutyunyan <arut@nginx.com>
parents:
5827
diff
changeset
|
813 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
|
814 |
d09b689911ac
Upstream: limited next_upstream time and tries (ticket #544).
Roman Arutyunyan <arut@nginx.com>
parents:
5827
diff
changeset
|
815 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
|
816 && 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
|
817 { |
d09b689911ac
Upstream: limited next_upstream time and tries (ticket #544).
Roman Arutyunyan <arut@nginx.com>
parents:
5827
diff
changeset
|
818 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
|
819 } |
d09b689911ac
Upstream: limited next_upstream time and tries (ticket #544).
Roman Arutyunyan <arut@nginx.com>
parents:
5827
diff
changeset
|
820 |
479 | 821 ngx_http_upstream_connect(r, u); |
822 } | |
823 | |
824 | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
825 #if (NGX_HTTP_CACHE) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
826 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
827 static ngx_int_t |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
828 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
|
829 { |
5951
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
830 ngx_int_t rc; |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
831 ngx_http_cache_t *c; |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
832 ngx_http_file_cache_t *cache; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
833 |
3056
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
834 c = r->cache; |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
835 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
836 if (c == NULL) { |
3056
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
837 |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
838 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
|
839 return NGX_DECLINED; |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
840 } |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
841 |
5951
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
842 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
|
843 |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
844 if (rc != NGX_OK) { |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
845 return rc; |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
846 } |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
847 |
6306
b1858fc47e3b
Style: unified request method checks.
Ruslan Ermilov <ru@nginx.com>
parents:
6303
diff
changeset
|
848 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
|
849 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
|
850 } |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
851 |
3698
d11227f0107f
rename ngx_http_file_cache_create() to ngx_http_file_cache_new()
Igor Sysoev <igor@sysoev.ru>
parents:
3697
diff
changeset
|
852 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
|
853 return NGX_ERROR; |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
854 } |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
855 |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
856 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
|
857 return NGX_ERROR; |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
858 } |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
859 |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
860 /* TODO: add keys */ |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
861 |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
862 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
|
863 |
7456
608810849b6d
Upstream: fixed logging of required buffer size (ticket #1722).
Chanhun Jeong <chanhun.jeong@navercorp.com>
parents:
7429
diff
changeset
|
864 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
|
865 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
|
866 "%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
|
867 "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
|
868 &u->conf->module, u->conf->buffer_size, |
215fe9223419
update r3945 with more descriptive error message
Igor Sysoev <igor@sysoev.ru>
parents:
3963
diff
changeset
|
869 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
|
870 |
f1f194ceab16
fix segfault if cache key is larger than upstream buffer size
Igor Sysoev <igor@sysoev.ru>
parents:
3940
diff
changeset
|
871 r->cache = NULL; |
f1f194ceab16
fix segfault if cache key is larger than upstream buffer size
Igor Sysoev <igor@sysoev.ru>
parents:
3940
diff
changeset
|
872 return NGX_DECLINED; |
f1f194ceab16
fix segfault if cache key is larger than upstream buffer size
Igor Sysoev <igor@sysoev.ru>
parents:
3940
diff
changeset
|
873 } |
f1f194ceab16
fix segfault if cache key is larger than upstream buffer size
Igor Sysoev <igor@sysoev.ru>
parents:
3940
diff
changeset
|
874 |
4176
2b5151a2300b
Fixed cache bypass caching of non-cacheable replies (ticket #21).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4152
diff
changeset
|
875 u->cacheable = 1; |
2b5151a2300b
Fixed cache bypass caching of non-cacheable replies (ticket #21).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4152
diff
changeset
|
876 |
5950
eaeecf00d5d7
Upstream: preset some cache configuration when bypassing.
Valentin Bartenev <vbart@nginx.com>
parents:
5949
diff
changeset
|
877 c = r->cache; |
eaeecf00d5d7
Upstream: preset some cache configuration when bypassing.
Valentin Bartenev <vbart@nginx.com>
parents:
5949
diff
changeset
|
878 |
eaeecf00d5d7
Upstream: preset some cache configuration when bypassing.
Valentin Bartenev <vbart@nginx.com>
parents:
5949
diff
changeset
|
879 c->body_start = u->conf->buffer_size; |
eaeecf00d5d7
Upstream: preset some cache configuration when bypassing.
Valentin Bartenev <vbart@nginx.com>
parents:
5949
diff
changeset
|
880 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
|
881 c->file_cache = cache; |
5950
eaeecf00d5d7
Upstream: preset some cache configuration when bypassing.
Valentin Bartenev <vbart@nginx.com>
parents:
5949
diff
changeset
|
882 |
3917
2a70484a6580
fix a broken cached response if bypass/no_cache directive values are different,
Igor Sysoev <igor@sysoev.ru>
parents:
3898
diff
changeset
|
883 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
|
884 |
2a70484a6580
fix a broken cached response if bypass/no_cache directive values are different,
Igor Sysoev <igor@sysoev.ru>
parents:
3898
diff
changeset
|
885 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
|
886 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
|
887 |
2a70484a6580
fix a broken cached response if bypass/no_cache directive values are different,
Igor Sysoev <igor@sysoev.ru>
parents:
3898
diff
changeset
|
888 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
|
889 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
|
890 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
|
891 |
2a70484a6580
fix a broken cached response if bypass/no_cache directive values are different,
Igor Sysoev <igor@sysoev.ru>
parents:
3898
diff
changeset
|
892 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
|
893 break; |
2a70484a6580
fix a broken cached response if bypass/no_cache directive values are different,
Igor Sysoev <igor@sysoev.ru>
parents:
3898
diff
changeset
|
894 } |
2a70484a6580
fix a broken cached response if bypass/no_cache directive values are different,
Igor Sysoev <igor@sysoev.ru>
parents:
3898
diff
changeset
|
895 |
4385
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4375
diff
changeset
|
896 c->lock = u->conf->cache_lock; |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4375
diff
changeset
|
897 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
|
898 c->lock_age = u->conf->cache_lock_age; |
4385
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4375
diff
changeset
|
899 |
3056
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
900 u->cache_status = NGX_HTTP_CACHE_MISS; |
2592
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 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
903 rc = ngx_http_file_cache_open(r); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
904 |
2926
80a314b63c56
delete useless r->cache->uses
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
905 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
|
906 "http upstream cache: %i", rc); |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
907 |
2952 | 908 switch (rc) { |
909 | |
6906
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
910 case NGX_HTTP_CACHE_STALE: |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
911 |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
912 if (((u->conf->cache_use_stale & NGX_HTTP_UPSTREAM_FT_UPDATING) |
7006
9552758a786e
Background subrequests for cache updates.
Roman Arutyunyan <arut@nginx.com>
parents:
6986
diff
changeset
|
913 || c->stale_updating) && !r->background |
6906
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
914 && u->conf->cache_background_update) |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
915 { |
7514
319242d2ddc9
Upstream: background cache update before cache send (ticket #1782).
Roman Arutyunyan <arut@nginx.com>
parents:
7504
diff
changeset
|
916 if (ngx_http_upstream_cache_background_update(r, u) == NGX_OK) { |
319242d2ddc9
Upstream: background cache update before cache send (ticket #1782).
Roman Arutyunyan <arut@nginx.com>
parents:
7504
diff
changeset
|
917 r->cache->background = 1; |
319242d2ddc9
Upstream: background cache update before cache send (ticket #1782).
Roman Arutyunyan <arut@nginx.com>
parents:
7504
diff
changeset
|
918 u->cache_status = rc; |
319242d2ddc9
Upstream: background cache update before cache send (ticket #1782).
Roman Arutyunyan <arut@nginx.com>
parents:
7504
diff
changeset
|
919 rc = NGX_OK; |
319242d2ddc9
Upstream: background cache update before cache send (ticket #1782).
Roman Arutyunyan <arut@nginx.com>
parents:
7504
diff
changeset
|
920 |
319242d2ddc9
Upstream: background cache update before cache send (ticket #1782).
Roman Arutyunyan <arut@nginx.com>
parents:
7504
diff
changeset
|
921 } else { |
319242d2ddc9
Upstream: background cache update before cache send (ticket #1782).
Roman Arutyunyan <arut@nginx.com>
parents:
7504
diff
changeset
|
922 rc = NGX_ERROR; |
319242d2ddc9
Upstream: background cache update before cache send (ticket #1782).
Roman Arutyunyan <arut@nginx.com>
parents:
7504
diff
changeset
|
923 } |
6906
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
924 } |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
925 |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
926 break; |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
927 |
2952 | 928 case NGX_HTTP_CACHE_UPDATING: |
929 | |
6906
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
930 if (((u->conf->cache_use_stale & NGX_HTTP_UPSTREAM_FT_UPDATING) |
7006
9552758a786e
Background subrequests for cache updates.
Roman Arutyunyan <arut@nginx.com>
parents:
6986
diff
changeset
|
931 || c->stale_updating) && !r->background) |
6905
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
932 { |
2952 | 933 u->cache_status = rc; |
2927
55ceaef03d34
proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents:
2926
diff
changeset
|
934 rc = NGX_OK; |
55ceaef03d34
proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents:
2926
diff
changeset
|
935 |
55ceaef03d34
proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents:
2926
diff
changeset
|
936 } else { |
55ceaef03d34
proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents:
2926
diff
changeset
|
937 rc = NGX_HTTP_CACHE_STALE; |
55ceaef03d34
proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents:
2926
diff
changeset
|
938 } |
2952 | 939 |
940 break; | |
941 | |
942 case NGX_OK: | |
943 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
|
944 } |
55ceaef03d34
proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents:
2926
diff
changeset
|
945 |
2952 | 946 switch (rc) { |
947 | |
948 case NGX_OK: | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
949 |
6242
0e3a45ec2a3a
Upstream: fixed cache send error handling.
Roman Arutyunyan <arut@nginx.com>
parents:
6180
diff
changeset
|
950 return NGX_OK; |
2952 | 951 |
952 case NGX_HTTP_CACHE_STALE: | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
953 |
2665
4d627567c324
fix r2664: ..._cache_valid did not work for stale responses
Igor Sysoev <igor@sysoev.ru>
parents:
2664
diff
changeset
|
954 c->valid_sec = 0; |
6905
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
955 c->updating_sec = 0; |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
956 c->error_sec = 0; |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
957 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
958 u->buffer.start = NULL; |
2952 | 959 u->cache_status = NGX_HTTP_CACHE_EXPIRED; |
960 | |
961 break; | |
962 | |
963 case NGX_DECLINED: | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
964 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
965 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
|
966 u->buffer.start = NULL; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
967 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
968 } else { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
969 u->buffer.pos = u->buffer.start + c->header_start; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
970 u->buffer.last = u->buffer.pos; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
971 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
972 |
2952 | 973 break; |
974 | |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
975 case NGX_HTTP_CACHE_SCARCE: |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
976 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
977 u->cacheable = 0; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
978 |
2952 | 979 break; |
980 | |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
981 case NGX_AGAIN: |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
982 |
3055
92b6cfaa3c27
fix sending a cached file using AIO
Igor Sysoev <igor@sysoev.ru>
parents:
3053
diff
changeset
|
983 return NGX_BUSY; |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
984 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
985 case NGX_ERROR: |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
986 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
987 return NGX_ERROR; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
988 |
2952 | 989 default: |
2592
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 /* 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
|
992 |
2952 | 993 u->cache_status = NGX_HTTP_CACHE_HIT; |
994 | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
995 return rc; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
996 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
997 |
6793
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
998 if (ngx_http_upstream_cache_check_range(r, u) == NGX_DECLINED) { |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
999 u->cacheable = 0; |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1000 } |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1001 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1002 r->cached = 0; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1003 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1004 return NGX_DECLINED; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1005 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1006 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1007 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1008 static ngx_int_t |
5951
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
1009 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
|
1010 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
|
1011 { |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
1012 ngx_str_t *name, val; |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
1013 ngx_uint_t i; |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
1014 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
|
1015 |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
1016 if (u->conf->cache_zone) { |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
1017 *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
|
1018 return NGX_OK; |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
1019 } |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
1020 |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
1021 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
|
1022 return NGX_ERROR; |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
1023 } |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
1024 |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
1025 if (val.len == 0 |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
1026 || (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
|
1027 { |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
1028 return NGX_DECLINED; |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
1029 } |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
1030 |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
1031 caches = u->caches->elts; |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
1032 |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
1033 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
|
1034 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
|
1035 |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
1036 if (name->len == val.len |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
1037 && 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
|
1038 { |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
1039 *cache = caches[i]; |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
1040 return NGX_OK; |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
1041 } |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
1042 } |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
1043 |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
1044 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
|
1045 "cache \"%V\" not found", &val); |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
1046 |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
1047 return NGX_ERROR; |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
1048 } |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
1049 |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
1050 |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
1051 static ngx_int_t |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1052 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
|
1053 { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1054 ngx_int_t rc; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1055 ngx_http_cache_t *c; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1056 |
2952 | 1057 r->cached = 1; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1058 c = r->cache; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1059 |
3369
479468a7d982
fix handling cached HTTP/0.9 response
Igor Sysoev <igor@sysoev.ru>
parents:
3272
diff
changeset
|
1060 if (c->header_start == c->body_start) { |
479468a7d982
fix handling cached HTTP/0.9 response
Igor Sysoev <igor@sysoev.ru>
parents:
3272
diff
changeset
|
1061 r->http_version = NGX_HTTP_VERSION_9; |
479468a7d982
fix handling cached HTTP/0.9 response
Igor Sysoev <igor@sysoev.ru>
parents:
3272
diff
changeset
|
1062 return ngx_http_cache_send(r); |
479468a7d982
fix handling cached HTTP/0.9 response
Igor Sysoev <igor@sysoev.ru>
parents:
3272
diff
changeset
|
1063 } |
479468a7d982
fix handling cached HTTP/0.9 response
Igor Sysoev <igor@sysoev.ru>
parents:
3272
diff
changeset
|
1064 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1065 /* TODO: cache stack */ |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1066 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1067 u->buffer = *c->buf; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1068 u->buffer.pos += c->header_start; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1069 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1070 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
|
1071 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
|
1072 u->headers_in.last_modified_time = -1; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1073 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1074 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
|
1075 sizeof(ngx_table_elt_t)) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1076 != NGX_OK) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1077 { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1078 return NGX_ERROR; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1079 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1080 |
7230
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
1081 if (ngx_list_init(&u->headers_in.trailers, r->pool, 2, |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
1082 sizeof(ngx_table_elt_t)) |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
1083 != NGX_OK) |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
1084 { |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
1085 return NGX_ERROR; |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
1086 } |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
1087 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1088 rc = u->process_header(r); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1089 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1090 if (rc == NGX_OK) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1091 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1092 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
|
1093 return NGX_DONE; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1094 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1095 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1096 return ngx_http_cache_send(r); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1097 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1098 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1099 if (rc == NGX_ERROR) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1100 return NGX_ERROR; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1101 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1102 |
7116
46ddff109e72
Upstream: better handling of invalid headers in cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7093
diff
changeset
|
1103 if (rc == NGX_AGAIN) { |
46ddff109e72
Upstream: better handling of invalid headers in cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7093
diff
changeset
|
1104 rc = NGX_HTTP_UPSTREAM_INVALID_HEADER; |
46ddff109e72
Upstream: better handling of invalid headers in cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7093
diff
changeset
|
1105 } |
46ddff109e72
Upstream: better handling of invalid headers in cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7093
diff
changeset
|
1106 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1107 /* rc == NGX_HTTP_UPSTREAM_INVALID_HEADER */ |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1108 |
7116
46ddff109e72
Upstream: better handling of invalid headers in cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7093
diff
changeset
|
1109 ngx_log_error(NGX_LOG_CRIT, r->connection->log, 0, |
46ddff109e72
Upstream: better handling of invalid headers in cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7093
diff
changeset
|
1110 "cache file \"%s\" contains invalid header", |
46ddff109e72
Upstream: better handling of invalid headers in cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7093
diff
changeset
|
1111 c->file.name.data); |
46ddff109e72
Upstream: better handling of invalid headers in cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7093
diff
changeset
|
1112 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1113 /* TODO: delete file */ |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1114 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1115 return rc; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1116 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1117 |
6793
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1118 |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1119 static ngx_int_t |
6906
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
1120 ngx_http_upstream_cache_background_update(ngx_http_request_t *r, |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
1121 ngx_http_upstream_t *u) |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
1122 { |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
1123 ngx_http_request_t *sr; |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
1124 |
7070
f583559aadc7
Upstream: keep request body file from removal if requested.
Roman Arutyunyan <arut@nginx.com>
parents:
7067
diff
changeset
|
1125 if (r == r->main) { |
f583559aadc7
Upstream: keep request body file from removal if requested.
Roman Arutyunyan <arut@nginx.com>
parents:
7067
diff
changeset
|
1126 r->preserve_body = 1; |
f583559aadc7
Upstream: keep request body file from removal if requested.
Roman Arutyunyan <arut@nginx.com>
parents:
7067
diff
changeset
|
1127 } |
f583559aadc7
Upstream: keep request body file from removal if requested.
Roman Arutyunyan <arut@nginx.com>
parents:
7067
diff
changeset
|
1128 |
6906
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
1129 if (ngx_http_subrequest(r, &r->uri, &r->args, &sr, NULL, |
7006
9552758a786e
Background subrequests for cache updates.
Roman Arutyunyan <arut@nginx.com>
parents:
6986
diff
changeset
|
1130 NGX_HTTP_SUBREQUEST_CLONE |
9552758a786e
Background subrequests for cache updates.
Roman Arutyunyan <arut@nginx.com>
parents:
6986
diff
changeset
|
1131 |NGX_HTTP_SUBREQUEST_BACKGROUND) |
6906
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
1132 != NGX_OK) |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
1133 { |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
1134 return NGX_ERROR; |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
1135 } |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
1136 |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
1137 sr->header_only = 1; |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
1138 |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
1139 return NGX_OK; |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
1140 } |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
1141 |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
1142 |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
1143 static ngx_int_t |
6793
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1144 ngx_http_upstream_cache_check_range(ngx_http_request_t *r, |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1145 ngx_http_upstream_t *u) |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1146 { |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1147 off_t offset; |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1148 u_char *p, *start; |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1149 ngx_table_elt_t *h; |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1150 |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1151 h = r->headers_in.range; |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1152 |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1153 if (h == NULL |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1154 || !u->cacheable |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1155 || u->conf->cache_max_range_offset == NGX_MAX_OFF_T_VALUE) |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1156 { |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1157 return NGX_OK; |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1158 } |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1159 |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1160 if (u->conf->cache_max_range_offset == 0) { |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1161 return NGX_DECLINED; |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1162 } |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1163 |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1164 if (h->value.len < 7 |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1165 || ngx_strncasecmp(h->value.data, (u_char *) "bytes=", 6) != 0) |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1166 { |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1167 return NGX_OK; |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1168 } |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1169 |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1170 p = h->value.data + 6; |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1171 |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1172 while (*p == ' ') { p++; } |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1173 |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1174 if (*p == '-') { |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1175 return NGX_DECLINED; |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1176 } |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1177 |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1178 start = p; |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1179 |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1180 while (*p >= '0' && *p <= '9') { p++; } |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1181 |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1182 offset = ngx_atoof(start, p - start); |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1183 |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1184 if (offset >= u->conf->cache_max_range_offset) { |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1185 return NGX_DECLINED; |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1186 } |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1187 |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1188 return NGX_OK; |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1189 } |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1190 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1191 #endif |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1192 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1193 |
487 | 1194 static void |
1658 | 1195 ngx_http_upstream_resolve_handler(ngx_resolver_ctx_t *ctx) |
1196 { | |
7041
6169dbad37d8
Upstream: fixed running posted requests (ticket #788).
Roman Arutyunyan <arut@nginx.com>
parents:
7018
diff
changeset
|
1197 ngx_uint_t run_posted; |
5113
08b36f2afc3f
Upstream: fixed previous commit.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5112
diff
changeset
|
1198 ngx_connection_t *c; |
1658 | 1199 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
|
1200 ngx_http_upstream_t *u; |
1658 | 1201 ngx_http_upstream_resolved_t *ur; |
1202 | |
7041
6169dbad37d8
Upstream: fixed running posted requests (ticket #788).
Roman Arutyunyan <arut@nginx.com>
parents:
7018
diff
changeset
|
1203 run_posted = ctx->async; |
6169dbad37d8
Upstream: fixed running posted requests (ticket #788).
Roman Arutyunyan <arut@nginx.com>
parents:
7018
diff
changeset
|
1204 |
1658 | 1205 r = ctx->data; |
5113
08b36f2afc3f
Upstream: fixed previous commit.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5112
diff
changeset
|
1206 c = r->connection; |
1658 | 1207 |
3169
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
1208 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
|
1209 ur = u->resolved; |
1658 | 1210 |
5928
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5911
diff
changeset
|
1211 ngx_http_set_log_request(c->log, r); |
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5911
diff
changeset
|
1212 |
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5911
diff
changeset
|
1213 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, |
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5911
diff
changeset
|
1214 "http upstream resolve: \"%V?%V\"", &r->uri, &r->args); |
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5911
diff
changeset
|
1215 |
1658 | 1216 if (ctx->state) { |
1217 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
1218 "%V could not be resolved (%i: %s)", | |
1219 &ctx->name, ctx->state, | |
1220 ngx_resolver_strerror(ctx->state)); | |
1221 | |
3169
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
1222 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
|
1223 goto failed; |
1658 | 1224 } |
1225 | |
1226 ur->naddrs = ctx->naddrs; | |
1227 ur->addrs = ctx->addrs; | |
1228 | |
1229 #if (NGX_DEBUG) | |
1230 { | |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5453
diff
changeset
|
1231 u_char text[NGX_SOCKADDR_STRLEN]; |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5453
diff
changeset
|
1232 ngx_str_t addr; |
1658 | 1233 ngx_uint_t i; |
1234 | |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5453
diff
changeset
|
1235 addr.data = text; |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5453
diff
changeset
|
1236 |
1658 | 1237 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
|
1238 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
|
1239 text, NGX_SOCKADDR_STRLEN, 0); |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5453
diff
changeset
|
1240 |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5453
diff
changeset
|
1241 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
|
1242 "name was resolved to %V", &addr); |
1658 | 1243 } |
1244 } | |
1245 #endif | |
1246 | |
1247 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
|
1248 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
|
1249 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
|
1250 goto failed; |
1658 | 1251 } |
1252 | |
1253 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
|
1254 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
|
1255 |
5885
5a042519bfe7
Upstream: limited next_upstream time and tries when resolving DNS.
Gu Feng <flygoast@126.com>
parents:
5883
diff
changeset
|
1256 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
|
1257 |
5a042519bfe7
Upstream: limited next_upstream time and tries when resolving DNS.
Gu Feng <flygoast@126.com>
parents:
5883
diff
changeset
|
1258 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
|
1259 && 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
|
1260 { |
5a042519bfe7
Upstream: limited next_upstream time and tries when resolving DNS.
Gu Feng <flygoast@126.com>
parents:
5883
diff
changeset
|
1261 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
|
1262 } |
5a042519bfe7
Upstream: limited next_upstream time and tries when resolving DNS.
Gu Feng <flygoast@126.com>
parents:
5883
diff
changeset
|
1263 |
3169
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
1264 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
|
1265 |
d3c15c7831eb
Upstream: call ngx_http_run_posted_requests() on resolve errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5104
diff
changeset
|
1266 failed: |
d3c15c7831eb
Upstream: call ngx_http_run_posted_requests() on resolve errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5104
diff
changeset
|
1267 |
7041
6169dbad37d8
Upstream: fixed running posted requests (ticket #788).
Roman Arutyunyan <arut@nginx.com>
parents:
7018
diff
changeset
|
1268 if (run_posted) { |
6169dbad37d8
Upstream: fixed running posted requests (ticket #788).
Roman Arutyunyan <arut@nginx.com>
parents:
7018
diff
changeset
|
1269 ngx_http_run_posted_requests(c); |
6169dbad37d8
Upstream: fixed running posted requests (ticket #788).
Roman Arutyunyan <arut@nginx.com>
parents:
7018
diff
changeset
|
1270 } |
1658 | 1271 } |
1272 | |
1273 | |
1274 static void | |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1275 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
|
1276 { |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1277 ngx_connection_t *c; |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1278 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
|
1279 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
|
1280 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1281 c = ev->data; |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1282 r = c->data; |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1283 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1284 u = r->upstream; |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1285 c = r->connection; |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1286 |
5928
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5911
diff
changeset
|
1287 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
|
1288 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1289 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
|
1290 "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
|
1291 |
6961
903fb1ddc07f
Moved handling of wev->delayed to the connection event handler.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6950
diff
changeset
|
1292 if (ev->delayed && ev->timedout) { |
903fb1ddc07f
Moved handling of wev->delayed to the connection event handler.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6950
diff
changeset
|
1293 ev->delayed = 0; |
903fb1ddc07f
Moved handling of wev->delayed to the connection event handler.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6950
diff
changeset
|
1294 ev->timedout = 0; |
903fb1ddc07f
Moved handling of wev->delayed to the connection event handler.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6950
diff
changeset
|
1295 } |
903fb1ddc07f
Moved handling of wev->delayed to the connection event handler.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6950
diff
changeset
|
1296 |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1297 if (ev->write) { |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1298 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
|
1299 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1300 } else { |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1301 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
|
1302 } |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1303 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1304 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
|
1305 } |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1306 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1307 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1308 static void |
509 | 1309 ngx_http_upstream_rd_check_broken_connection(ngx_http_request_t *r) |
1310 { | |
1311 ngx_http_upstream_check_broken_connection(r, r->connection->read); | |
1312 } | |
1313 | |
1314 | |
1315 static void | |
1316 ngx_http_upstream_wr_check_broken_connection(ngx_http_request_t *r) | |
1317 { | |
1318 ngx_http_upstream_check_broken_connection(r, r->connection->write); | |
1319 } | |
1320 | |
1321 | |
1322 static void | |
1323 ngx_http_upstream_check_broken_connection(ngx_http_request_t *r, | |
1324 ngx_event_t *ev) | |
479 | 1325 { |
1326 int n; | |
1327 char buf[1]; | |
577 | 1328 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
|
1329 ngx_int_t event; |
479 | 1330 ngx_connection_t *c; |
1331 ngx_http_upstream_t *u; | |
1332 | |
527 | 1333 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, ev->log, 0, |
1334 "http upstream check client, write event:%d, \"%V\"", | |
1335 ev->write, &r->uri); | |
479 | 1336 |
509 | 1337 c = r->connection; |
483 | 1338 u = r->upstream; |
1339 | |
583 | 1340 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
|
1341 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
|
1342 |
6ad4bba6313e
delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents:
2805
diff
changeset
|
1343 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
|
1344 |
6ad4bba6313e
delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents:
2805
diff
changeset
|
1345 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
|
1346 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
|
1347 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
|
1348 return; |
6ad4bba6313e
delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents:
2805
diff
changeset
|
1349 } |
6ad4bba6313e
delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents:
2805
diff
changeset
|
1350 } |
6ad4bba6313e
delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents:
2805
diff
changeset
|
1351 |
2757
9cc973b46af1
get a full response if the response is cacheable or storable even
Igor Sysoev <igor@sysoev.ru>
parents:
2708
diff
changeset
|
1352 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
|
1353 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
|
1354 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
|
1355 } |
2807
6ad4bba6313e
delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents:
2805
diff
changeset
|
1356 |
527 | 1357 return; |
1358 } | |
1359 | |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
6242
diff
changeset
|
1360 #if (NGX_HTTP_V2) |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
6242
diff
changeset
|
1361 if (r->stream) { |
5121
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
5113
diff
changeset
|
1362 return; |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
5113
diff
changeset
|
1363 } |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
5113
diff
changeset
|
1364 #endif |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
5113
diff
changeset
|
1365 |
8059
a748095bf94e
HTTP/3: special handling of client errors in the upstream module.
Roman Arutyunyan <arut@nginx.com>
parents:
7982
diff
changeset
|
1366 #if (NGX_HTTP_QUIC) |
a748095bf94e
HTTP/3: special handling of client errors in the upstream module.
Roman Arutyunyan <arut@nginx.com>
parents:
7982
diff
changeset
|
1367 |
8200
279ad36f2f4b
QUIC: renamed c->qs to c->quic.
Roman Arutyunyan <arut@nginx.com>
parents:
8143
diff
changeset
|
1368 if (c->quic) { |
8059
a748095bf94e
HTTP/3: special handling of client errors in the upstream module.
Roman Arutyunyan <arut@nginx.com>
parents:
7982
diff
changeset
|
1369 if (c->write->error) { |
a748095bf94e
HTTP/3: special handling of client errors in the upstream module.
Roman Arutyunyan <arut@nginx.com>
parents:
7982
diff
changeset
|
1370 ngx_http_upstream_finalize_request(r, u, |
a748095bf94e
HTTP/3: special handling of client errors in the upstream module.
Roman Arutyunyan <arut@nginx.com>
parents:
7982
diff
changeset
|
1371 NGX_HTTP_CLIENT_CLOSED_REQUEST); |
a748095bf94e
HTTP/3: special handling of client errors in the upstream module.
Roman Arutyunyan <arut@nginx.com>
parents:
7982
diff
changeset
|
1372 } |
a748095bf94e
HTTP/3: special handling of client errors in the upstream module.
Roman Arutyunyan <arut@nginx.com>
parents:
7982
diff
changeset
|
1373 |
a748095bf94e
HTTP/3: special handling of client errors in the upstream module.
Roman Arutyunyan <arut@nginx.com>
parents:
7982
diff
changeset
|
1374 return; |
a748095bf94e
HTTP/3: special handling of client errors in the upstream module.
Roman Arutyunyan <arut@nginx.com>
parents:
7982
diff
changeset
|
1375 } |
a748095bf94e
HTTP/3: special handling of client errors in the upstream module.
Roman Arutyunyan <arut@nginx.com>
parents:
7982
diff
changeset
|
1376 |
a748095bf94e
HTTP/3: special handling of client errors in the upstream module.
Roman Arutyunyan <arut@nginx.com>
parents:
7982
diff
changeset
|
1377 #endif |
a748095bf94e
HTTP/3: special handling of client errors in the upstream module.
Roman Arutyunyan <arut@nginx.com>
parents:
7982
diff
changeset
|
1378 |
479 | 1379 #if (NGX_HAVE_KQUEUE) |
1380 | |
1381 if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) { | |
1382 | |
1383 if (!ev->pending_eof) { | |
1384 return; | |
1385 } | |
1386 | |
1387 ev->eof = 1; | |
583 | 1388 c->error = 1; |
479 | 1389 |
1390 if (ev->kq_errno) { | |
1391 ev->error = 1; | |
1392 } | |
1393 | |
2757
9cc973b46af1
get a full response if the response is cacheable or storable even
Igor Sysoev <igor@sysoev.ru>
parents:
2708
diff
changeset
|
1394 if (!u->cacheable && u->peer.connection) { |
479 | 1395 ngx_log_error(NGX_LOG_INFO, ev->log, ev->kq_errno, |
4182 | 1396 "kevent() reported that client prematurely closed " |
527 | 1397 "connection, so upstream connection is closed too"); |
479 | 1398 ngx_http_upstream_finalize_request(r, u, |
1399 NGX_HTTP_CLIENT_CLOSED_REQUEST); | |
1400 return; | |
1401 } | |
1402 | |
1403 ngx_log_error(NGX_LOG_INFO, ev->log, ev->kq_errno, | |
4182 | 1404 "kevent() reported that client prematurely closed " |
1405 "connection"); | |
479 | 1406 |
1407 if (u->peer.connection == NULL) { | |
1408 ngx_http_upstream_finalize_request(r, u, | |
1409 NGX_HTTP_CLIENT_CLOSED_REQUEST); | |
1410 } | |
1411 | |
1412 return; | |
1413 } | |
1414 | |
1415 #endif | |
1416 | |
5373
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1417 #if (NGX_HAVE_EPOLLRDHUP) |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1418 |
6536
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6530
diff
changeset
|
1419 if ((ngx_event_flags & NGX_USE_EPOLL_EVENT) && ngx_use_epoll_rdhup) { |
5373
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1420 socklen_t len; |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1421 |
6536
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6530
diff
changeset
|
1422 if (!ev->pending_eof) { |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6530
diff
changeset
|
1423 return; |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6530
diff
changeset
|
1424 } |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6530
diff
changeset
|
1425 |
5373
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1426 ev->eof = 1; |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1427 c->error = 1; |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1428 |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1429 err = 0; |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1430 len = sizeof(ngx_err_t); |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1431 |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1432 /* |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1433 * 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
|
1434 * 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
|
1435 */ |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1436 |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1437 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
|
1438 == -1) |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1439 { |
5557
188481078faf
Use ngx_socket_errno where appropriate.
Piotr Sikora <piotr@cloudflare.com>
parents:
5546
diff
changeset
|
1440 err = ngx_socket_errno; |
5373
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1441 } |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1442 |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1443 if (err) { |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1444 ev->error = 1; |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1445 } |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1446 |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1447 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
|
1448 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
|
1449 "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
|
1450 "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
|
1451 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
|
1452 NGX_HTTP_CLIENT_CLOSED_REQUEST); |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1453 return; |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1454 } |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1455 |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1456 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
|
1457 "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
|
1458 "connection"); |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1459 |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1460 if (u->peer.connection == NULL) { |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1461 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
|
1462 NGX_HTTP_CLIENT_CLOSED_REQUEST); |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1463 } |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1464 |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1465 return; |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1466 } |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1467 |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1468 #endif |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1469 |
479 | 1470 n = recv(c->fd, buf, 1, MSG_PEEK); |
1471 | |
1472 err = ngx_socket_errno; | |
1473 | |
1109 | 1474 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ev->log, err, |
1475 "http upstream recv(): %d", n); | |
1476 | |
479 | 1477 if (ev->write && (n >= 0 || err == NGX_EAGAIN)) { |
1478 return; | |
1479 } | |
1480 | |
1481 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
|
1482 |
6ad4bba6313e
delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents:
2805
diff
changeset
|
1483 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
|
1484 |
6ad4bba6313e
delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents:
2805
diff
changeset
|
1485 if (ngx_del_event(ev, event, 0) != NGX_OK) { |
479 | 1486 ngx_http_upstream_finalize_request(r, u, |
1487 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
1488 return; | |
1489 } | |
1490 } | |
1491 | |
1492 if (n > 0) { | |
1493 return; | |
1494 } | |
1495 | |
1496 if (n == -1) { | |
1497 if (err == NGX_EAGAIN) { | |
1498 return; | |
1499 } | |
1500 | |
1501 ev->error = 1; | |
1502 | |
483 | 1503 } else { /* n == 0 */ |
479 | 1504 err = 0; |
1505 } | |
1506 | |
529 | 1507 ev->eof = 1; |
583 | 1508 c->error = 1; |
529 | 1509 |
2757
9cc973b46af1
get a full response if the response is cacheable or storable even
Igor Sysoev <igor@sysoev.ru>
parents:
2708
diff
changeset
|
1510 if (!u->cacheable && u->peer.connection) { |
479 | 1511 ngx_log_error(NGX_LOG_INFO, ev->log, err, |
4182 | 1512 "client prematurely closed connection, " |
479 | 1513 "so upstream connection is closed too"); |
1514 ngx_http_upstream_finalize_request(r, u, | |
1515 NGX_HTTP_CLIENT_CLOSED_REQUEST); | |
1516 return; | |
1517 } | |
1518 | |
1519 ngx_log_error(NGX_LOG_INFO, ev->log, err, | |
4182 | 1520 "client prematurely closed connection"); |
479 | 1521 |
1522 if (u->peer.connection == NULL) { | |
1523 ngx_http_upstream_finalize_request(r, u, | |
1524 NGX_HTTP_CLIENT_CLOSED_REQUEST); | |
1525 } | |
1526 } | |
1527 | |
1528 | |
487 | 1529 static void |
1530 ngx_http_upstream_connect(ngx_http_request_t *r, ngx_http_upstream_t *u) | |
479 | 1531 { |
591 | 1532 ngx_int_t rc; |
1533 ngx_connection_t *c; | |
479 | 1534 |
483 | 1535 r->connection->log->action = "connecting to upstream"; |
479 | 1536 |
7397
860d3907da1c
Upstream: revised upstream response time variables.
Vladimir Homutov <vl@nginx.com>
parents:
7371
diff
changeset
|
1537 if (u->state && u->state->response_time == (ngx_msec_t) -1) { |
860d3907da1c
Upstream: revised upstream response time variables.
Vladimir Homutov <vl@nginx.com>
parents:
7371
diff
changeset
|
1538 u->state->response_time = ngx_current_msec - u->start_time; |
665 | 1539 } |
1540 | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
1541 u->state = ngx_array_push(r->upstream_states); |
665 | 1542 if (u->state == NULL) { |
1543 ngx_http_upstream_finalize_request(r, u, | |
1544 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
1545 return; | |
1546 } | |
1547 | |
1548 ngx_memzero(u->state, sizeof(ngx_http_upstream_state_t)); | |
1549 | |
7397
860d3907da1c
Upstream: revised upstream response time variables.
Vladimir Homutov <vl@nginx.com>
parents:
7371
diff
changeset
|
1550 u->start_time = ngx_current_msec; |
860d3907da1c
Upstream: revised upstream response time variables.
Vladimir Homutov <vl@nginx.com>
parents:
7371
diff
changeset
|
1551 |
860d3907da1c
Upstream: revised upstream response time variables.
Vladimir Homutov <vl@nginx.com>
parents:
7371
diff
changeset
|
1552 u->state->response_time = (ngx_msec_t) -1; |
6147
74b6ef56ea56
Upstream: $upstream_connect_time.
Ruslan Ermilov <ru@nginx.com>
parents:
6146
diff
changeset
|
1553 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
|
1554 u->state->header_time = (ngx_msec_t) -1; |
665 | 1555 |
479 | 1556 rc = ngx_event_connect_peer(&u->peer); |
1557 | |
1558 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
1559 "http upstream connect: %i", rc); | |
1560 | |
1561 if (rc == NGX_ERROR) { | |
1562 ngx_http_upstream_finalize_request(r, u, | |
1563 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
1564 return; | |
1565 } | |
1566 | |
1707
f3188f6eae1f
$upstream_addr did not contain last address, the bug was introduced in r1659
Igor Sysoev <igor@sysoev.ru>
parents:
1706
diff
changeset
|
1567 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
|
1568 |
543 | 1569 if (rc == NGX_BUSY) { |
1570 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "no live upstreams"); | |
1378 | 1571 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_NOLIVE); |
1572 return; | |
543 | 1573 } |
1574 | |
1378 | 1575 if (rc == NGX_DECLINED) { |
479 | 1576 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR); |
1577 return; | |
1578 } | |
1579 | |
5261
af60a210cb78
Upstream: updated list of ngx_event_connect_peer() return values.
Ruslan Ermilov <ru@nginx.com>
parents:
5231
diff
changeset
|
1580 /* rc == NGX_OK || rc == NGX_AGAIN || rc == NGX_DONE */ |
577 | 1581 |
479 | 1582 c = u->peer.connection; |
1583 | |
7340
70c6b08973a0
Upstream keepalive: keepalive_requests directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7320
diff
changeset
|
1584 c->requests++; |
70c6b08973a0
Upstream keepalive: keepalive_requests directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7320
diff
changeset
|
1585 |
479 | 1586 c->data = r; |
591 | 1587 |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1588 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
|
1589 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
|
1590 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1591 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
|
1592 u->read_event_handler = ngx_http_upstream_process_header; |
479 | 1593 |
1397
6c25a49e548a
upstream sendfile bit was overridden by r->connection->sendfile
Igor Sysoev <igor@sysoev.ru>
parents:
1378
diff
changeset
|
1594 c->sendfile &= r->connection->sendfile; |
1958 | 1595 u->output.sendfile = c->sendfile; |
479 | 1596 |
7306
8eab05b83dde
Upstream: fixed unexpected tcp_nopush usage on peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7297
diff
changeset
|
1597 if (r->connection->tcp_nopush == NGX_TCP_NOPUSH_DISABLED) { |
8eab05b83dde
Upstream: fixed unexpected tcp_nopush usage on peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7297
diff
changeset
|
1598 c->tcp_nopush = NGX_TCP_NOPUSH_DISABLED; |
8eab05b83dde
Upstream: fixed unexpected tcp_nopush usage on peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7297
diff
changeset
|
1599 } |
8eab05b83dde
Upstream: fixed unexpected tcp_nopush usage on peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7297
diff
changeset
|
1600 |
4116
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1601 if (c->pool == NULL) { |
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1602 |
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1603 /* 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
|
1604 |
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1605 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
|
1606 if (c->pool == NULL) { |
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1607 ngx_http_upstream_finalize_request(r, u, |
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1608 NGX_HTTP_INTERNAL_SERVER_ERROR); |
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1609 return; |
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1610 } |
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1611 } |
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1612 |
2847 | 1613 c->log = r->connection->log; |
4116
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1614 c->pool->log = c->log; |
2847 | 1615 c->read->log = c->log; |
1616 c->write->log = c->log; | |
479 | 1617 |
1618 /* init or reinit the ngx_output_chain() and ngx_chain_writer() contexts */ | |
1619 | |
1620 u->writer.out = NULL; | |
1621 u->writer.last = &u->writer.out; | |
1622 u->writer.connection = c; | |
1623 u->writer.limit = 0; | |
1624 | |
1625 if (u->request_sent) { | |
509 | 1626 if (ngx_http_upstream_reinit(r, u) != NGX_OK) { |
1627 ngx_http_upstream_finalize_request(r, u, | |
1628 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
1629 return; | |
1630 } | |
479 | 1631 } |
1632 | |
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
|
1633 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
|
1634 && 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
|
1635 && 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
|
1636 && 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
|
1637 { |
573 | 1638 /* |
1639 * 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
|
1640 * the subrequests should allocate their own temporary bufs |
573 | 1641 */ |
1642 | |
1643 u->output.free = ngx_alloc_chain_link(r->pool); | |
1644 if (u->output.free == NULL) { | |
1645 ngx_http_upstream_finalize_request(r, u, | |
1646 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
1647 return; | |
479 | 1648 } |
573 | 1649 |
1650 u->output.free->buf = r->request_body->buf; | |
1651 u->output.free->next = NULL; | |
1652 u->output.allocated = 1; | |
1653 | |
1654 r->request_body->buf->pos = r->request_body->buf->start; | |
1655 r->request_body->buf->last = r->request_body->buf->start; | |
1656 r->request_body->buf->tag = u->output.tag; | |
479 | 1657 } |
1658 | |
1659 u->request_sent = 0; | |
6332
78b4e10b4367
Upstream: don't keep connections on early responses (ticket #669).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6326
diff
changeset
|
1660 u->request_body_sent = 0; |
7231
22f7bdbd96d3
Upstream: u->request_body_blocked flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7230
diff
changeset
|
1661 u->request_body_blocked = 0; |
479 | 1662 |
1663 if (rc == NGX_AGAIN) { | |
1664 ngx_add_timer(c->write, u->conf->connect_timeout); | |
1665 return; | |
1666 } | |
1667 | |
577 | 1668 #if (NGX_HTTP_SSL) |
1669 | |
1658 | 1670 if (u->ssl && c->ssl == NULL) { |
591 | 1671 ngx_http_upstream_ssl_init_connection(r, u, c); |
577 | 1672 return; |
1673 } | |
1674 | |
1675 #endif | |
1676 | |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1677 ngx_http_upstream_send_request(r, u, 1); |
479 | 1678 } |
1679 | |
1680 | |
577 | 1681 #if (NGX_HTTP_SSL) |
1682 | |
1683 static void | |
591 | 1684 ngx_http_upstream_ssl_init_connection(ngx_http_request_t *r, |
1685 ngx_http_upstream_t *u, ngx_connection_t *c) | |
1686 { | |
6068
643f2ce02f1c
Upstream: abbreviated SSL handshake may interact badly with Nagle.
Ruslan Ermilov <ru@nginx.com>
parents:
6050
diff
changeset
|
1687 ngx_int_t rc; |
643f2ce02f1c
Upstream: abbreviated SSL handshake may interact badly with Nagle.
Ruslan Ermilov <ru@nginx.com>
parents:
6050
diff
changeset
|
1688 ngx_http_core_loc_conf_t *clcf; |
591 | 1689 |
5305
12b750d35162
Upstream: reliably detect connection failures with SSL peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5304
diff
changeset
|
1690 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
|
1691 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
|
1692 return; |
12b750d35162
Upstream: reliably detect connection failures with SSL peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5304
diff
changeset
|
1693 } |
12b750d35162
Upstream: reliably detect connection failures with SSL peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5304
diff
changeset
|
1694 |
591 | 1695 if (ngx_ssl_create_connection(u->conf->ssl, c, |
1696 NGX_SSL_BUFFER|NGX_SSL_CLIENT) | |
2536
a6d6d762c554
small optimization: " == NGX_ERROR" > " != NGX_OK"
Igor Sysoev <igor@sysoev.ru>
parents:
2463
diff
changeset
|
1697 != NGX_OK) |
591 | 1698 { |
1699 ngx_http_upstream_finalize_request(r, u, | |
1700 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
1701 return; | |
1702 } | |
1703 | |
1704 c->sendfile = 0; | |
619 | 1705 u->output.sendfile = 0; |
591 | 1706 |
5661
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1707 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
|
1708 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
|
1709 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
|
1710 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
|
1711 return; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1712 } |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1713 } |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1714 |
2184 | 1715 if (u->conf->ssl_session_reuse) { |
7320
696df3ac27ac
SSL: save sessions for upstream peers using a callback function.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7307
diff
changeset
|
1716 c->ssl->save_session = ngx_http_upstream_ssl_save_session; |
696df3ac27ac
SSL: save sessions for upstream peers using a callback function.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7307
diff
changeset
|
1717 |
2184 | 1718 if (u->peer.set_session(&u->peer, u->peer.data) != NGX_OK) { |
1719 ngx_http_upstream_finalize_request(r, u, | |
1720 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
1721 return; | |
1722 } | |
6068
643f2ce02f1c
Upstream: abbreviated SSL handshake may interact badly with Nagle.
Ruslan Ermilov <ru@nginx.com>
parents:
6050
diff
changeset
|
1723 |
643f2ce02f1c
Upstream: abbreviated SSL handshake may interact badly with Nagle.
Ruslan Ermilov <ru@nginx.com>
parents:
6050
diff
changeset
|
1724 /* 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
|
1725 |
643f2ce02f1c
Upstream: abbreviated SSL handshake may interact badly with Nagle.
Ruslan Ermilov <ru@nginx.com>
parents:
6050
diff
changeset
|
1726 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
|
1727 |
7007
ed1101bbf19f
Introduced ngx_tcp_nodelay().
Ruslan Ermilov <ru@nginx.com>
parents:
7006
diff
changeset
|
1728 if (clcf->tcp_nodelay && ngx_tcp_nodelay(c) != NGX_OK) { |
ed1101bbf19f
Introduced ngx_tcp_nodelay().
Ruslan Ermilov <ru@nginx.com>
parents:
7006
diff
changeset
|
1729 ngx_http_upstream_finalize_request(r, u, |
6068
643f2ce02f1c
Upstream: abbreviated SSL handshake may interact badly with Nagle.
Ruslan Ermilov <ru@nginx.com>
parents:
6050
diff
changeset
|
1730 NGX_HTTP_INTERNAL_SERVER_ERROR); |
7007
ed1101bbf19f
Introduced ngx_tcp_nodelay().
Ruslan Ermilov <ru@nginx.com>
parents:
7006
diff
changeset
|
1731 return; |
6068
643f2ce02f1c
Upstream: abbreviated SSL handshake may interact badly with Nagle.
Ruslan Ermilov <ru@nginx.com>
parents:
6050
diff
changeset
|
1732 } |
591 | 1733 } |
1734 | |
641 | 1735 r->connection->log->action = "SSL handshaking to upstream"; |
1736 | |
591 | 1737 rc = ngx_ssl_handshake(c); |
1738 | |
1739 if (rc == NGX_AGAIN) { | |
5774
9bf58a3da25b
Upstream: SSL handshake timeouts.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5770
diff
changeset
|
1740 |
9bf58a3da25b
Upstream: SSL handshake timeouts.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5770
diff
changeset
|
1741 if (!c->write->timer_set) { |
9bf58a3da25b
Upstream: SSL handshake timeouts.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5770
diff
changeset
|
1742 ngx_add_timer(c->write, u->conf->connect_timeout); |
9bf58a3da25b
Upstream: SSL handshake timeouts.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5770
diff
changeset
|
1743 } |
9bf58a3da25b
Upstream: SSL handshake timeouts.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5770
diff
changeset
|
1744 |
7042
bd2f97a3aecc
Upstream: introduced ngx_http_upstream_ssl_handshake_handler().
Maxim Dounin <mdounin@mdounin.ru>
parents:
7041
diff
changeset
|
1745 c->ssl->handler = ngx_http_upstream_ssl_handshake_handler; |
591 | 1746 return; |
1747 } | |
1748 | |
7042
bd2f97a3aecc
Upstream: introduced ngx_http_upstream_ssl_handshake_handler().
Maxim Dounin <mdounin@mdounin.ru>
parents:
7041
diff
changeset
|
1749 ngx_http_upstream_ssl_handshake(r, u, c); |
591 | 1750 } |
1751 | |
1752 | |
1753 static void | |
7042
bd2f97a3aecc
Upstream: introduced ngx_http_upstream_ssl_handshake_handler().
Maxim Dounin <mdounin@mdounin.ru>
parents:
7041
diff
changeset
|
1754 ngx_http_upstream_ssl_handshake_handler(ngx_connection_t *c) |
577 | 1755 { |
1756 ngx_http_request_t *r; | |
1757 ngx_http_upstream_t *u; | |
1758 | |
1759 r = c->data; | |
7042
bd2f97a3aecc
Upstream: introduced ngx_http_upstream_ssl_handshake_handler().
Maxim Dounin <mdounin@mdounin.ru>
parents:
7041
diff
changeset
|
1760 |
577 | 1761 u = r->upstream; |
7042
bd2f97a3aecc
Upstream: introduced ngx_http_upstream_ssl_handshake_handler().
Maxim Dounin <mdounin@mdounin.ru>
parents:
7041
diff
changeset
|
1762 c = r->connection; |
577 | 1763 |
5928
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5911
diff
changeset
|
1764 ngx_http_set_log_request(c->log, r); |
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5911
diff
changeset
|
1765 |
7042
bd2f97a3aecc
Upstream: introduced ngx_http_upstream_ssl_handshake_handler().
Maxim Dounin <mdounin@mdounin.ru>
parents:
7041
diff
changeset
|
1766 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, |
bd2f97a3aecc
Upstream: introduced ngx_http_upstream_ssl_handshake_handler().
Maxim Dounin <mdounin@mdounin.ru>
parents:
7041
diff
changeset
|
1767 "http upstream ssl handshake: \"%V?%V\"", |
bd2f97a3aecc
Upstream: introduced ngx_http_upstream_ssl_handshake_handler().
Maxim Dounin <mdounin@mdounin.ru>
parents:
7041
diff
changeset
|
1768 &r->uri, &r->args); |
bd2f97a3aecc
Upstream: introduced ngx_http_upstream_ssl_handshake_handler().
Maxim Dounin <mdounin@mdounin.ru>
parents:
7041
diff
changeset
|
1769 |
bd2f97a3aecc
Upstream: introduced ngx_http_upstream_ssl_handshake_handler().
Maxim Dounin <mdounin@mdounin.ru>
parents:
7041
diff
changeset
|
1770 ngx_http_upstream_ssl_handshake(r, u, u->peer.connection); |
bd2f97a3aecc
Upstream: introduced ngx_http_upstream_ssl_handshake_handler().
Maxim Dounin <mdounin@mdounin.ru>
parents:
7041
diff
changeset
|
1771 |
bd2f97a3aecc
Upstream: introduced ngx_http_upstream_ssl_handshake_handler().
Maxim Dounin <mdounin@mdounin.ru>
parents:
7041
diff
changeset
|
1772 ngx_http_run_posted_requests(c); |
bd2f97a3aecc
Upstream: introduced ngx_http_upstream_ssl_handshake_handler().
Maxim Dounin <mdounin@mdounin.ru>
parents:
7041
diff
changeset
|
1773 } |
bd2f97a3aecc
Upstream: introduced ngx_http_upstream_ssl_handshake_handler().
Maxim Dounin <mdounin@mdounin.ru>
parents:
7041
diff
changeset
|
1774 |
bd2f97a3aecc
Upstream: introduced ngx_http_upstream_ssl_handshake_handler().
Maxim Dounin <mdounin@mdounin.ru>
parents:
7041
diff
changeset
|
1775 |
bd2f97a3aecc
Upstream: introduced ngx_http_upstream_ssl_handshake_handler().
Maxim Dounin <mdounin@mdounin.ru>
parents:
7041
diff
changeset
|
1776 static void |
bd2f97a3aecc
Upstream: introduced ngx_http_upstream_ssl_handshake_handler().
Maxim Dounin <mdounin@mdounin.ru>
parents:
7041
diff
changeset
|
1777 ngx_http_upstream_ssl_handshake(ngx_http_request_t *r, ngx_http_upstream_t *u, |
bd2f97a3aecc
Upstream: introduced ngx_http_upstream_ssl_handshake_handler().
Maxim Dounin <mdounin@mdounin.ru>
parents:
7041
diff
changeset
|
1778 ngx_connection_t *c) |
bd2f97a3aecc
Upstream: introduced ngx_http_upstream_ssl_handshake_handler().
Maxim Dounin <mdounin@mdounin.ru>
parents:
7041
diff
changeset
|
1779 { |
bd2f97a3aecc
Upstream: introduced ngx_http_upstream_ssl_handshake_handler().
Maxim Dounin <mdounin@mdounin.ru>
parents:
7041
diff
changeset
|
1780 long rc; |
bd2f97a3aecc
Upstream: introduced ngx_http_upstream_ssl_handshake_handler().
Maxim Dounin <mdounin@mdounin.ru>
parents:
7041
diff
changeset
|
1781 |
577 | 1782 if (c->ssl->handshaked) { |
1783 | |
5661
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1784 if (u->conf->ssl_verify) { |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1785 rc = SSL_get_verify_result(c->ssl->connection); |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1786 |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1787 if (rc != X509_V_OK) { |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1788 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
|
1789 "upstream SSL certificate verify error: (%l:%s)", |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1790 rc, X509_verify_cert_error_string(rc)); |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1791 goto failed; |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1792 } |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1793 |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1794 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
|
1795 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
|
1796 "upstream SSL certificate does not match \"%V\"", |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1797 &u->ssl_name); |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1798 goto failed; |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1799 } |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1800 } |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1801 |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1802 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
|
1803 c->read->handler = ngx_http_upstream_handler; |
577 | 1804 |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1805 ngx_http_upstream_send_request(r, u, 1); |
577 | 1806 |
1807 return; | |
1808 } | |
1809 | |
6799
d8d037f20484
Upstream: handling of upstream SSL handshake timeouts.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6795
diff
changeset
|
1810 if (c->write->timedout) { |
d8d037f20484
Upstream: handling of upstream SSL handshake timeouts.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6795
diff
changeset
|
1811 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_TIMEOUT); |
d8d037f20484
Upstream: handling of upstream SSL handshake timeouts.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6795
diff
changeset
|
1812 return; |
d8d037f20484
Upstream: handling of upstream SSL handshake timeouts.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6795
diff
changeset
|
1813 } |
d8d037f20484
Upstream: handling of upstream SSL handshake timeouts.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6795
diff
changeset
|
1814 |
5661
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1815 failed: |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1816 |
577 | 1817 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR); |
1818 } | |
1819 | |
5660
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1820 |
7320
696df3ac27ac
SSL: save sessions for upstream peers using a callback function.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7307
diff
changeset
|
1821 static void |
696df3ac27ac
SSL: save sessions for upstream peers using a callback function.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7307
diff
changeset
|
1822 ngx_http_upstream_ssl_save_session(ngx_connection_t *c) |
696df3ac27ac
SSL: save sessions for upstream peers using a callback function.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7307
diff
changeset
|
1823 { |
696df3ac27ac
SSL: save sessions for upstream peers using a callback function.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7307
diff
changeset
|
1824 ngx_http_request_t *r; |
696df3ac27ac
SSL: save sessions for upstream peers using a callback function.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7307
diff
changeset
|
1825 ngx_http_upstream_t *u; |
696df3ac27ac
SSL: save sessions for upstream peers using a callback function.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7307
diff
changeset
|
1826 |
696df3ac27ac
SSL: save sessions for upstream peers using a callback function.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7307
diff
changeset
|
1827 if (c->idle) { |
696df3ac27ac
SSL: save sessions for upstream peers using a callback function.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7307
diff
changeset
|
1828 return; |
696df3ac27ac
SSL: save sessions for upstream peers using a callback function.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7307
diff
changeset
|
1829 } |
696df3ac27ac
SSL: save sessions for upstream peers using a callback function.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7307
diff
changeset
|
1830 |
696df3ac27ac
SSL: save sessions for upstream peers using a callback function.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7307
diff
changeset
|
1831 r = c->data; |
696df3ac27ac
SSL: save sessions for upstream peers using a callback function.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7307
diff
changeset
|
1832 |
696df3ac27ac
SSL: save sessions for upstream peers using a callback function.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7307
diff
changeset
|
1833 u = r->upstream; |
696df3ac27ac
SSL: save sessions for upstream peers using a callback function.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7307
diff
changeset
|
1834 c = r->connection; |
696df3ac27ac
SSL: save sessions for upstream peers using a callback function.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7307
diff
changeset
|
1835 |
696df3ac27ac
SSL: save sessions for upstream peers using a callback function.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7307
diff
changeset
|
1836 ngx_http_set_log_request(c->log, r); |
696df3ac27ac
SSL: save sessions for upstream peers using a callback function.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7307
diff
changeset
|
1837 |
696df3ac27ac
SSL: save sessions for upstream peers using a callback function.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7307
diff
changeset
|
1838 u->peer.save_session(&u->peer, u->peer.data); |
696df3ac27ac
SSL: save sessions for upstream peers using a callback function.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7307
diff
changeset
|
1839 } |
696df3ac27ac
SSL: save sessions for upstream peers using a callback function.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7307
diff
changeset
|
1840 |
696df3ac27ac
SSL: save sessions for upstream peers using a callback function.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7307
diff
changeset
|
1841 |
5660
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1842 static ngx_int_t |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1843 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
|
1844 ngx_connection_t *c) |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1845 { |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1846 u_char *p, *last; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1847 ngx_str_t name; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1848 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1849 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
|
1850 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
|
1851 return NGX_ERROR; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1852 } |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1853 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1854 } else { |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1855 name = u->ssl_name; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1856 } |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1857 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1858 if (name.len == 0) { |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1859 goto done; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1860 } |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1861 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1862 /* |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1863 * 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
|
1864 * 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
|
1865 */ |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1866 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1867 p = name.data; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1868 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
|
1869 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1870 if (*p == '[') { |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1871 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
|
1872 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1873 if (p == NULL) { |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1874 p = name.data; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1875 } |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1876 } |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1877 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1878 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
|
1879 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1880 if (p != NULL) { |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1881 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
|
1882 } |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1883 |
5661
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1884 if (!u->conf->ssl_server_name) { |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1885 goto done; |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1886 } |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1887 |
5660
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1888 #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
|
1889 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1890 /* 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
|
1891 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1892 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
|
1893 goto done; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1894 } |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1895 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1896 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
|
1897 goto done; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1898 } |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1899 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1900 /* |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1901 * 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
|
1902 * 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
|
1903 */ |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1904 |
5667
16405e02e612
Upstream: for ssl name, non-aligned memory allocation is enough.
Ruslan Ermilov <ru@nginx.com>
parents:
5661
diff
changeset
|
1905 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
|
1906 if (p == NULL) { |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1907 return NGX_ERROR; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1908 } |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1909 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1910 (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
|
1911 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1912 name.data = p; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1913 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1914 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
|
1915 "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
|
1916 |
6777
563a1ee345a4
SSL: compatibility with BoringSSL.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6745
diff
changeset
|
1917 if (SSL_set_tlsext_host_name(c->ssl->connection, |
563a1ee345a4
SSL: compatibility with BoringSSL.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6745
diff
changeset
|
1918 (char *) name.data) |
563a1ee345a4
SSL: compatibility with BoringSSL.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6745
diff
changeset
|
1919 == 0) |
563a1ee345a4
SSL: compatibility with BoringSSL.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6745
diff
changeset
|
1920 { |
5660
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1921 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
|
1922 "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
|
1923 return NGX_ERROR; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1924 } |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1925 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1926 #endif |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1927 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1928 done: |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1929 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1930 u->ssl_name = name; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1931 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1932 return NGX_OK; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1933 } |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1934 |
577 | 1935 #endif |
1936 | |
1937 | |
509 | 1938 static ngx_int_t |
487 | 1939 ngx_http_upstream_reinit(ngx_http_request_t *r, ngx_http_upstream_t *u) |
479 | 1940 { |
5848
106a8bfa4f42
Upstream: fixed file buffers reinit in ngx_http_upstream_reinit().
Roman Arutyunyan <arut@nginx.com>
parents:
5832
diff
changeset
|
1941 off_t file_pos; |
479 | 1942 ngx_chain_t *cl; |
1943 | |
509 | 1944 if (u->reinit_request(r) != NGX_OK) { |
1945 return NGX_ERROR; | |
1946 } | |
1947 | |
4120
42135dd1f0ea
Upstream: keepalive flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4119
diff
changeset
|
1948 u->keepalive = 0; |
5072
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
1949 u->upgrade = 0; |
7982
05e42236e95b
FastCGI: protection from responses with wrong length.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7981
diff
changeset
|
1950 u->error = 0; |
4120
42135dd1f0ea
Upstream: keepalive flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4119
diff
changeset
|
1951 |
1705 | 1952 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
|
1953 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
|
1954 u->headers_in.last_modified_time = -1; |
1705 | 1955 |
1956 if (ngx_list_init(&u->headers_in.headers, r->pool, 8, | |
591 | 1957 sizeof(ngx_table_elt_t)) |
1958 != NGX_OK) | |
509 | 1959 { |
1960 return NGX_ERROR; | |
479 | 1961 } |
1962 | |
7230
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
1963 if (ngx_list_init(&u->headers_in.trailers, r->pool, 2, |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
1964 sizeof(ngx_table_elt_t)) |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
1965 != NGX_OK) |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
1966 { |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
1967 return NGX_ERROR; |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
1968 } |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
1969 |
479 | 1970 /* reinit the request chain */ |
577 | 1971 |
5848
106a8bfa4f42
Upstream: fixed file buffers reinit in ngx_http_upstream_reinit().
Roman Arutyunyan <arut@nginx.com>
parents:
5832
diff
changeset
|
1972 file_pos = 0; |
106a8bfa4f42
Upstream: fixed file buffers reinit in ngx_http_upstream_reinit().
Roman Arutyunyan <arut@nginx.com>
parents:
5832
diff
changeset
|
1973 |
509 | 1974 for (cl = u->request_bufs; cl; cl = cl->next) { |
479 | 1975 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
|
1976 |
106a8bfa4f42
Upstream: fixed file buffers reinit in ngx_http_upstream_reinit().
Roman Arutyunyan <arut@nginx.com>
parents:
5832
diff
changeset
|
1977 /* 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
|
1978 |
106a8bfa4f42
Upstream: fixed file buffers reinit in ngx_http_upstream_reinit().
Roman Arutyunyan <arut@nginx.com>
parents:
5832
diff
changeset
|
1979 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
|
1980 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
|
1981 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
|
1982 } |
479 | 1983 } |
1984 | |
509 | 1985 /* reinit the subrequest's ngx_output_chain() context */ |
1986 | |
573 | 1987 if (r->request_body && r->request_body->temp_file |
597 | 1988 && r != r->main && u->output.buf) |
573 | 1989 { |
1990 u->output.free = ngx_alloc_chain_link(r->pool); | |
1991 if (u->output.free == NULL) { | |
1992 return NGX_ERROR; | |
509 | 1993 } |
573 | 1994 |
1995 u->output.free->buf = u->output.buf; | |
1996 u->output.free->next = NULL; | |
1997 | |
1998 u->output.buf->pos = u->output.buf->start; | |
1999 u->output.buf->last = u->output.buf->start; | |
509 | 2000 } |
479 | 2001 |
2002 u->output.buf = NULL; | |
2003 u->output.in = NULL; | |
2004 u->output.busy = NULL; | |
577 | 2005 |
581 | 2006 /* reinit u->buffer */ |
577 | 2007 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2008 u->buffer.pos = u->buffer.start; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2009 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2010 #if (NGX_HTTP_CACHE) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2011 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2012 if (r->cache) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2013 u->buffer.pos += r->cache->header_start; |
479 | 2014 } |
509 | 2015 |
479 | 2016 #endif |
2017 | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2018 u->buffer.last = u->buffer.pos; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2019 |
509 | 2020 return NGX_OK; |
479 | 2021 } |
2022 | |
2023 | |
487 | 2024 static void |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2025 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
|
2026 ngx_uint_t do_write) |
479 | 2027 { |
1153
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2028 ngx_int_t rc; |
483 | 2029 ngx_connection_t *c; |
577 | 2030 |
479 | 2031 c = u->peer.connection; |
2032 | |
2033 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
2034 "http upstream send request"); | |
2035 | |
6147
74b6ef56ea56
Upstream: $upstream_connect_time.
Ruslan Ermilov <ru@nginx.com>
parents:
6146
diff
changeset
|
2036 if (u->state->connect_time == (ngx_msec_t) -1) { |
7397
860d3907da1c
Upstream: revised upstream response time variables.
Vladimir Homutov <vl@nginx.com>
parents:
7371
diff
changeset
|
2037 u->state->connect_time = ngx_current_msec - u->start_time; |
6147
74b6ef56ea56
Upstream: $upstream_connect_time.
Ruslan Ermilov <ru@nginx.com>
parents:
6146
diff
changeset
|
2038 } |
74b6ef56ea56
Upstream: $upstream_connect_time.
Ruslan Ermilov <ru@nginx.com>
parents:
6146
diff
changeset
|
2039 |
1153
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2040 if (!u->request_sent && ngx_http_upstream_test_connect(c) != NGX_OK) { |
1166 | 2041 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
|
2042 return; |
479 | 2043 } |
2044 | |
483 | 2045 c->log->action = "sending request to upstream"; |
479 | 2046 |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2047 rc = ngx_http_upstream_send_request_body(r, u, do_write); |
479 | 2048 |
2049 if (rc == NGX_ERROR) { | |
2050 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR); | |
2051 return; | |
2052 } | |
2053 | |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2054 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2055 ngx_http_upstream_finalize_request(r, u, rc); |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2056 return; |
479 | 2057 } |
2058 | |
2059 if (rc == NGX_AGAIN) { | |
7231
22f7bdbd96d3
Upstream: u->request_body_blocked flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7230
diff
changeset
|
2060 if (!c->write->ready || u->request_body_blocked) { |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2061 ngx_add_timer(c->write, u->conf->send_timeout); |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2062 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2063 } else if (c->write->timer_set) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2064 ngx_del_timer(c->write); |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2065 } |
479 | 2066 |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2067 if (ngx_handle_write_event(c->write, u->conf->send_lowat) != NGX_OK) { |
479 | 2068 ngx_http_upstream_finalize_request(r, u, |
2069 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
2070 return; | |
2071 } | |
2072 | |
7307
ece9b5454b8a
Upstream: fixed tcp_nopush with gRPC.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7306
diff
changeset
|
2073 if (c->write->ready && c->tcp_nopush == NGX_TCP_NOPUSH_SET) { |
ece9b5454b8a
Upstream: fixed tcp_nopush with gRPC.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7306
diff
changeset
|
2074 if (ngx_tcp_push(c->fd) == -1) { |
ece9b5454b8a
Upstream: fixed tcp_nopush with gRPC.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7306
diff
changeset
|
2075 ngx_log_error(NGX_LOG_CRIT, c->log, ngx_socket_errno, |
ece9b5454b8a
Upstream: fixed tcp_nopush with gRPC.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7306
diff
changeset
|
2076 ngx_tcp_push_n " failed"); |
ece9b5454b8a
Upstream: fixed tcp_nopush with gRPC.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7306
diff
changeset
|
2077 ngx_http_upstream_finalize_request(r, u, |
ece9b5454b8a
Upstream: fixed tcp_nopush with gRPC.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7306
diff
changeset
|
2078 NGX_HTTP_INTERNAL_SERVER_ERROR); |
ece9b5454b8a
Upstream: fixed tcp_nopush with gRPC.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7306
diff
changeset
|
2079 return; |
ece9b5454b8a
Upstream: fixed tcp_nopush with gRPC.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7306
diff
changeset
|
2080 } |
ece9b5454b8a
Upstream: fixed tcp_nopush with gRPC.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7306
diff
changeset
|
2081 |
ece9b5454b8a
Upstream: fixed tcp_nopush with gRPC.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7306
diff
changeset
|
2082 c->tcp_nopush = NGX_TCP_NOPUSH_UNSET; |
ece9b5454b8a
Upstream: fixed tcp_nopush with gRPC.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7306
diff
changeset
|
2083 } |
ece9b5454b8a
Upstream: fixed tcp_nopush with gRPC.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7306
diff
changeset
|
2084 |
479 | 2085 return; |
2086 } | |
2087 | |
2088 /* rc == NGX_OK */ | |
2089 | |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2090 if (c->write->timer_set) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2091 ngx_del_timer(c->write); |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2092 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2093 |
479 | 2094 if (c->tcp_nopush == NGX_TCP_NOPUSH_SET) { |
7239
400a3412b1e3
Fixed checking ngx_tcp_push() and ngx_tcp_nopush() return values.
Ruslan Ermilov <ru@nginx.com>
parents:
7232
diff
changeset
|
2095 if (ngx_tcp_push(c->fd) == -1) { |
479 | 2096 ngx_log_error(NGX_LOG_CRIT, c->log, ngx_socket_errno, |
2097 ngx_tcp_push_n " failed"); | |
2098 ngx_http_upstream_finalize_request(r, u, | |
2099 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
577 | 2100 return; |
479 | 2101 } |
2102 | |
2103 c->tcp_nopush = NGX_TCP_NOPUSH_UNSET; | |
2104 } | |
577 | 2105 |
7232
a7ed15573ae9
Upstream: u->conf->preserve_output flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7231
diff
changeset
|
2106 if (!u->conf->preserve_output) { |
a7ed15573ae9
Upstream: u->conf->preserve_output flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7231
diff
changeset
|
2107 u->write_event_handler = ngx_http_upstream_dummy_handler; |
a7ed15573ae9
Upstream: u->conf->preserve_output flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7231
diff
changeset
|
2108 } |
479 | 2109 |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2110 if (ngx_handle_write_event(c->write, 0) != NGX_OK) { |
479 | 2111 ngx_http_upstream_finalize_request(r, u, |
2112 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
2113 return; | |
2114 } | |
5745
9d3a9c45fc43
Upstream: fixed handling of write event after sending request.
Valentin Bartenev <vbart@nginx.com>
parents:
5738
diff
changeset
|
2115 |
7260
08f114ed5449
Upstream: fixed u->conf->preserve_output (ticket #1519).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7255
diff
changeset
|
2116 if (!u->request_body_sent) { |
08f114ed5449
Upstream: fixed u->conf->preserve_output (ticket #1519).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7255
diff
changeset
|
2117 u->request_body_sent = 1; |
08f114ed5449
Upstream: fixed u->conf->preserve_output (ticket #1519).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7255
diff
changeset
|
2118 |
08f114ed5449
Upstream: fixed u->conf->preserve_output (ticket #1519).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7255
diff
changeset
|
2119 if (u->header_sent) { |
08f114ed5449
Upstream: fixed u->conf->preserve_output (ticket #1519).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7255
diff
changeset
|
2120 return; |
08f114ed5449
Upstream: fixed u->conf->preserve_output (ticket #1519).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7255
diff
changeset
|
2121 } |
08f114ed5449
Upstream: fixed u->conf->preserve_output (ticket #1519).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7255
diff
changeset
|
2122 |
08f114ed5449
Upstream: fixed u->conf->preserve_output (ticket #1519).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7255
diff
changeset
|
2123 ngx_add_timer(c->read, u->conf->read_timeout); |
08f114ed5449
Upstream: fixed u->conf->preserve_output (ticket #1519).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7255
diff
changeset
|
2124 |
08f114ed5449
Upstream: fixed u->conf->preserve_output (ticket #1519).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7255
diff
changeset
|
2125 if (c->read->ready) { |
08f114ed5449
Upstream: fixed u->conf->preserve_output (ticket #1519).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7255
diff
changeset
|
2126 ngx_http_upstream_process_header(r, u); |
08f114ed5449
Upstream: fixed u->conf->preserve_output (ticket #1519).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7255
diff
changeset
|
2127 return; |
08f114ed5449
Upstream: fixed u->conf->preserve_output (ticket #1519).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7255
diff
changeset
|
2128 } |
5745
9d3a9c45fc43
Upstream: fixed handling of write event after sending request.
Valentin Bartenev <vbart@nginx.com>
parents:
5738
diff
changeset
|
2129 } |
479 | 2130 } |
2131 | |
2132 | |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2133 static ngx_int_t |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2134 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
|
2135 ngx_http_upstream_t *u, ngx_uint_t do_write) |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2136 { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2137 ngx_int_t rc; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2138 ngx_chain_t *out, *cl, *ln; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2139 ngx_connection_t *c; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2140 ngx_http_core_loc_conf_t *clcf; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2141 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2142 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
|
2143 "http upstream send request body"); |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2144 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2145 if (!r->request_body_no_buffering) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2146 |
6474 | 2147 /* buffered request body */ |
2148 | |
2149 if (!u->request_sent) { | |
2150 u->request_sent = 1; | |
2151 out = u->request_bufs; | |
2152 | |
2153 } else { | |
2154 out = NULL; | |
2155 } | |
2156 | |
7231
22f7bdbd96d3
Upstream: u->request_body_blocked flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7230
diff
changeset
|
2157 rc = ngx_output_chain(&u->output, out); |
22f7bdbd96d3
Upstream: u->request_body_blocked flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7230
diff
changeset
|
2158 |
22f7bdbd96d3
Upstream: u->request_body_blocked flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7230
diff
changeset
|
2159 if (rc == NGX_AGAIN) { |
22f7bdbd96d3
Upstream: u->request_body_blocked flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7230
diff
changeset
|
2160 u->request_body_blocked = 1; |
22f7bdbd96d3
Upstream: u->request_body_blocked flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7230
diff
changeset
|
2161 |
22f7bdbd96d3
Upstream: u->request_body_blocked flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7230
diff
changeset
|
2162 } else { |
22f7bdbd96d3
Upstream: u->request_body_blocked flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7230
diff
changeset
|
2163 u->request_body_blocked = 0; |
22f7bdbd96d3
Upstream: u->request_body_blocked flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7230
diff
changeset
|
2164 } |
22f7bdbd96d3
Upstream: u->request_body_blocked flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7230
diff
changeset
|
2165 |
22f7bdbd96d3
Upstream: u->request_body_blocked flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7230
diff
changeset
|
2166 return rc; |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2167 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2168 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2169 if (!u->request_sent) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2170 u->request_sent = 1; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2171 out = u->request_bufs; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2172 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2173 if (r->request_body->bufs) { |
7341
15ea84e65d07
Upstream: fixed request chain traversal (ticket #1618).
Vladimir Homutov <vl@nginx.com>
parents:
7340
diff
changeset
|
2174 for (cl = out; cl->next; cl = cl->next) { /* void */ } |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2175 cl->next = r->request_body->bufs; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2176 r->request_body->bufs = NULL; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2177 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2178 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2179 c = u->peer.connection; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2180 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
|
2181 |
7007
ed1101bbf19f
Introduced ngx_tcp_nodelay().
Ruslan Ermilov <ru@nginx.com>
parents:
7006
diff
changeset
|
2182 if (clcf->tcp_nodelay && ngx_tcp_nodelay(c) != NGX_OK) { |
ed1101bbf19f
Introduced ngx_tcp_nodelay().
Ruslan Ermilov <ru@nginx.com>
parents:
7006
diff
changeset
|
2183 return NGX_ERROR; |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2184 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2185 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2186 r->read_event_handler = ngx_http_upstream_read_request_handler; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2187 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2188 } else { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2189 out = NULL; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2190 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2191 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2192 for ( ;; ) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2193 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2194 if (do_write) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2195 rc = ngx_output_chain(&u->output, out); |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2196 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2197 if (rc == NGX_ERROR) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2198 return NGX_ERROR; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2199 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2200 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2201 while (out) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2202 ln = out; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2203 out = out->next; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2204 ngx_free_chain(r->pool, ln); |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2205 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2206 |
7231
22f7bdbd96d3
Upstream: u->request_body_blocked flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7230
diff
changeset
|
2207 if (rc == NGX_AGAIN) { |
22f7bdbd96d3
Upstream: u->request_body_blocked flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7230
diff
changeset
|
2208 u->request_body_blocked = 1; |
22f7bdbd96d3
Upstream: u->request_body_blocked flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7230
diff
changeset
|
2209 |
22f7bdbd96d3
Upstream: u->request_body_blocked flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7230
diff
changeset
|
2210 } else { |
22f7bdbd96d3
Upstream: u->request_body_blocked flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7230
diff
changeset
|
2211 u->request_body_blocked = 0; |
22f7bdbd96d3
Upstream: u->request_body_blocked flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7230
diff
changeset
|
2212 } |
22f7bdbd96d3
Upstream: u->request_body_blocked flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7230
diff
changeset
|
2213 |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2214 if (rc == NGX_OK && !r->reading_body) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2215 break; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2216 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2217 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2218 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2219 if (r->reading_body) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2220 /* read client request body */ |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2221 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2222 rc = ngx_http_read_unbuffered_request_body(r); |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2223 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2224 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2225 return rc; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2226 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2227 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2228 out = r->request_body->bufs; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2229 r->request_body->bufs = NULL; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2230 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2231 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2232 /* stop if there is nothing to send */ |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2233 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2234 if (out == NULL) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2235 rc = NGX_AGAIN; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2236 break; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2237 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2238 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2239 do_write = 1; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2240 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2241 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2242 if (!r->reading_body) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2243 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
|
2244 r->read_event_handler = |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2245 ngx_http_upstream_rd_check_broken_connection; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2246 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2247 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2248 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2249 return rc; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2250 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2251 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2252 |
487 | 2253 static void |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2254 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
|
2255 ngx_http_upstream_t *u) |
479 | 2256 { |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2257 ngx_connection_t *c; |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2258 |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2259 c = u->peer.connection; |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2260 |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2261 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
479 | 2262 "http upstream send request handler"); |
2263 | |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2264 if (c->write->timedout) { |
479 | 2265 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_TIMEOUT); |
2266 return; | |
2267 } | |
2268 | |
591 | 2269 #if (NGX_HTTP_SSL) |
2270 | |
1658 | 2271 if (u->ssl && c->ssl == NULL) { |
591 | 2272 ngx_http_upstream_ssl_init_connection(r, u, c); |
2273 return; | |
2274 } | |
2275 | |
2276 #endif | |
2277 | |
7232
a7ed15573ae9
Upstream: u->conf->preserve_output flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7231
diff
changeset
|
2278 if (u->header_sent && !u->conf->preserve_output) { |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
2279 u->write_event_handler = ngx_http_upstream_dummy_handler; |
651 | 2280 |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2281 (void) ngx_handle_write_event(c->write, 0); |
651 | 2282 |
2283 return; | |
2284 } | |
2285 | |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2286 ngx_http_upstream_send_request(r, u, 1); |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2287 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2288 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2289 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2290 static void |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2291 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
|
2292 { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2293 ngx_connection_t *c; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2294 ngx_http_upstream_t *u; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2295 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2296 c = r->connection; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2297 u = r->upstream; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2298 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2299 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
|
2300 "http upstream read request handler"); |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2301 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2302 if (c->read->timedout) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2303 c->timedout = 1; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2304 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
|
2305 return; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2306 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2307 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2308 ngx_http_upstream_send_request(r, u, 0); |
479 | 2309 } |
2310 | |
2311 | |
487 | 2312 static void |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2313 ngx_http_upstream_process_header(ngx_http_request_t *r, ngx_http_upstream_t *u) |
479 | 2314 { |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2315 ssize_t n; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2316 ngx_int_t rc; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2317 ngx_connection_t *c; |
479 | 2318 |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2319 c = u->peer.connection; |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2320 |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2321 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, |
483 | 2322 "http upstream process header"); |
479 | 2323 |
483 | 2324 c->log->action = "reading response header from upstream"; |
479 | 2325 |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2326 if (c->read->timedout) { |
479 | 2327 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_TIMEOUT); |
2328 return; | |
2329 } | |
577 | 2330 |
1153
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2331 if (!u->request_sent && ngx_http_upstream_test_connect(c) != NGX_OK) { |
1166 | 2332 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
|
2333 return; |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2334 } |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2335 |
581 | 2336 if (u->buffer.start == NULL) { |
2337 u->buffer.start = ngx_palloc(r->pool, u->conf->buffer_size); | |
2338 if (u->buffer.start == NULL) { | |
479 | 2339 ngx_http_upstream_finalize_request(r, u, |
2340 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
2341 return; | |
2342 } | |
2343 | |
581 | 2344 u->buffer.pos = u->buffer.start; |
2345 u->buffer.last = u->buffer.start; | |
2346 u->buffer.end = u->buffer.start + u->conf->buffer_size; | |
2347 u->buffer.temporary = 1; | |
2348 | |
2349 u->buffer.tag = u->output.tag; | |
479 | 2350 |
1705 | 2351 if (ngx_list_init(&u->headers_in.headers, r->pool, 8, |
581 | 2352 sizeof(ngx_table_elt_t)) |
2353 != NGX_OK) | |
509 | 2354 { |
2355 ngx_http_upstream_finalize_request(r, u, | |
2356 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
2357 return; | |
2358 } | |
2359 | |
7230
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2360 if (ngx_list_init(&u->headers_in.trailers, r->pool, 2, |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2361 sizeof(ngx_table_elt_t)) |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2362 != NGX_OK) |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2363 { |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2364 ngx_http_upstream_finalize_request(r, u, |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2365 NGX_HTTP_INTERNAL_SERVER_ERROR); |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2366 return; |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2367 } |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2368 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2369 #if (NGX_HTTP_CACHE) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2370 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2371 if (r->cache) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2372 u->buffer.pos += r->cache->header_start; |
581 | 2373 u->buffer.last = u->buffer.pos; |
479 | 2374 } |
2375 #endif | |
2376 } | |
2377 | |
2360
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2378 for ( ;; ) { |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2379 |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2380 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
|
2381 |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2382 if (n == NGX_AGAIN) { |
479 | 2383 #if 0 |
2360
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2384 ngx_add_timer(rev, u->read_timeout); |
479 | 2385 #endif |
2386 | |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2387 if (ngx_handle_read_event(c->read, 0) != NGX_OK) { |
2360
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2388 ngx_http_upstream_finalize_request(r, u, |
479 | 2389 NGX_HTTP_INTERNAL_SERVER_ERROR); |
2360
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2390 return; |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2391 } |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2392 |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2393 return; |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2394 } |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2395 |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2396 if (n == 0) { |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2397 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
|
2398 "upstream prematurely closed connection"); |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2399 } |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2400 |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2401 if (n == NGX_ERROR || n == 0) { |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2402 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR); |
479 | 2403 return; |
2404 } | |
2405 | |
6654
c131f20c9562
Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6594
diff
changeset
|
2406 u->state->bytes_received += n; |
c131f20c9562
Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6594
diff
changeset
|
2407 |
2360
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2408 u->buffer.last += n; |
479 | 2409 |
2410 #if 0 | |
2360
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2411 u->valid_header_in = 0; |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2412 |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2413 u->peer.cached = 0; |
479 | 2414 #endif |
2415 | |
2360
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2416 rc = u->process_header(r); |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2417 |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2418 if (rc == NGX_AGAIN) { |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2419 |
4460
6299d1c4dbb4
Upstream: fixed "too big header" check.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
2420 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
|
2421 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
|
2422 "upstream sent too big header"); |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2423 |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2424 ngx_http_upstream_next(r, u, |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2425 NGX_HTTP_UPSTREAM_FT_INVALID_HEADER); |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2426 return; |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2427 } |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2428 |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2429 continue; |
479 | 2430 } |
2431 | |
2360
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2432 break; |
479 | 2433 } |
2434 | |
2435 if (rc == NGX_HTTP_UPSTREAM_INVALID_HEADER) { | |
2436 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_INVALID_HEADER); | |
2437 return; | |
2438 } | |
2439 | |
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
|
2440 if (rc == NGX_ERROR) { |
479 | 2441 ngx_http_upstream_finalize_request(r, u, |
2442 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
2443 return; | |
2444 } | |
2445 | |
2446 /* rc == NGX_OK */ | |
2447 | |
7397
860d3907da1c
Upstream: revised upstream response time variables.
Vladimir Homutov <vl@nginx.com>
parents:
7371
diff
changeset
|
2448 u->state->header_time = ngx_current_msec - u->start_time; |
5964
0a198a517eaf
Upstream: $upstream_header_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
5960
diff
changeset
|
2449 |
5209
07e515e65984
Upstream: allow to intercept responses with status 300.
Ruslan Ermilov <ru@nginx.com>
parents:
5169
diff
changeset
|
2450 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
|
2451 |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2452 if (ngx_http_upstream_test_next(r, u) == NGX_OK) { |
509 | 2453 return; |
2454 } | |
2455 | |
2267
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2456 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
|
2457 return; |
487 | 2458 } |
2459 } | |
2460 | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2461 if (ngx_http_upstream_process_headers(r, u) != NGX_OK) { |
515 | 2462 return; |
2463 } | |
2464 | |
7220
20f139e9ffa8
Generic subrequests in memory.
Roman Arutyunyan <arut@nginx.com>
parents:
7199
diff
changeset
|
2465 ngx_http_upstream_send_response(r, u); |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2466 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2467 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2468 |
1153
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2469 static ngx_int_t |
2268
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2470 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
|
2471 { |
7255
4db4fe3bdeda
Upstream: fixed ngx_http_upstream_test_next() conditions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7239
diff
changeset
|
2472 ngx_msec_t timeout; |
4db4fe3bdeda
Upstream: fixed ngx_http_upstream_test_next() conditions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7239
diff
changeset
|
2473 ngx_uint_t status, mask; |
2268
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2474 ngx_http_upstream_next_t *un; |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2475 |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2476 status = u->headers_in.status_n; |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2477 |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2478 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
|
2479 |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2480 if (status != un->status) { |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2481 continue; |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2482 } |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2483 |
7255
4db4fe3bdeda
Upstream: fixed ngx_http_upstream_test_next() conditions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7239
diff
changeset
|
2484 timeout = u->conf->next_upstream_timeout; |
4db4fe3bdeda
Upstream: fixed ngx_http_upstream_test_next() conditions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7239
diff
changeset
|
2485 |
4db4fe3bdeda
Upstream: fixed ngx_http_upstream_test_next() conditions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7239
diff
changeset
|
2486 if (u->request_sent |
4db4fe3bdeda
Upstream: fixed ngx_http_upstream_test_next() conditions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7239
diff
changeset
|
2487 && (r->method & (NGX_HTTP_POST|NGX_HTTP_LOCK|NGX_HTTP_PATCH))) |
4db4fe3bdeda
Upstream: fixed ngx_http_upstream_test_next() conditions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7239
diff
changeset
|
2488 { |
4db4fe3bdeda
Upstream: fixed ngx_http_upstream_test_next() conditions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7239
diff
changeset
|
2489 mask = un->mask | NGX_HTTP_UPSTREAM_FT_NON_IDEMPOTENT; |
4db4fe3bdeda
Upstream: fixed ngx_http_upstream_test_next() conditions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7239
diff
changeset
|
2490 |
4db4fe3bdeda
Upstream: fixed ngx_http_upstream_test_next() conditions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7239
diff
changeset
|
2491 } else { |
4db4fe3bdeda
Upstream: fixed ngx_http_upstream_test_next() conditions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7239
diff
changeset
|
2492 mask = un->mask; |
4db4fe3bdeda
Upstream: fixed ngx_http_upstream_test_next() conditions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7239
diff
changeset
|
2493 } |
4db4fe3bdeda
Upstream: fixed ngx_http_upstream_test_next() conditions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7239
diff
changeset
|
2494 |
4db4fe3bdeda
Upstream: fixed ngx_http_upstream_test_next() conditions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7239
diff
changeset
|
2495 if (u->peer.tries > 1 |
4db4fe3bdeda
Upstream: fixed ngx_http_upstream_test_next() conditions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7239
diff
changeset
|
2496 && ((u->conf->next_upstream & mask) == mask) |
4db4fe3bdeda
Upstream: fixed ngx_http_upstream_test_next() conditions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7239
diff
changeset
|
2497 && !(u->request_sent && r->request_body_no_buffering) |
4db4fe3bdeda
Upstream: fixed ngx_http_upstream_test_next() conditions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7239
diff
changeset
|
2498 && !(timeout && ngx_current_msec - u->peer.start_time >= timeout)) |
4db4fe3bdeda
Upstream: fixed ngx_http_upstream_test_next() conditions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7239
diff
changeset
|
2499 { |
2268
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2500 ngx_http_upstream_next(r, u, un->mask); |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2501 return NGX_OK; |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2502 } |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2503 |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2504 #if (NGX_HTTP_CACHE) |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2505 |
2952 | 2506 if (u->cache_status == NGX_HTTP_CACHE_EXPIRED |
8047
7015f26aef90
Cache: ignore stale-if-error for 4xx and 5xx codes.
Roman Arutyunyan <arut@nginx.com>
parents:
7982
diff
changeset
|
2507 && (u->conf->cache_use_stale & un->mask)) |
2952 | 2508 { |
2824
d106509491b5
fix building --without-http-cache
Igor Sysoev <igor@sysoev.ru>
parents:
2807
diff
changeset
|
2509 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
|
2510 |
60551422e150
reinit proxy/fastcgi header parser before ngx_http_upstream_cache_send()
Igor Sysoev <igor@sysoev.ru>
parents:
2804
diff
changeset
|
2511 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
|
2512 |
7126
77fe752b4586
Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7125
diff
changeset
|
2513 if (rc != NGX_OK) { |
77fe752b4586
Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7125
diff
changeset
|
2514 ngx_http_upstream_finalize_request(r, u, rc); |
77fe752b4586
Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7125
diff
changeset
|
2515 return NGX_OK; |
77fe752b4586
Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7125
diff
changeset
|
2516 } |
77fe752b4586
Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7125
diff
changeset
|
2517 |
77fe752b4586
Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7125
diff
changeset
|
2518 u->cache_status = NGX_HTTP_CACHE_STALE; |
77fe752b4586
Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7125
diff
changeset
|
2519 rc = ngx_http_upstream_cache_send(r, u); |
77fe752b4586
Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7125
diff
changeset
|
2520 |
77fe752b4586
Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7125
diff
changeset
|
2521 if (rc == NGX_DONE) { |
77fe752b4586
Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7125
diff
changeset
|
2522 return NGX_OK; |
77fe752b4586
Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7125
diff
changeset
|
2523 } |
77fe752b4586
Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7125
diff
changeset
|
2524 |
77fe752b4586
Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7125
diff
changeset
|
2525 if (rc == NGX_HTTP_UPSTREAM_INVALID_HEADER) { |
77fe752b4586
Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7125
diff
changeset
|
2526 rc = NGX_HTTP_INTERNAL_SERVER_ERROR; |
2805
60551422e150
reinit proxy/fastcgi header parser before ngx_http_upstream_cache_send()
Igor Sysoev <igor@sysoev.ru>
parents:
2804
diff
changeset
|
2527 } |
60551422e150
reinit proxy/fastcgi header parser before ngx_http_upstream_cache_send()
Igor Sysoev <igor@sysoev.ru>
parents:
2804
diff
changeset
|
2528 |
60551422e150
reinit proxy/fastcgi header parser before ngx_http_upstream_cache_send()
Igor Sysoev <igor@sysoev.ru>
parents:
2804
diff
changeset
|
2529 ngx_http_upstream_finalize_request(r, u, rc); |
2268
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2530 return NGX_OK; |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2531 } |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2532 |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2533 #endif |
7895
3c8082c3f98a
Upstream: jump out of loop after matching the status code.
Jinhua Tan <312841925@qq.com>
parents:
7538
diff
changeset
|
2534 |
3c8082c3f98a
Upstream: jump out of loop after matching the status code.
Jinhua Tan <312841925@qq.com>
parents:
7538
diff
changeset
|
2535 break; |
2268
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2536 } |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2537 |
5441
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2538 #if (NGX_HTTP_CACHE) |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2539 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2540 if (status == NGX_HTTP_NOT_MODIFIED |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2541 && u->cache_status == NGX_HTTP_CACHE_EXPIRED |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2542 && u->conf->cache_revalidate) |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2543 { |
6905
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
2544 time_t now, valid, updating, error; |
5441
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2545 ngx_int_t rc; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2546 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2547 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
|
2548 "http upstream not modified"); |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2549 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2550 now = ngx_time(); |
6905
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
2551 |
5441
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2552 valid = r->cache->valid_sec; |
6905
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
2553 updating = r->cache->updating_sec; |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
2554 error = r->cache->error_sec; |
5441
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2555 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2556 rc = u->reinit_request(r); |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2557 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2558 if (rc != NGX_OK) { |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2559 ngx_http_upstream_finalize_request(r, u, rc); |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2560 return NGX_OK; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2561 } |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2562 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2563 u->cache_status = NGX_HTTP_CACHE_REVALIDATED; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2564 rc = ngx_http_upstream_cache_send(r, u); |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2565 |
7126
77fe752b4586
Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7125
diff
changeset
|
2566 if (rc == NGX_DONE) { |
77fe752b4586
Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7125
diff
changeset
|
2567 return NGX_OK; |
77fe752b4586
Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7125
diff
changeset
|
2568 } |
77fe752b4586
Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7125
diff
changeset
|
2569 |
77fe752b4586
Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7125
diff
changeset
|
2570 if (rc == NGX_HTTP_UPSTREAM_INVALID_HEADER) { |
77fe752b4586
Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7125
diff
changeset
|
2571 rc = NGX_HTTP_INTERNAL_SERVER_ERROR; |
77fe752b4586
Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7125
diff
changeset
|
2572 } |
77fe752b4586
Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7125
diff
changeset
|
2573 |
5441
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2574 if (valid == 0) { |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2575 valid = r->cache->valid_sec; |
6905
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
2576 updating = r->cache->updating_sec; |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
2577 error = r->cache->error_sec; |
5441
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2578 } |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2579 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2580 if (valid == 0) { |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2581 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
|
2582 u->headers_in.status_n); |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2583 if (valid) { |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2584 valid = now + valid; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2585 } |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2586 } |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2587 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2588 if (valid) { |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2589 r->cache->valid_sec = valid; |
6905
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
2590 r->cache->updating_sec = updating; |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
2591 r->cache->error_sec = error; |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
2592 |
5441
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2593 r->cache->date = now; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2594 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2595 ngx_http_file_cache_update_header(r); |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2596 } |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2597 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2598 ngx_http_upstream_finalize_request(r, u, rc); |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2599 return NGX_OK; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2600 } |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2601 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2602 #endif |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2603 |
2268
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2604 return NGX_DECLINED; |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2605 } |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2606 |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2607 |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2608 static ngx_int_t |
2267
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2609 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
|
2610 ngx_http_upstream_t *u) |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2611 { |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2612 ngx_int_t status; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2613 ngx_uint_t i; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2614 ngx_table_elt_t *h; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2615 ngx_http_err_page_t *err_page; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2616 ngx_http_core_loc_conf_t *clcf; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2617 |
2441
0c117a89f399
in miss case memcached module returned END instead of default 404 page body
Igor Sysoev <igor@sysoev.ru>
parents:
2422
diff
changeset
|
2618 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
|
2619 |
0c117a89f399
in miss case memcached module returned END instead of default 404 page body
Igor Sysoev <igor@sysoev.ru>
parents:
2422
diff
changeset
|
2620 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
|
2621 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
|
2622 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
|
2623 } |
0c117a89f399
in miss case memcached module returned END instead of default 404 page body
Igor Sysoev <igor@sysoev.ru>
parents:
2422
diff
changeset
|
2624 |
2267
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2625 if (!u->conf->intercept_errors) { |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2626 return NGX_DECLINED; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2627 } |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2628 |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2629 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
|
2630 |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2631 if (clcf->error_pages == NULL) { |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2632 return NGX_DECLINED; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2633 } |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2634 |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2635 err_page = clcf->error_pages->elts; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2636 for (i = 0; i < clcf->error_pages->nelts; i++) { |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2637 |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2638 if (err_page[i].status == status) { |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2639 |
2953
aa12525236da
fix segfault if there is error_page 401, proxy_intercept_errors is on
Igor Sysoev <igor@sysoev.ru>
parents:
2952
diff
changeset
|
2640 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
|
2641 && 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
|
2642 { |
2267
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2643 h = ngx_list_push(&r->headers_out.headers); |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2644 |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2645 if (h == NULL) { |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2646 ngx_http_upstream_finalize_request(r, u, |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2647 NGX_HTTP_INTERNAL_SERVER_ERROR); |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2648 return NGX_OK; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2649 } |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2650 |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2651 *h = *u->headers_in.www_authenticate; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2652 |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2653 r->headers_out.www_authenticate = h; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2654 } |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2655 |
3706
ea908f6ae499
an intercepted error code was not cached
Igor Sysoev <igor@sysoev.ru>
parents:
3705
diff
changeset
|
2656 #if (NGX_HTTP_CACHE) |
ea908f6ae499
an intercepted error code was not cached
Igor Sysoev <igor@sysoev.ru>
parents:
3705
diff
changeset
|
2657 |
3709
64777690c697
fix r3707: cache node should be freed be a response is not cached
Igor Sysoev <igor@sysoev.ru>
parents:
3708
diff
changeset
|
2658 if (r->cache) { |
7117
dbd77a638eb7
Cache: fixed caching of intercepted errors (ticket #1382).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7116
diff
changeset
|
2659 |
dbd77a638eb7
Cache: fixed caching of intercepted errors (ticket #1382).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7116
diff
changeset
|
2660 if (u->cacheable) { |
dbd77a638eb7
Cache: fixed caching of intercepted errors (ticket #1382).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7116
diff
changeset
|
2661 time_t valid; |
dbd77a638eb7
Cache: fixed caching of intercepted errors (ticket #1382).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7116
diff
changeset
|
2662 |
dbd77a638eb7
Cache: fixed caching of intercepted errors (ticket #1382).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7116
diff
changeset
|
2663 valid = r->cache->valid_sec; |
dbd77a638eb7
Cache: fixed caching of intercepted errors (ticket #1382).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7116
diff
changeset
|
2664 |
dbd77a638eb7
Cache: fixed caching of intercepted errors (ticket #1382).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7116
diff
changeset
|
2665 if (valid == 0) { |
dbd77a638eb7
Cache: fixed caching of intercepted errors (ticket #1382).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7116
diff
changeset
|
2666 valid = ngx_http_file_cache_valid(u->conf->cache_valid, |
dbd77a638eb7
Cache: fixed caching of intercepted errors (ticket #1382).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7116
diff
changeset
|
2667 status); |
dbd77a638eb7
Cache: fixed caching of intercepted errors (ticket #1382).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7116
diff
changeset
|
2668 if (valid) { |
dbd77a638eb7
Cache: fixed caching of intercepted errors (ticket #1382).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7116
diff
changeset
|
2669 r->cache->valid_sec = ngx_time() + valid; |
dbd77a638eb7
Cache: fixed caching of intercepted errors (ticket #1382).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7116
diff
changeset
|
2670 } |
dbd77a638eb7
Cache: fixed caching of intercepted errors (ticket #1382).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7116
diff
changeset
|
2671 } |
dbd77a638eb7
Cache: fixed caching of intercepted errors (ticket #1382).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7116
diff
changeset
|
2672 |
dbd77a638eb7
Cache: fixed caching of intercepted errors (ticket #1382).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7116
diff
changeset
|
2673 if (valid) { |
dbd77a638eb7
Cache: fixed caching of intercepted errors (ticket #1382).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7116
diff
changeset
|
2674 r->cache->error = status; |
dbd77a638eb7
Cache: fixed caching of intercepted errors (ticket #1382).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7116
diff
changeset
|
2675 } |
3706
ea908f6ae499
an intercepted error code was not cached
Igor Sysoev <igor@sysoev.ru>
parents:
3705
diff
changeset
|
2676 } |
ea908f6ae499
an intercepted error code was not cached
Igor Sysoev <igor@sysoev.ru>
parents:
3705
diff
changeset
|
2677 |
3711
ce6ba077c270
several changes in cache cleanup handling:
Igor Sysoev <igor@sysoev.ru>
parents:
3709
diff
changeset
|
2678 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
|
2679 } |
ea908f6ae499
an intercepted error code was not cached
Igor Sysoev <igor@sysoev.ru>
parents:
3705
diff
changeset
|
2680 #endif |
2267
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2681 ngx_http_upstream_finalize_request(r, u, status); |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2682 |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2683 return NGX_OK; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2684 } |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2685 } |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2686 |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2687 return NGX_DECLINED; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2688 } |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2689 |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2690 |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2691 static ngx_int_t |
1153
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2692 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
|
2693 { |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2694 int err; |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2695 socklen_t len; |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2696 |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2697 #if (NGX_HAVE_KQUEUE) |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2698 |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2699 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
|
2700 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
|
2701 if (c->write->pending_eof) { |
e62219793beb
Upstream: better detection of connect() failures with kqueue.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4895
diff
changeset
|
2702 err = c->write->kq_errno; |
e62219793beb
Upstream: better detection of connect() failures with kqueue.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4895
diff
changeset
|
2703 |
e62219793beb
Upstream: better detection of connect() failures with kqueue.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4895
diff
changeset
|
2704 } else { |
e62219793beb
Upstream: better detection of connect() failures with kqueue.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4895
diff
changeset
|
2705 err = c->read->kq_errno; |
e62219793beb
Upstream: better detection of connect() failures with kqueue.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4895
diff
changeset
|
2706 } |
e62219793beb
Upstream: better detection of connect() failures with kqueue.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4895
diff
changeset
|
2707 |
1469
0a269c464eaf
connection error should be logged with "connecting to upstream" action,
Igor Sysoev <igor@sysoev.ru>
parents:
1468
diff
changeset
|
2708 c->log->action = "connecting to upstream"; |
4916
79c8e87b1fcb
Trailing whitespace fix.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4915
diff
changeset
|
2709 (void) ngx_connection_error(c, err, |
1166 | 2710 "kevent() reported that connect() failed"); |
2711 return NGX_ERROR; | |
2712 } | |
1153
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2713 |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2714 } else |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2715 #endif |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2716 { |
1166 | 2717 err = 0; |
2718 len = sizeof(int); | |
2719 | |
2720 /* | |
2721 * BSDs and Linux return 0 and set a pending error in err | |
2722 * Solaris returns -1 and sets errno | |
2723 */ | |
2724 | |
2725 if (getsockopt(c->fd, SOL_SOCKET, SO_ERROR, (void *) &err, &len) | |
2726 == -1) | |
2727 { | |
5557
188481078faf
Use ngx_socket_errno where appropriate.
Piotr Sikora <piotr@cloudflare.com>
parents:
5546
diff
changeset
|
2728 err = ngx_socket_errno; |
1166 | 2729 } |
2730 | |
2731 if (err) { | |
1469
0a269c464eaf
connection error should be logged with "connecting to upstream" action,
Igor Sysoev <igor@sysoev.ru>
parents:
1468
diff
changeset
|
2732 c->log->action = "connecting to upstream"; |
1166 | 2733 (void) ngx_connection_error(c, err, "connect() failed"); |
2734 return NGX_ERROR; | |
2735 } | |
1153
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2736 } |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2737 |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2738 return NGX_OK; |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2739 } |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2740 |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2741 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2742 static ngx_int_t |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2743 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
|
2744 { |
5489
6d357b2a9d6e
Upstream: keep $upstream_http_x_accel_redirect intact.
Ruslan Ermilov <ru@nginx.com>
parents:
5477
diff
changeset
|
2745 ngx_str_t uri, args; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2746 ngx_uint_t i, flags; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2747 ngx_list_part_t *part; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2748 ngx_table_elt_t *h; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2749 ngx_http_upstream_header_t *hh; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2750 ngx_http_upstream_main_conf_t *umcf; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2751 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2752 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
|
2753 |
2786
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
2754 if (u->headers_in.x_accel_redirect |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
2755 && !(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
|
2756 { |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2757 ngx_http_upstream_finalize_request(r, u, NGX_DECLINED); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2758 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2759 part = &u->headers_in.headers.part; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2760 h = part->elts; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2761 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2762 for (i = 0; /* void */; i++) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2763 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2764 if (i >= part->nelts) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2765 if (part->next == NULL) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2766 break; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2767 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2768 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2769 part = part->next; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2770 h = part->elts; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2771 i = 0; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2772 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2773 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2774 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
|
2775 h[i].lowcase_key, h[i].key.len); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2776 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2777 if (hh && hh->redirect) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2778 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
|
2779 ngx_http_finalize_request(r, |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2780 NGX_HTTP_INTERNAL_SERVER_ERROR); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2781 return NGX_DONE; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2782 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2783 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2784 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2785 |
5489
6d357b2a9d6e
Upstream: keep $upstream_http_x_accel_redirect intact.
Ruslan Ermilov <ru@nginx.com>
parents:
5477
diff
changeset
|
2786 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
|
2787 |
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2788 if (uri.data[0] == '@') { |
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2789 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
|
2790 |
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2791 } else { |
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2792 ngx_str_null(&args); |
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2793 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
|
2794 |
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2795 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
|
2796 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
|
2797 return NGX_DONE; |
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2798 } |
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2799 |
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2800 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
|
2801 r->method = NGX_HTTP_GET; |
6334
b31928ca3870
Upstream: fixed changing method on X-Accel-Redirect.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6332
diff
changeset
|
2802 r->method_name = ngx_http_core_get_method; |
5901
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2803 } |
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2804 |
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2805 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
|
2806 } |
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2807 |
3120
40b8b398dbbc
fix request counter for X-Accel-Redirect, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3112
diff
changeset
|
2808 ngx_http_finalize_request(r, NGX_DONE); |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2809 return NGX_DONE; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2810 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2811 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2812 part = &u->headers_in.headers.part; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2813 h = part->elts; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2814 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2815 for (i = 0; /* void */; i++) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2816 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2817 if (i >= part->nelts) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2818 if (part->next == NULL) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2819 break; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2820 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2821 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2822 part = part->next; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2823 h = part->elts; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2824 i = 0; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2825 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2826 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2827 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
|
2828 h[i].lowcase_key, h[i].key.len)) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2829 { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2830 continue; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2831 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2832 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2833 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
|
2834 h[i].lowcase_key, h[i].key.len); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2835 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2836 if (hh) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2837 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
|
2838 ngx_http_upstream_finalize_request(r, u, |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2839 NGX_HTTP_INTERNAL_SERVER_ERROR); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2840 return NGX_DONE; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2841 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2842 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2843 continue; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2844 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2845 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2846 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
|
2847 ngx_http_upstream_finalize_request(r, u, |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2848 NGX_HTTP_INTERNAL_SERVER_ERROR); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2849 return NGX_DONE; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2850 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2851 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2852 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2853 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
|
2854 r->headers_out.server->hash = 0; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2855 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2856 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2857 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
|
2858 r->headers_out.date->hash = 0; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2859 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2860 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2861 r->headers_out.status = u->headers_in.status_n; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2862 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
|
2863 |
4117
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
2864 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
|
2865 |
5735
5fb1e57c758a
Entity tags: explicit flag to skip not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5732
diff
changeset
|
2866 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
|
2867 |
5874
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
2868 if (u->conf->force_ranges) { |
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
2869 r->allow_ranges = 1; |
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
2870 r->single_range = 1; |
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
2871 |
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
2872 #if (NGX_HTTP_CACHE) |
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
2873 if (r->cached) { |
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
2874 r->single_range = 0; |
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
2875 } |
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
2876 #endif |
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
2877 } |
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
2878 |
5300
f538a67c9f77
Upstream: u->length now defaults to -1 (API change).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5299
diff
changeset
|
2879 u->length = -1; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2880 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2881 return NGX_OK; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2882 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2883 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2884 |
7230
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2885 static ngx_int_t |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2886 ngx_http_upstream_process_trailers(ngx_http_request_t *r, |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2887 ngx_http_upstream_t *u) |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2888 { |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2889 ngx_uint_t i; |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2890 ngx_list_part_t *part; |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2891 ngx_table_elt_t *h, *ho; |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2892 |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2893 if (!u->conf->pass_trailers) { |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2894 return NGX_OK; |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2895 } |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2896 |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2897 part = &u->headers_in.trailers.part; |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2898 h = part->elts; |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2899 |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2900 for (i = 0; /* void */; i++) { |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2901 |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2902 if (i >= part->nelts) { |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2903 if (part->next == NULL) { |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2904 break; |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2905 } |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2906 |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2907 part = part->next; |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2908 h = part->elts; |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2909 i = 0; |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2910 } |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2911 |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2912 if (ngx_hash_find(&u->conf->hide_headers_hash, h[i].hash, |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2913 h[i].lowcase_key, h[i].key.len)) |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2914 { |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2915 continue; |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2916 } |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2917 |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2918 ho = ngx_list_push(&r->headers_out.trailers); |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2919 if (ho == NULL) { |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2920 return NGX_ERROR; |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2921 } |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2922 |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2923 *ho = h[i]; |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2924 } |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2925 |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2926 return NGX_OK; |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2927 } |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2928 |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2929 |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2930 static void |
681 | 2931 ngx_http_upstream_send_response(ngx_http_request_t *r, ngx_http_upstream_t *u) |
2932 { | |
2402 | 2933 ssize_t n; |
681 | 2934 ngx_int_t rc; |
2935 ngx_event_pipe_t *p; | |
2936 ngx_connection_t *c; | |
2937 ngx_http_core_loc_conf_t *clcf; | |
2938 | |
509 | 2939 rc = ngx_http_send_header(r); |
479 | 2940 |
2701 | 2941 if (rc == NGX_ERROR || rc > NGX_OK || r->post_action) { |
485 | 2942 ngx_http_upstream_finalize_request(r, u, rc); |
479 | 2943 return; |
2944 } | |
2945 | |
5353
1608b1135a1d
Upstream: setting u->header_sent before ngx_http_upstream_upgrade().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5340
diff
changeset
|
2946 u->header_sent = 1; |
1608b1135a1d
Upstream: setting u->header_sent before ngx_http_upstream_upgrade().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5340
diff
changeset
|
2947 |
5072
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2948 if (u->upgrade) { |
6794
93b294c5d581
Upstream: avoid holding a cache node with upgraded connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6793
diff
changeset
|
2949 |
93b294c5d581
Upstream: avoid holding a cache node with upgraded connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6793
diff
changeset
|
2950 #if (NGX_HTTP_CACHE) |
93b294c5d581
Upstream: avoid holding a cache node with upgraded connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6793
diff
changeset
|
2951 |
93b294c5d581
Upstream: avoid holding a cache node with upgraded connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6793
diff
changeset
|
2952 if (r->cache) { |
93b294c5d581
Upstream: avoid holding a cache node with upgraded connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6793
diff
changeset
|
2953 ngx_http_file_cache_free(r->cache, u->pipe->temp_file); |
93b294c5d581
Upstream: avoid holding a cache node with upgraded connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6793
diff
changeset
|
2954 } |
93b294c5d581
Upstream: avoid holding a cache node with upgraded connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6793
diff
changeset
|
2955 |
93b294c5d581
Upstream: avoid holding a cache node with upgraded connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6793
diff
changeset
|
2956 #endif |
93b294c5d581
Upstream: avoid holding a cache node with upgraded connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6793
diff
changeset
|
2957 |
5072
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2958 ngx_http_upstream_upgrade(r, u); |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2959 return; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2960 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2961 |
2704
ac1e2e199c9f
shutdown client connection for cacheable header only responses
Igor Sysoev <igor@sysoev.ru>
parents:
2703
diff
changeset
|
2962 c = r->connection; |
ac1e2e199c9f
shutdown client connection for cacheable header only responses
Igor Sysoev <igor@sysoev.ru>
parents:
2703
diff
changeset
|
2963 |
2701 | 2964 if (r->header_only) { |
2704
ac1e2e199c9f
shutdown client connection for cacheable header only responses
Igor Sysoev <igor@sysoev.ru>
parents:
2703
diff
changeset
|
2965 |
5746
35990c69b3ac
Upstream: p->downstream_error instead of closing connection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5745
diff
changeset
|
2966 if (!u->buffering) { |
2701 | 2967 ngx_http_upstream_finalize_request(r, u, rc); |
2968 return; | |
2969 } | |
5746
35990c69b3ac
Upstream: p->downstream_error instead of closing connection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5745
diff
changeset
|
2970 |
35990c69b3ac
Upstream: p->downstream_error instead of closing connection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5745
diff
changeset
|
2971 if (!u->cacheable && !u->store) { |
35990c69b3ac
Upstream: p->downstream_error instead of closing connection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5745
diff
changeset
|
2972 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
|
2973 return; |
35990c69b3ac
Upstream: p->downstream_error instead of closing connection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5745
diff
changeset
|
2974 } |
35990c69b3ac
Upstream: p->downstream_error instead of closing connection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5745
diff
changeset
|
2975 |
35990c69b3ac
Upstream: p->downstream_error instead of closing connection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5745
diff
changeset
|
2976 u->pipe->downstream_error = 1; |
2701 | 2977 } |
2978 | |
7070
f583559aadc7
Upstream: keep request body file from removal if requested.
Roman Arutyunyan <arut@nginx.com>
parents:
7067
diff
changeset
|
2979 if (r->request_body && r->request_body->temp_file |
7297
a10e5fe44762
Upstream: disable body cleanup with preserve_output (ticket #1565).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7260
diff
changeset
|
2980 && r == r->main && !r->preserve_body |
a10e5fe44762
Upstream: disable body cleanup with preserve_output (ticket #1565).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7260
diff
changeset
|
2981 && !u->conf->preserve_output) |
7070
f583559aadc7
Upstream: keep request body file from removal if requested.
Roman Arutyunyan <arut@nginx.com>
parents:
7067
diff
changeset
|
2982 { |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2983 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
|
2984 r->request_body->temp_file->file.fd = NGX_INVALID_FILE; |
563 | 2985 } |
2986 | |
581 | 2987 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
2988 | |
649 | 2989 if (!u->buffering) { |
581 | 2990 |
6794
93b294c5d581
Upstream: avoid holding a cache node with upgraded connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6793
diff
changeset
|
2991 #if (NGX_HTTP_CACHE) |
93b294c5d581
Upstream: avoid holding a cache node with upgraded connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6793
diff
changeset
|
2992 |
93b294c5d581
Upstream: avoid holding a cache node with upgraded connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6793
diff
changeset
|
2993 if (r->cache) { |
93b294c5d581
Upstream: avoid holding a cache node with upgraded connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6793
diff
changeset
|
2994 ngx_http_file_cache_free(r->cache, u->pipe->temp_file); |
93b294c5d581
Upstream: avoid holding a cache node with upgraded connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6793
diff
changeset
|
2995 } |
93b294c5d581
Upstream: avoid holding a cache node with upgraded connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6793
diff
changeset
|
2996 |
93b294c5d581
Upstream: avoid holding a cache node with upgraded connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6793
diff
changeset
|
2997 #endif |
93b294c5d581
Upstream: avoid holding a cache node with upgraded connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6793
diff
changeset
|
2998 |
581 | 2999 if (u->input_filter == NULL) { |
3000 u->input_filter_init = ngx_http_upstream_non_buffered_filter_init; | |
3001 u->input_filter = ngx_http_upstream_non_buffered_filter; | |
3002 u->input_filter_ctx = r; | |
3003 } | |
3004 | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3005 u->read_event_handler = ngx_http_upstream_process_non_buffered_upstream; |
581 | 3006 r->write_event_handler = |
3007 ngx_http_upstream_process_non_buffered_downstream; | |
3008 | |
3009 r->limit_rate = 0; | |
7504
c19ca381b2e6
Variables support in limit_rate and limit_rate_after (ticket #293).
Ruslan Ermilov <ru@nginx.com>
parents:
7456
diff
changeset
|
3010 r->limit_rate_set = 1; |
581 | 3011 |
3012 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
|
3013 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
581 | 3014 return; |
3015 } | |
3016 | |
7007
ed1101bbf19f
Introduced ngx_tcp_nodelay().
Ruslan Ermilov <ru@nginx.com>
parents:
7006
diff
changeset
|
3017 if (clcf->tcp_nodelay && ngx_tcp_nodelay(c) != NGX_OK) { |
ed1101bbf19f
Introduced ngx_tcp_nodelay().
Ruslan Ermilov <ru@nginx.com>
parents:
7006
diff
changeset
|
3018 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
ed1101bbf19f
Introduced ngx_tcp_nodelay().
Ruslan Ermilov <ru@nginx.com>
parents:
7006
diff
changeset
|
3019 return; |
583 | 3020 } |
3021 | |
2402 | 3022 n = u->buffer.last - u->buffer.pos; |
3023 | |
3024 if (n) { | |
581 | 3025 u->buffer.last = u->buffer.pos; |
3026 | |
2402 | 3027 u->state->response_length += n; |
3028 | |
3029 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
|
3030 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
581 | 3031 return; |
3032 } | |
3033 | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3034 ngx_http_upstream_process_non_buffered_downstream(r); |
581 | 3035 |
3036 } else { | |
3037 u->buffer.pos = u->buffer.start; | |
3038 u->buffer.last = u->buffer.start; | |
3039 | |
3040 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
|
3041 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
581 | 3042 return; |
3043 } | |
1468
491e5059ea19
read EOF of header only responses in non-buffered proxying
Igor Sysoev <igor@sysoev.ru>
parents:
1397
diff
changeset
|
3044 |
8372
b1302f1dd2f6
Upstream: fixed non-buffered proxying with eventport.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8299
diff
changeset
|
3045 ngx_http_upstream_process_non_buffered_upstream(r, u); |
581 | 3046 } |
3047 | |
3048 return; | |
3049 } | |
3050 | |
479 | 3051 /* TODO: preallocate event_pipe bufs, look "Content-Length" */ |
3052 | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3053 #if (NGX_HTTP_CACHE) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3054 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3055 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
|
3056 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
|
3057 r->cache->file.fd = NGX_INVALID_FILE; |
479 | 3058 } |
3059 | |
3699
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
3060 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
|
3061 |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
3062 case NGX_ERROR: |
5295
a489c31c9783
Upstream: ngx_http_upstream_finalize_request(NGX_ERROR) on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5294
diff
changeset
|
3063 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
|
3064 return; |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
3065 |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
3066 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
|
3067 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
|
3068 break; |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
3069 |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
3070 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
|
3071 |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
3072 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
|
3073 |
5950
eaeecf00d5d7
Upstream: preset some cache configuration when bypassing.
Valentin Bartenev <vbart@nginx.com>
parents:
5949
diff
changeset
|
3074 /* 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
|
3075 |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
3076 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
|
3077 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
|
3078 return; |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
3079 } |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
3080 } |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
3081 |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
3082 break; |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
3083 } |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
3084 |
1565 | 3085 if (u->cacheable) { |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3086 time_t now, valid; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3087 |
2663
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
3088 now = ngx_time(); |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
3089 |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
3090 valid = r->cache->valid_sec; |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
3091 |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
3092 if (valid == 0) { |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
3093 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
|
3094 u->headers_in.status_n); |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
3095 if (valid) { |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
3096 r->cache->valid_sec = now + valid; |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
3097 } |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
3098 } |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
3099 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3100 if (valid) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3101 r->cache->date = now; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3102 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
|
3103 |
5935
1573fc7875fa
Cache: send conditional requests only for cached 200/206 responses.
Piotr Sikora <piotr@cloudflare.com>
parents:
5928
diff
changeset
|
3104 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
|
3105 || 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
|
3106 { |
1573fc7875fa
Cache: send conditional requests only for cached 200/206 responses.
Piotr Sikora <piotr@cloudflare.com>
parents:
5928
diff
changeset
|
3107 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
|
3108 |
1573fc7875fa
Cache: send conditional requests only for cached 200/206 responses.
Piotr Sikora <piotr@cloudflare.com>
parents:
5928
diff
changeset
|
3109 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
|
3110 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
|
3111 |
174512857ccf
Cache: do not inherit last_modified and etag from stale response.
Roman Arutyunyan <arut@nginx.com>
parents:
5977
diff
changeset
|
3112 } else { |
174512857ccf
Cache: do not inherit last_modified and etag from stale response.
Roman Arutyunyan <arut@nginx.com>
parents:
5977
diff
changeset
|
3113 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
|
3114 } |
5992
174512857ccf
Cache: do not inherit last_modified and etag from stale response.
Roman Arutyunyan <arut@nginx.com>
parents:
5977
diff
changeset
|
3115 |
174512857ccf
Cache: do not inherit last_modified and etag from stale response.
Roman Arutyunyan <arut@nginx.com>
parents:
5977
diff
changeset
|
3116 } else { |
174512857ccf
Cache: do not inherit last_modified and etag from stale response.
Roman Arutyunyan <arut@nginx.com>
parents:
5977
diff
changeset
|
3117 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
|
3118 ngx_str_null(&r->cache->etag); |
5737
44b9ab7752e3
Cache: ETag now saved into cache header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5735
diff
changeset
|
3119 } |
44b9ab7752e3
Cache: ETag now saved into cache header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5735
diff
changeset
|
3120 |
5959
f7584d7c0ccb
Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents:
5951
diff
changeset
|
3121 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
|
3122 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
|
3123 return; |
f7584d7c0ccb
Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents:
5951
diff
changeset
|
3124 } |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3125 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3126 } else { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3127 u->cacheable = 0; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3128 } |
479 | 3129 } |
3130 | |
2690 | 3131 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, |
3132 "http cacheable: %d", u->cacheable); | |
3133 | |
3083
ffe8bfb38184
clean cache updating state if a response has uncacheable code or
Igor Sysoev <igor@sysoev.ru>
parents:
3056
diff
changeset
|
3134 if (u->cacheable == 0 && r->cache) { |
3711
ce6ba077c270
several changes in cache cleanup handling:
Igor Sysoev <igor@sysoev.ru>
parents:
3709
diff
changeset
|
3135 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
|
3136 } |
ffe8bfb38184
clean cache updating state if a response has uncacheable code or
Igor Sysoev <igor@sysoev.ru>
parents:
3056
diff
changeset
|
3137 |
6428
545b5e4d83b2
Upstream: avoid closing client connection in edge case.
Justin Li <jli.justinli@gmail.com>
parents:
6427
diff
changeset
|
3138 if (r->header_only && !u->cacheable && !u->store) { |
545b5e4d83b2
Upstream: avoid closing client connection in edge case.
Justin Li <jli.justinli@gmail.com>
parents:
6427
diff
changeset
|
3139 ngx_http_upstream_finalize_request(r, u, 0); |
545b5e4d83b2
Upstream: avoid closing client connection in edge case.
Justin Li <jli.justinli@gmail.com>
parents:
6427
diff
changeset
|
3140 return; |
545b5e4d83b2
Upstream: avoid closing client connection in edge case.
Justin Li <jli.justinli@gmail.com>
parents:
6427
diff
changeset
|
3141 } |
545b5e4d83b2
Upstream: avoid closing client connection in edge case.
Justin Li <jli.justinli@gmail.com>
parents:
6427
diff
changeset
|
3142 |
479 | 3143 #endif |
3144 | |
581 | 3145 p = u->pipe; |
479 | 3146 |
6443
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3147 p->output_filter = ngx_http_upstream_output_filter; |
479 | 3148 p->output_ctx = r; |
3149 p->tag = u->output.tag; | |
577 | 3150 p->bufs = u->conf->bufs; |
479 | 3151 p->busy_size = u->conf->busy_buffers_size; |
3152 p->upstream = u->peer.connection; | |
583 | 3153 p->downstream = c; |
479 | 3154 p->pool = r->pool; |
583 | 3155 p->log = c->log; |
5883
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3156 p->limit_rate = u->conf->limit_rate; |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3157 p->start_sec = ngx_time(); |
577 | 3158 |
1565 | 3159 p->cacheable = u->cacheable || u->store; |
479 | 3160 |
501 | 3161 p->temp_file = ngx_pcalloc(r->pool, sizeof(ngx_temp_file_t)); |
3162 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
|
3163 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
479 | 3164 return; |
3165 } | |
3166 | |
3167 p->temp_file->file.fd = NGX_INVALID_FILE; | |
583 | 3168 p->temp_file->file.log = c->log; |
479 | 3169 p->temp_file->path = u->conf->temp_path; |
3170 p->temp_file->pool = r->pool; | |
577 | 3171 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3172 if (p->cacheable) { |
479 | 3173 p->temp_file->persistent = 1; |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3174 |
5960
e9effef98874
Upstream: use_temp_path parameter of proxy_cache_path and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5959
diff
changeset
|
3175 #if (NGX_HTTP_CACHE) |
6795
1a917932db96
Cache: prefix-based temporary files.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6794
diff
changeset
|
3176 if (r->cache && !r->cache->file_cache->use_temp_path) { |
1a917932db96
Cache: prefix-based temporary files.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6794
diff
changeset
|
3177 p->temp_file->path = r->cache->file_cache->path; |
1a917932db96
Cache: prefix-based temporary files.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6794
diff
changeset
|
3178 p->temp_file->file.name = r->cache->file.name; |
5960
e9effef98874
Upstream: use_temp_path parameter of proxy_cache_path and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5959
diff
changeset
|
3179 } |
e9effef98874
Upstream: use_temp_path parameter of proxy_cache_path and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5959
diff
changeset
|
3180 #endif |
e9effef98874
Upstream: use_temp_path parameter of proxy_cache_path and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5959
diff
changeset
|
3181 |
479 | 3182 } else { |
667 | 3183 p->temp_file->log_level = NGX_LOG_WARN; |
479 | 3184 p->temp_file->warn = "an upstream response is buffered " |
3185 "to a temporary file"; | |
3186 } | |
3187 | |
3188 p->max_temp_file_size = u->conf->max_temp_file_size; | |
3189 p->temp_file_write_size = u->conf->temp_file_write_size; | |
3190 | |
6443
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3191 #if (NGX_THREADS) |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3192 if (clcf->aio == NGX_HTTP_AIO_THREADS && clcf->aio_write) { |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3193 p->thread_handler = ngx_http_upstream_thread_handler; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3194 p->thread_ctx = r; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3195 } |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3196 #endif |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3197 |
501 | 3198 p->preread_bufs = ngx_alloc_chain_link(r->pool); |
3199 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
|
3200 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
479 | 3201 return; |
3202 } | |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3203 |
581 | 3204 p->preread_bufs->buf = &u->buffer; |
479 | 3205 p->preread_bufs->next = NULL; |
581 | 3206 u->buffer.recycled = 1; |
3207 | |
3208 p->preread_size = u->buffer.last - u->buffer.pos; | |
479 | 3209 |
1565 | 3210 if (u->cacheable) { |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3211 |
479 | 3212 p->buf_to_file = ngx_calloc_buf(r->pool); |
3213 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
|
3214 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
479 | 3215 return; |
3216 } | |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3217 |
4895
508e61393b6c
Event pipe: fixed handling of buf_to_file data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4769
diff
changeset
|
3218 p->buf_to_file->start = u->buffer.start; |
581 | 3219 p->buf_to_file->pos = u->buffer.start; |
3220 p->buf_to_file->last = u->buffer.pos; | |
479 | 3221 p->buf_to_file->temporary = 1; |
3222 } | |
3223 | |
6125
4dc8e7b62216
Removed the obsolete aio module.
Ruslan Ermilov <ru@nginx.com>
parents:
6068
diff
changeset
|
3224 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
|
3225 /* the posted aio operation may corrupt a shadow buffer */ |
479 | 3226 p->single_buf = 1; |
3227 } | |
3228 | |
3229 /* TODO: p->free_bufs = 0 if use ngx_create_chain_of_bufs() */ | |
3230 p->free_bufs = 1; | |
3231 | |
3232 /* | |
581 | 3233 * event_pipe would do u->buffer.last += p->preread_size |
479 | 3234 * as though these bytes were read |
3235 */ | |
581 | 3236 u->buffer.last = u->buffer.pos; |
479 | 3237 |
3238 if (u->conf->cyclic_temp_file) { | |
3239 | |
3240 /* | |
3241 * we need to disable the use of sendfile() if we use cyclic temp file | |
3242 * because the writing a new data may interfere with sendfile() | |
3243 * that uses the same kernel file pages (at least on FreeBSD) | |
3244 */ | |
3245 | |
3246 p->cyclic_temp_file = 1; | |
583 | 3247 c->sendfile = 0; |
479 | 3248 |
3249 } else { | |
3250 p->cyclic_temp_file = 0; | |
3251 } | |
3252 | |
3253 p->read_timeout = u->conf->read_timeout; | |
3254 p->send_timeout = clcf->send_timeout; | |
3255 p->send_lowat = clcf->send_lowat; | |
3256 | |
4119
b66712cde67d
Upstream: pipe length and input_filter_init in buffered mode.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4118
diff
changeset
|
3257 p->length = -1; |
b66712cde67d
Upstream: pipe length and input_filter_init in buffered mode.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4118
diff
changeset
|
3258 |
b66712cde67d
Upstream: pipe length and input_filter_init in buffered mode.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4118
diff
changeset
|
3259 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
|
3260 && 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
|
3261 { |
5295
a489c31c9783
Upstream: ngx_http_upstream_finalize_request(NGX_ERROR) on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5294
diff
changeset
|
3262 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
|
3263 return; |
b66712cde67d
Upstream: pipe length and input_filter_init in buffered mode.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4118
diff
changeset
|
3264 } |
b66712cde67d
Upstream: pipe length and input_filter_init in buffered mode.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4118
diff
changeset
|
3265 |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3266 u->read_event_handler = ngx_http_upstream_process_upstream; |
509 | 3267 r->write_event_handler = ngx_http_upstream_process_downstream; |
479 | 3268 |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
3269 ngx_http_upstream_process_upstream(r, u); |
479 | 3270 } |
3271 | |
3272 | |
487 | 3273 static void |
5072
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3274 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
|
3275 { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3276 ngx_connection_t *c; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3277 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
|
3278 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3279 c = r->connection; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3280 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
|
3281 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3282 /* 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
|
3283 |
7131
6a5a91de5b74
Upstream: disabled upgrading in subrequests.
Roman Arutyunyan <arut@nginx.com>
parents:
7130
diff
changeset
|
3284 if (r != r->main) { |
6a5a91de5b74
Upstream: disabled upgrading in subrequests.
Roman Arutyunyan <arut@nginx.com>
parents:
7130
diff
changeset
|
3285 ngx_log_error(NGX_LOG_ERR, c->log, 0, |
6a5a91de5b74
Upstream: disabled upgrading in subrequests.
Roman Arutyunyan <arut@nginx.com>
parents:
7130
diff
changeset
|
3286 "connection upgrade in subrequest"); |
6a5a91de5b74
Upstream: disabled upgrading in subrequests.
Roman Arutyunyan <arut@nginx.com>
parents:
7130
diff
changeset
|
3287 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
6a5a91de5b74
Upstream: disabled upgrading in subrequests.
Roman Arutyunyan <arut@nginx.com>
parents:
7130
diff
changeset
|
3288 return; |
6a5a91de5b74
Upstream: disabled upgrading in subrequests.
Roman Arutyunyan <arut@nginx.com>
parents:
7130
diff
changeset
|
3289 } |
6a5a91de5b74
Upstream: disabled upgrading in subrequests.
Roman Arutyunyan <arut@nginx.com>
parents:
7130
diff
changeset
|
3290 |
5072
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3291 r->keepalive = 0; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3292 c->log->action = "proxying upgraded connection"; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3293 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3294 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
|
3295 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
|
3296 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
|
3297 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
|
3298 |
5142
afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5132
diff
changeset
|
3299 if (clcf->tcp_nodelay) { |
7007
ed1101bbf19f
Introduced ngx_tcp_nodelay().
Ruslan Ermilov <ru@nginx.com>
parents:
7006
diff
changeset
|
3300 |
ed1101bbf19f
Introduced ngx_tcp_nodelay().
Ruslan Ermilov <ru@nginx.com>
parents:
7006
diff
changeset
|
3301 if (ngx_tcp_nodelay(c) != NGX_OK) { |
ed1101bbf19f
Introduced ngx_tcp_nodelay().
Ruslan Ermilov <ru@nginx.com>
parents:
7006
diff
changeset
|
3302 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
ed1101bbf19f
Introduced ngx_tcp_nodelay().
Ruslan Ermilov <ru@nginx.com>
parents:
7006
diff
changeset
|
3303 return; |
ed1101bbf19f
Introduced ngx_tcp_nodelay().
Ruslan Ermilov <ru@nginx.com>
parents:
7006
diff
changeset
|
3304 } |
ed1101bbf19f
Introduced ngx_tcp_nodelay().
Ruslan Ermilov <ru@nginx.com>
parents:
7006
diff
changeset
|
3305 |
ed1101bbf19f
Introduced ngx_tcp_nodelay().
Ruslan Ermilov <ru@nginx.com>
parents:
7006
diff
changeset
|
3306 if (ngx_tcp_nodelay(u->peer.connection) != NGX_OK) { |
ed1101bbf19f
Introduced ngx_tcp_nodelay().
Ruslan Ermilov <ru@nginx.com>
parents:
7006
diff
changeset
|
3307 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
ed1101bbf19f
Introduced ngx_tcp_nodelay().
Ruslan Ermilov <ru@nginx.com>
parents:
7006
diff
changeset
|
3308 return; |
5072
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3309 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3310 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3311 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3312 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
|
3313 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
|
3314 return; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3315 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3316 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3317 if (u->peer.connection->read->ready |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3318 || u->buffer.pos != u->buffer.last) |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3319 { |
5579
7586e7b2dbe9
Upstream: ngx_post_event() instead of upgraded call (ticket #503).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5557
diff
changeset
|
3320 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
|
3321 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
|
3322 return; |
5072
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3323 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3324 |
5532
17134d29782e
Upstream: reading from a client after connection upgrade.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5500
diff
changeset
|
3325 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
|
3326 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3327 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3328 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3329 static void |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3330 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
|
3331 { |
5073
52eb762c68a9
Proxy: fixed do_write handling in previous commit.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5072
diff
changeset
|
3332 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
|
3333 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3334 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3335 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3336 static void |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3337 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
|
3338 { |
5073
52eb762c68a9
Proxy: fixed do_write handling in previous commit.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5072
diff
changeset
|
3339 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
|
3340 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3341 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3342 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3343 static void |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3344 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
|
3345 ngx_http_upstream_t *u) |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3346 { |
5073
52eb762c68a9
Proxy: fixed do_write handling in previous commit.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5072
diff
changeset
|
3347 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
|
3348 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3349 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3350 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3351 static void |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3352 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
|
3353 ngx_http_upstream_t *u) |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3354 { |
5073
52eb762c68a9
Proxy: fixed do_write handling in previous commit.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5072
diff
changeset
|
3355 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
|
3356 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3357 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3358 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3359 static void |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3360 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
|
3361 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
|
3362 { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3363 size_t size; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3364 ssize_t n; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3365 ngx_buf_t *b; |
7538
08ed570ad93c
Upstream: fixed EOF handling in unbuffered and upgraded modes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7514
diff
changeset
|
3366 ngx_uint_t flags; |
5072
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3367 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
|
3368 ngx_http_upstream_t *u; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3369 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
|
3370 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3371 c = r->connection; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3372 u = r->upstream; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3373 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3374 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
|
3375 "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
|
3376 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3377 downstream = c; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3378 upstream = u->peer.connection; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3379 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3380 if (downstream->write->timedout) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3381 c->timedout = 1; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3382 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
|
3383 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
|
3384 return; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3385 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3386 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3387 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
|
3388 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
|
3389 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
|
3390 return; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3391 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3392 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3393 if (from_upstream) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3394 src = upstream; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3395 dst = downstream; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3396 b = &u->buffer; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3397 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3398 } else { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3399 src = downstream; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3400 dst = upstream; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3401 b = &u->from_client; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3402 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3403 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
|
3404 b = r->header_in; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3405 b->end = b->last; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3406 do_write = 1; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3407 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3408 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3409 if (b->start == NULL) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3410 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
|
3411 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
|
3412 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
|
3413 return; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3414 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3415 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3416 b->pos = b->start; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3417 b->last = b->start; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3418 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
|
3419 b->temporary = 1; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3420 b->tag = u->output.tag; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3421 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3422 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3423 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3424 for ( ;; ) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3425 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3426 if (do_write) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3427 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3428 size = b->last - b->pos; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3429 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3430 if (size && dst->write->ready) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3431 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3432 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
|
3433 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3434 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
|
3435 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
|
3436 return; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3437 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3438 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3439 if (n > 0) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3440 b->pos += n; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3441 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3442 if (b->pos == b->last) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3443 b->pos = b->start; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3444 b->last = b->start; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3445 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3446 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3447 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3448 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3449 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3450 size = b->end - b->last; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3451 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3452 if (size && src->read->ready) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3453 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3454 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
|
3455 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3456 if (n == NGX_AGAIN || n == 0) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3457 break; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3458 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3459 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3460 if (n > 0) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3461 do_write = 1; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3462 b->last += n; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3463 |
6654
c131f20c9562
Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6594
diff
changeset
|
3464 if (from_upstream) { |
c131f20c9562
Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6594
diff
changeset
|
3465 u->state->bytes_received += n; |
c131f20c9562
Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6594
diff
changeset
|
3466 } |
c131f20c9562
Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6594
diff
changeset
|
3467 |
5072
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3468 continue; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3469 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3470 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3471 if (n == NGX_ERROR) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3472 src->read->eof = 1; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3473 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3474 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3475 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3476 break; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3477 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3478 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3479 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
|
3480 || (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
|
3481 || (downstream->read->eof && upstream->read->eof)) |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3482 { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3483 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
|
3484 "http upstream upgraded done"); |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3485 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
|
3486 return; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3487 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3488 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3489 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
|
3490 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3491 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
|
3492 != NGX_OK) |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3493 { |
5295
a489c31c9783
Upstream: ngx_http_upstream_finalize_request(NGX_ERROR) on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5294
diff
changeset
|
3494 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
|
3495 return; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3496 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3497 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3498 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
|
3499 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
|
3500 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3501 } else if (upstream->write->timer_set) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3502 ngx_del_timer(upstream->write); |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3503 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3504 |
7538
08ed570ad93c
Upstream: fixed EOF handling in unbuffered and upgraded modes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7514
diff
changeset
|
3505 if (upstream->read->eof || upstream->read->error) { |
08ed570ad93c
Upstream: fixed EOF handling in unbuffered and upgraded modes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7514
diff
changeset
|
3506 flags = NGX_CLOSE_EVENT; |
08ed570ad93c
Upstream: fixed EOF handling in unbuffered and upgraded modes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7514
diff
changeset
|
3507 |
08ed570ad93c
Upstream: fixed EOF handling in unbuffered and upgraded modes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7514
diff
changeset
|
3508 } else { |
08ed570ad93c
Upstream: fixed EOF handling in unbuffered and upgraded modes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7514
diff
changeset
|
3509 flags = 0; |
08ed570ad93c
Upstream: fixed EOF handling in unbuffered and upgraded modes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7514
diff
changeset
|
3510 } |
08ed570ad93c
Upstream: fixed EOF handling in unbuffered and upgraded modes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7514
diff
changeset
|
3511 |
08ed570ad93c
Upstream: fixed EOF handling in unbuffered and upgraded modes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7514
diff
changeset
|
3512 if (ngx_handle_read_event(upstream->read, flags) != NGX_OK) { |
5295
a489c31c9783
Upstream: ngx_http_upstream_finalize_request(NGX_ERROR) on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5294
diff
changeset
|
3513 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
|
3514 return; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3515 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3516 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3517 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
|
3518 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
|
3519 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3520 } else if (upstream->read->timer_set) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3521 ngx_del_timer(upstream->read); |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3522 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3523 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3524 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
|
3525 != NGX_OK) |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3526 { |
5295
a489c31c9783
Upstream: ngx_http_upstream_finalize_request(NGX_ERROR) on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5294
diff
changeset
|
3527 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
|
3528 return; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3529 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3530 |
7538
08ed570ad93c
Upstream: fixed EOF handling in unbuffered and upgraded modes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7514
diff
changeset
|
3531 if (downstream->read->eof || downstream->read->error) { |
08ed570ad93c
Upstream: fixed EOF handling in unbuffered and upgraded modes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7514
diff
changeset
|
3532 flags = NGX_CLOSE_EVENT; |
08ed570ad93c
Upstream: fixed EOF handling in unbuffered and upgraded modes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7514
diff
changeset
|
3533 |
08ed570ad93c
Upstream: fixed EOF handling in unbuffered and upgraded modes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7514
diff
changeset
|
3534 } else { |
08ed570ad93c
Upstream: fixed EOF handling in unbuffered and upgraded modes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7514
diff
changeset
|
3535 flags = 0; |
08ed570ad93c
Upstream: fixed EOF handling in unbuffered and upgraded modes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7514
diff
changeset
|
3536 } |
08ed570ad93c
Upstream: fixed EOF handling in unbuffered and upgraded modes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7514
diff
changeset
|
3537 |
08ed570ad93c
Upstream: fixed EOF handling in unbuffered and upgraded modes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7514
diff
changeset
|
3538 if (ngx_handle_read_event(downstream->read, flags) != NGX_OK) { |
5295
a489c31c9783
Upstream: ngx_http_upstream_finalize_request(NGX_ERROR) on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5294
diff
changeset
|
3539 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
|
3540 return; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3541 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3542 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3543 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
|
3544 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
|
3545 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3546 } else if (downstream->write->timer_set) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3547 ngx_del_timer(downstream->write); |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3548 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3549 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3550 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3551 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3552 static void |
581 | 3553 ngx_http_upstream_process_non_buffered_downstream(ngx_http_request_t *r) |
3554 { | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3555 ngx_event_t *wev; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3556 ngx_connection_t *c; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3557 ngx_http_upstream_t *u; |
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 = r->connection; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3560 u = r->upstream; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3561 wev = c->write; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3562 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3563 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
|
3564 "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
|
3565 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3566 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
|
3567 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3568 if (wev->timedout) { |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3569 c->timedout = 1; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3570 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
|
3571 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
|
3572 return; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3573 } |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3574 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3575 ngx_http_upstream_process_non_buffered_request(r, 1); |
581 | 3576 } |
3577 | |
3578 | |
3579 static void | |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
3580 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
|
3581 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
|
3582 { |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
3583 ngx_connection_t *c; |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
3584 |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
3585 c = u->peer.connection; |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3586 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3587 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
|
3588 "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
|
3589 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3590 c->log->action = "reading upstream"; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3591 |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
3592 if (c->read->timedout) { |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3593 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
|
3594 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
|
3595 return; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3596 } |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3597 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3598 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
|
3599 } |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3600 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3601 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3602 static void |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3603 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
|
3604 ngx_uint_t do_write) |
581 | 3605 { |
3606 size_t size; | |
3607 ssize_t n; | |
3608 ngx_buf_t *b; | |
583 | 3609 ngx_int_t rc; |
7538
08ed570ad93c
Upstream: fixed EOF handling in unbuffered and upgraded modes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7514
diff
changeset
|
3610 ngx_uint_t flags; |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3611 ngx_connection_t *downstream, *upstream; |
581 | 3612 ngx_http_upstream_t *u; |
3613 ngx_http_core_loc_conf_t *clcf; | |
3614 | |
756
d904b5cb3bba
fix building introduced by previous commit
Igor Sysoev <igor@sysoev.ru>
parents:
755
diff
changeset
|
3615 u = r->upstream; |
884 | 3616 downstream = r->connection; |
3617 upstream = u->peer.connection; | |
581 | 3618 |
3619 b = &u->buffer; | |
3620 | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3621 do_write = do_write || u->length == 0; |
581 | 3622 |
3623 for ( ;; ) { | |
3624 | |
3625 if (do_write) { | |
3626 | |
7166
a762ddf22dbb
Upstream: flush low-level buffers on write retry.
Patryk Lesiewicz <patryk@google.com>
parents:
7131
diff
changeset
|
3627 if (u->out_bufs || u->busy_bufs || downstream->buffered) { |
583 | 3628 rc = ngx_http_output_filter(r, u->out_bufs); |
3629 | |
3630 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
|
3631 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
581 | 3632 return; |
3633 } | |
3634 | |
4114
5db098f97e0e
API change: ngx_chain_update_chains() now requires pool.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3976
diff
changeset
|
3635 ngx_chain_update_chains(r->pool, &u->free_bufs, &u->busy_bufs, |
581 | 3636 &u->out_bufs, u->output.tag); |
3637 } | |
3638 | |
3639 if (u->busy_bufs == NULL) { | |
3640 | |
3641 if (u->length == 0 | |
5301
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3642 || (upstream->read->eof && u->length == -1)) |
581 | 3643 { |
3644 ngx_http_upstream_finalize_request(r, u, 0); | |
3645 return; | |
3646 } | |
3647 | |
5301
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3648 if (upstream->read->eof) { |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3649 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
|
3650 "upstream prematurely closed connection"); |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3651 |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3652 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
|
3653 NGX_HTTP_BAD_GATEWAY); |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3654 return; |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3655 } |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3656 |
7982
05e42236e95b
FastCGI: protection from responses with wrong length.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7981
diff
changeset
|
3657 if (upstream->read->error || u->error) { |
5301
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3658 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
|
3659 NGX_HTTP_BAD_GATEWAY); |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3660 return; |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3661 } |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3662 |
581 | 3663 b->pos = b->start; |
3664 b->last = b->start; | |
3665 } | |
3666 } | |
3667 | |
3668 size = b->end - b->last; | |
3669 | |
884 | 3670 if (size && upstream->read->ready) { |
3671 | |
3672 n = upstream->recv(upstream, b->last, size); | |
581 | 3673 |
3674 if (n == NGX_AGAIN) { | |
3675 break; | |
3676 } | |
3677 | |
3678 if (n > 0) { | |
6654
c131f20c9562
Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6594
diff
changeset
|
3679 u->state->bytes_received += n; |
2402 | 3680 u->state->response_length += n; |
3681 | |
581 | 3682 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
|
3683 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
581 | 3684 return; |
3685 } | |
3686 } | |
3687 | |
3688 do_write = 1; | |
3689 | |
3690 continue; | |
3691 } | |
3692 | |
3693 break; | |
3694 } | |
3695 | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3696 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
|
3697 |
884 | 3698 if (downstream->data == r) { |
3699 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
|
3700 != NGX_OK) |
583 | 3701 { |
5295
a489c31c9783
Upstream: ngx_http_upstream_finalize_request(NGX_ERROR) on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5294
diff
changeset
|
3702 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
583 | 3703 return; |
3704 } | |
581 | 3705 } |
3706 | |
1063
e2a6ecc5a3ae
a non-active client connection must not closed after send timeout
Igor Sysoev <igor@sysoev.ru>
parents:
1031
diff
changeset
|
3707 if (downstream->write->active && !downstream->write->ready) { |
884 | 3708 ngx_add_timer(downstream->write, clcf->send_timeout); |
3709 | |
3710 } else if (downstream->write->timer_set) { | |
3711 ngx_del_timer(downstream->write); | |
581 | 3712 } |
3713 | |
7538
08ed570ad93c
Upstream: fixed EOF handling in unbuffered and upgraded modes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7514
diff
changeset
|
3714 if (upstream->read->eof || upstream->read->error) { |
08ed570ad93c
Upstream: fixed EOF handling in unbuffered and upgraded modes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7514
diff
changeset
|
3715 flags = NGX_CLOSE_EVENT; |
08ed570ad93c
Upstream: fixed EOF handling in unbuffered and upgraded modes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7514
diff
changeset
|
3716 |
08ed570ad93c
Upstream: fixed EOF handling in unbuffered and upgraded modes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7514
diff
changeset
|
3717 } else { |
08ed570ad93c
Upstream: fixed EOF handling in unbuffered and upgraded modes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7514
diff
changeset
|
3718 flags = 0; |
08ed570ad93c
Upstream: fixed EOF handling in unbuffered and upgraded modes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7514
diff
changeset
|
3719 } |
08ed570ad93c
Upstream: fixed EOF handling in unbuffered and upgraded modes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7514
diff
changeset
|
3720 |
08ed570ad93c
Upstream: fixed EOF handling in unbuffered and upgraded modes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7514
diff
changeset
|
3721 if (ngx_handle_read_event(upstream->read, flags) != NGX_OK) { |
5295
a489c31c9783
Upstream: ngx_http_upstream_finalize_request(NGX_ERROR) on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5294
diff
changeset
|
3722 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
581 | 3723 return; |
3724 } | |
3725 | |
1063
e2a6ecc5a3ae
a non-active client connection must not closed after send timeout
Igor Sysoev <igor@sysoev.ru>
parents:
1031
diff
changeset
|
3726 if (upstream->read->active && !upstream->read->ready) { |
884 | 3727 ngx_add_timer(upstream->read, u->conf->read_timeout); |
3728 | |
3729 } else if (upstream->read->timer_set) { | |
3730 ngx_del_timer(upstream->read); | |
581 | 3731 } |
3732 } | |
3733 | |
3734 | |
7981
bffcc5af1d72
Upstream: drop extra data sent by upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7895
diff
changeset
|
3735 ngx_int_t |
581 | 3736 ngx_http_upstream_non_buffered_filter_init(void *data) |
3737 { | |
3738 return NGX_OK; | |
3739 } | |
3740 | |
3741 | |
7981
bffcc5af1d72
Upstream: drop extra data sent by upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7895
diff
changeset
|
3742 ngx_int_t |
581 | 3743 ngx_http_upstream_non_buffered_filter(void *data, ssize_t bytes) |
3744 { | |
3745 ngx_http_request_t *r = data; | |
3746 | |
3747 ngx_buf_t *b; | |
3748 ngx_chain_t *cl, **ll; | |
3749 ngx_http_upstream_t *u; | |
3750 | |
3751 u = r->upstream; | |
3752 | |
8299
83c4622053b0
Upstream: fixed zero size buf alerts on extra data (ticket #2117).
Maxim Dounin <mdounin@mdounin.ru>
parents:
8047
diff
changeset
|
3753 if (u->length == 0) { |
83c4622053b0
Upstream: fixed zero size buf alerts on extra data (ticket #2117).
Maxim Dounin <mdounin@mdounin.ru>
parents:
8047
diff
changeset
|
3754 ngx_log_error(NGX_LOG_WARN, r->connection->log, 0, |
83c4622053b0
Upstream: fixed zero size buf alerts on extra data (ticket #2117).
Maxim Dounin <mdounin@mdounin.ru>
parents:
8047
diff
changeset
|
3755 "upstream sent more data than specified in " |
83c4622053b0
Upstream: fixed zero size buf alerts on extra data (ticket #2117).
Maxim Dounin <mdounin@mdounin.ru>
parents:
8047
diff
changeset
|
3756 "\"Content-Length\" header"); |
83c4622053b0
Upstream: fixed zero size buf alerts on extra data (ticket #2117).
Maxim Dounin <mdounin@mdounin.ru>
parents:
8047
diff
changeset
|
3757 return NGX_OK; |
83c4622053b0
Upstream: fixed zero size buf alerts on extra data (ticket #2117).
Maxim Dounin <mdounin@mdounin.ru>
parents:
8047
diff
changeset
|
3758 } |
83c4622053b0
Upstream: fixed zero size buf alerts on extra data (ticket #2117).
Maxim Dounin <mdounin@mdounin.ru>
parents:
8047
diff
changeset
|
3759 |
581 | 3760 for (cl = u->out_bufs, ll = &u->out_bufs; cl; cl = cl->next) { |
3761 ll = &cl->next; | |
3762 } | |
3763 | |
3764 cl = ngx_chain_get_free_buf(r->pool, &u->free_bufs); | |
3765 if (cl == NULL) { | |
3766 return NGX_ERROR; | |
3767 } | |
3768 | |
3769 *ll = cl; | |
3770 | |
3771 cl->buf->flush = 1; | |
3772 cl->buf->memory = 1; | |
3773 | |
3774 b = &u->buffer; | |
3775 | |
3776 cl->buf->pos = b->last; | |
3777 b->last += bytes; | |
3778 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
|
3779 cl->buf->tag = u->output.tag; |
581 | 3780 |
4118
dbddec65fdab
Upstream: r->upstream->length type change to off_t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4117
diff
changeset
|
3781 if (u->length == -1) { |
581 | 3782 return NGX_OK; |
3783 } | |
3784 | |
7981
bffcc5af1d72
Upstream: drop extra data sent by upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7895
diff
changeset
|
3785 if (bytes > u->length) { |
bffcc5af1d72
Upstream: drop extra data sent by upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7895
diff
changeset
|
3786 |
bffcc5af1d72
Upstream: drop extra data sent by upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7895
diff
changeset
|
3787 ngx_log_error(NGX_LOG_WARN, r->connection->log, 0, |
bffcc5af1d72
Upstream: drop extra data sent by upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7895
diff
changeset
|
3788 "upstream sent more data than specified in " |
bffcc5af1d72
Upstream: drop extra data sent by upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7895
diff
changeset
|
3789 "\"Content-Length\" header"); |
bffcc5af1d72
Upstream: drop extra data sent by upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7895
diff
changeset
|
3790 |
bffcc5af1d72
Upstream: drop extra data sent by upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7895
diff
changeset
|
3791 cl->buf->last = cl->buf->pos + u->length; |
bffcc5af1d72
Upstream: drop extra data sent by upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7895
diff
changeset
|
3792 u->length = 0; |
bffcc5af1d72
Upstream: drop extra data sent by upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7895
diff
changeset
|
3793 |
bffcc5af1d72
Upstream: drop extra data sent by upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7895
diff
changeset
|
3794 return NGX_OK; |
bffcc5af1d72
Upstream: drop extra data sent by upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7895
diff
changeset
|
3795 } |
bffcc5af1d72
Upstream: drop extra data sent by upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7895
diff
changeset
|
3796 |
581 | 3797 u->length -= bytes; |
3798 | |
3799 return NGX_OK; | |
3800 } | |
3801 | |
3802 | |
6443
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3803 #if (NGX_THREADS) |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3804 |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3805 static ngx_int_t |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3806 ngx_http_upstream_thread_handler(ngx_thread_task_t *task, ngx_file_t *file) |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3807 { |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3808 ngx_str_t name; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3809 ngx_event_pipe_t *p; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3810 ngx_thread_pool_t *tp; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3811 ngx_http_request_t *r; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3812 ngx_http_core_loc_conf_t *clcf; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3813 |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3814 r = file->thread_ctx; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3815 p = r->upstream->pipe; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3816 |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3817 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3818 tp = clcf->thread_pool; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3819 |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3820 if (tp == NULL) { |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3821 if (ngx_http_complex_value(r, clcf->thread_pool_value, &name) |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3822 != NGX_OK) |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3823 { |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3824 return NGX_ERROR; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3825 } |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3826 |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3827 tp = ngx_thread_pool_get((ngx_cycle_t *) ngx_cycle, &name); |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3828 |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3829 if (tp == NULL) { |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3830 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3831 "thread pool \"%V\" not found", &name); |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3832 return NGX_ERROR; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3833 } |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3834 } |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3835 |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3836 task->event.data = r; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3837 task->event.handler = ngx_http_upstream_thread_event_handler; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3838 |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3839 if (ngx_thread_task_post(tp, task) != NGX_OK) { |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3840 return NGX_ERROR; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3841 } |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3842 |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3843 r->main->blocked++; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3844 r->aio = 1; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3845 p->aio = 1; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3846 |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3847 return NGX_OK; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3848 } |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3849 |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3850 |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3851 static void |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3852 ngx_http_upstream_thread_event_handler(ngx_event_t *ev) |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3853 { |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3854 ngx_connection_t *c; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3855 ngx_http_request_t *r; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3856 |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3857 r = ev->data; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3858 c = r->connection; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3859 |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3860 ngx_http_set_log_request(c->log, r); |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3861 |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3862 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3863 "http upstream thread: \"%V?%V\"", &r->uri, &r->args); |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3864 |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3865 r->main->blocked--; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3866 r->aio = 0; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3867 |
6950
4cb4ffe06785
Threads: fixed request hang with aio_write and subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6923
diff
changeset
|
3868 if (r->done) { |
4cb4ffe06785
Threads: fixed request hang with aio_write and subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6923
diff
changeset
|
3869 /* |
4cb4ffe06785
Threads: fixed request hang with aio_write and subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6923
diff
changeset
|
3870 * trigger connection event handler if the subrequest was |
4cb4ffe06785
Threads: fixed request hang with aio_write and subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6923
diff
changeset
|
3871 * already finalized; this can happen if the handler is used |
4cb4ffe06785
Threads: fixed request hang with aio_write and subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6923
diff
changeset
|
3872 * for sendfile() in threads |
4cb4ffe06785
Threads: fixed request hang with aio_write and subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6923
diff
changeset
|
3873 */ |
4cb4ffe06785
Threads: fixed request hang with aio_write and subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6923
diff
changeset
|
3874 |
4cb4ffe06785
Threads: fixed request hang with aio_write and subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6923
diff
changeset
|
3875 c->write->handler(c->write); |
4cb4ffe06785
Threads: fixed request hang with aio_write and subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6923
diff
changeset
|
3876 |
4cb4ffe06785
Threads: fixed request hang with aio_write and subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6923
diff
changeset
|
3877 } else { |
4cb4ffe06785
Threads: fixed request hang with aio_write and subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6923
diff
changeset
|
3878 r->write_event_handler(r); |
4cb4ffe06785
Threads: fixed request hang with aio_write and subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6923
diff
changeset
|
3879 ngx_http_run_posted_requests(c); |
4cb4ffe06785
Threads: fixed request hang with aio_write and subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6923
diff
changeset
|
3880 } |
6443
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3881 } |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3882 |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3883 #endif |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3884 |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3885 |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3886 static ngx_int_t |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3887 ngx_http_upstream_output_filter(void *data, ngx_chain_t *chain) |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3888 { |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3889 ngx_int_t rc; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3890 ngx_event_pipe_t *p; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3891 ngx_http_request_t *r; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3892 |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3893 r = data; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3894 p = r->upstream->pipe; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3895 |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3896 rc = ngx_http_output_filter(r, chain); |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3897 |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3898 p->aio = r->aio; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3899 |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3900 return rc; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3901 } |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3902 |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3903 |
581 | 3904 static void |
509 | 3905 ngx_http_upstream_process_downstream(ngx_http_request_t *r) |
3906 { | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3907 ngx_event_t *wev; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3908 ngx_connection_t *c; |
509 | 3909 ngx_event_pipe_t *p; |
479 | 3910 ngx_http_upstream_t *u; |
3911 | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3912 c = r->connection; |
479 | 3913 u = r->upstream; |
581 | 3914 p = u->pipe; |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3915 wev = c->write; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3916 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3917 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
|
3918 "http upstream process downstream"); |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3919 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3920 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
|
3921 |
6443
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3922 #if (NGX_THREADS) |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3923 p->aio = r->aio; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3924 #endif |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3925 |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3926 if (wev->timedout) { |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3927 |
6961
903fb1ddc07f
Moved handling of wev->delayed to the connection event handler.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6950
diff
changeset
|
3928 p->downstream_error = 1; |
903fb1ddc07f
Moved handling of wev->delayed to the connection event handler.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6950
diff
changeset
|
3929 c->timedout = 1; |
903fb1ddc07f
Moved handling of wev->delayed to the connection event handler.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6950
diff
changeset
|
3930 ngx_connection_error(c, NGX_ETIMEDOUT, "client timed out"); |
479 | 3931 |
3932 } else { | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3933 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3934 if (wev->delayed) { |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3935 |
527 | 3936 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, |
3937 "http downstream delayed"); | |
3938 | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3939 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
|
3940 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
527 | 3941 } |
3942 | |
3943 return; | |
3944 } | |
3945 | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3946 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
|
3947 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
479 | 3948 return; |
3949 } | |
3950 } | |
577 | 3951 |
5995
5f179f344096
Upstream: upstream argument in ngx_http_upstream_process_request().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5994
diff
changeset
|
3952 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
|
3953 } |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3954 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3955 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3956 static void |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
3957 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
|
3958 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
|
3959 { |
5883
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3960 ngx_event_t *rev; |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3961 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
|
3962 ngx_connection_t *c; |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
3963 |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
3964 c = u->peer.connection; |
5883
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3965 p = u->pipe; |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3966 rev = c->read; |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3967 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3968 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
|
3969 "http upstream process upstream"); |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3970 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3971 c->log->action = "reading upstream"; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3972 |
5883
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3973 if (rev->timedout) { |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3974 |
6961
903fb1ddc07f
Moved handling of wev->delayed to the connection event handler.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6950
diff
changeset
|
3975 p->upstream_error = 1; |
903fb1ddc07f
Moved handling of wev->delayed to the connection event handler.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6950
diff
changeset
|
3976 ngx_connection_error(c, NGX_ETIMEDOUT, "upstream timed out"); |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3977 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3978 } else { |
5883
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3979 |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3980 if (rev->delayed) { |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3981 |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3982 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
|
3983 "http upstream delayed"); |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3984 |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3985 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
|
3986 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
|
3987 } |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3988 |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3989 return; |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3990 } |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3991 |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3992 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
|
3993 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
|
3994 return; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3995 } |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3996 } |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3997 |
5995
5f179f344096
Upstream: upstream argument in ngx_http_upstream_process_request().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5994
diff
changeset
|
3998 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
|
3999 } |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
4000 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
4001 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
4002 static void |
5995
5f179f344096
Upstream: upstream argument in ngx_http_upstream_process_request().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5994
diff
changeset
|
4003 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
|
4004 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
|
4005 { |
5996 | 4006 ngx_temp_file_t *tf; |
4007 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
|
4008 |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
4009 p = u->pipe; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
4010 |
6443
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
4011 #if (NGX_THREADS) |
6876
a5d1b1383dea
Upstream: fixed cache corruption and socket leaks with aio_write.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6853
diff
changeset
|
4012 |
a5d1b1383dea
Upstream: fixed cache corruption and socket leaks with aio_write.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6853
diff
changeset
|
4013 if (p->writing && !p->aio) { |
a5d1b1383dea
Upstream: fixed cache corruption and socket leaks with aio_write.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6853
diff
changeset
|
4014 |
a5d1b1383dea
Upstream: fixed cache corruption and socket leaks with aio_write.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6853
diff
changeset
|
4015 /* |
a5d1b1383dea
Upstream: fixed cache corruption and socket leaks with aio_write.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6853
diff
changeset
|
4016 * make sure to call ngx_event_pipe() |
a5d1b1383dea
Upstream: fixed cache corruption and socket leaks with aio_write.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6853
diff
changeset
|
4017 * if there is an incomplete aio write |
a5d1b1383dea
Upstream: fixed cache corruption and socket leaks with aio_write.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6853
diff
changeset
|
4018 */ |
a5d1b1383dea
Upstream: fixed cache corruption and socket leaks with aio_write.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6853
diff
changeset
|
4019 |
a5d1b1383dea
Upstream: fixed cache corruption and socket leaks with aio_write.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6853
diff
changeset
|
4020 if (ngx_event_pipe(p, 1) == NGX_ABORT) { |
a5d1b1383dea
Upstream: fixed cache corruption and socket leaks with aio_write.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6853
diff
changeset
|
4021 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
a5d1b1383dea
Upstream: fixed cache corruption and socket leaks with aio_write.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6853
diff
changeset
|
4022 return; |
a5d1b1383dea
Upstream: fixed cache corruption and socket leaks with aio_write.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6853
diff
changeset
|
4023 } |
a5d1b1383dea
Upstream: fixed cache corruption and socket leaks with aio_write.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6853
diff
changeset
|
4024 } |
a5d1b1383dea
Upstream: fixed cache corruption and socket leaks with aio_write.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6853
diff
changeset
|
4025 |
6443
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
4026 if (p->writing) { |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
4027 return; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
4028 } |
6876
a5d1b1383dea
Upstream: fixed cache corruption and socket leaks with aio_write.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6853
diff
changeset
|
4029 |
6443
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
4030 #endif |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
4031 |
479 | 4032 if (u->peer.connection) { |
4033 | |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4034 if (u->store) { |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4035 |
2463 | 4036 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
|
4037 |
5298
a7b2db9119e0
Upstream: replaced u->pipe->temp_file with p->temp_file.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5297
diff
changeset
|
4038 tf = p->temp_file; |
4469
24c0dca04eb9
Fix for proxy_store leaving temporary files for subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4464
diff
changeset
|
4039 |
2445
3c6af1fb7586
proxy/fastcgi_store did not delete incomplete files
Igor Sysoev <igor@sysoev.ru>
parents:
2441
diff
changeset
|
4040 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
|
4041 && (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
|
4042 && (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
|
4043 || 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
|
4044 { |
3c6af1fb7586
proxy/fastcgi_store did not delete incomplete files
Igor Sysoev <igor@sysoev.ru>
parents:
2441
diff
changeset
|
4045 ngx_http_upstream_store(r, u); |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4046 } |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4047 } |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4048 } |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4049 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4050 #if (NGX_HTTP_CACHE) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4051 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4052 if (u->cacheable) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4053 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4054 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
|
4055 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
|
4056 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4057 } else if (p->upstream_eof) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4058 |
5298
a7b2db9119e0
Upstream: replaced u->pipe->temp_file with p->temp_file.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5297
diff
changeset
|
4059 tf = p->temp_file; |
4298
186f02886bed
Upstream: don't cache unfinished responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4197
diff
changeset
|
4060 |
5299
b779728b180c
Upstream: fixed store/cache of unfinished responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5298
diff
changeset
|
4061 if (p->length == -1 |
b779728b180c
Upstream: fixed store/cache of unfinished responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5298
diff
changeset
|
4062 && (u->headers_in.content_length_n == -1 |
b779728b180c
Upstream: fixed store/cache of unfinished responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5298
diff
changeset
|
4063 || u->headers_in.content_length_n |
b779728b180c
Upstream: fixed store/cache of unfinished responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5298
diff
changeset
|
4064 == 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
|
4065 { |
186f02886bed
Upstream: don't cache unfinished responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4197
diff
changeset
|
4066 ngx_http_file_cache_update(r, tf); |
186f02886bed
Upstream: don't cache unfinished responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4197
diff
changeset
|
4067 |
186f02886bed
Upstream: don't cache unfinished responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4197
diff
changeset
|
4068 } else { |
186f02886bed
Upstream: don't cache unfinished responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4197
diff
changeset
|
4069 ngx_http_file_cache_free(r->cache, tf); |
186f02886bed
Upstream: don't cache unfinished responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4197
diff
changeset
|
4070 } |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4071 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4072 } 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
|
4073 ngx_http_file_cache_free(r->cache, p->temp_file); |
479 | 4074 } |
4075 } | |
4076 | |
4077 #endif | |
4078 | |
4079 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
|
4080 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
483 | 4081 "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
|
4082 |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
4083 if (p->upstream_done |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
4084 || (p->upstream_eof && p->length == -1)) |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
4085 { |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
4086 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
|
4087 return; |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
4088 } |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
4089 |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
4090 if (p->upstream_eof) { |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
4091 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
|
4092 "upstream prematurely closed connection"); |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
4093 } |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
4094 |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
4095 ngx_http_upstream_finalize_request(r, u, NGX_HTTP_BAD_GATEWAY); |
479 | 4096 return; |
4097 } | |
4098 } | |
4099 | |
4100 if (p->downstream_error) { | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
4101 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
483 | 4102 "http upstream downstream error"); |
479 | 4103 |
2757
9cc973b46af1
get a full response if the response is cacheable or storable even
Igor Sysoev <igor@sysoev.ru>
parents:
2708
diff
changeset
|
4104 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
|
4105 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
479 | 4106 } |
4107 } | |
4108 } | |
4109 | |
4110 | |
487 | 4111 static void |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4112 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
|
4113 { |
1947
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
4114 size_t root; |
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
4115 time_t lm; |
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
4116 ngx_str_t path; |
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
4117 ngx_temp_file_t *tf; |
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
4118 ngx_ext_rename_file_t ext; |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4119 |
1777 | 4120 tf = u->pipe->temp_file; |
4121 | |
4122 if (tf->file.fd == NGX_INVALID_FILE) { | |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4123 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4124 /* create file for empty 200 response */ |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4125 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4126 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
|
4127 if (tf == NULL) { |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4128 return; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4129 } |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4130 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4131 tf->file.fd = NGX_INVALID_FILE; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4132 tf->file.log = r->connection->log; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4133 tf->path = u->conf->temp_path; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4134 tf->pool = r->pool; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4135 tf->persistent = 1; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4136 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4137 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
|
4138 tf->persistent, tf->clean, tf->access) |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4139 != NGX_OK) |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4140 { |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4141 return; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4142 } |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4143 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4144 u->pipe->temp_file = tf; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4145 } |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4146 |
1947
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
4147 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
|
4148 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
|
4149 ext.time = -1; |
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
4150 ext.create_path = 1; |
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
4151 ext.delete_file = 1; |
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
4152 ext.log = r->connection->log; |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4153 |
1705 | 4154 if (u->headers_in.last_modified) { |
4155 | |
6180
8b6fa4842133
Moved ngx_http_parse_time() to core, renamed accordingly.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6147
diff
changeset
|
4156 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
|
4157 u->headers_in.last_modified->value.len); |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4158 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4159 if (lm != NGX_ERROR) { |
1947
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
4160 ext.time = lm; |
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
4161 ext.fd = tf->file.fd; |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4162 } |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4163 } |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4164 |
1295
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
4165 if (u->conf->store_lengths == NULL) { |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
4166 |
5770
9de5820bb3e0
Upstream: ngx_http_upstream_store() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5757
diff
changeset
|
4167 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
|
4168 return; |
9de5820bb3e0
Upstream: ngx_http_upstream_store() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5757
diff
changeset
|
4169 } |
1295
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
4170 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
4171 } else { |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
4172 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
|
4173 u->conf->store_values->elts) |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
4174 == NULL) |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
4175 { |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
4176 return; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
4177 } |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
4178 } |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4179 |
3032
524ba56ba9f7
fix copy destination name length, introduced in r3025
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
4180 path.len--; |
524ba56ba9f7
fix copy destination name length, introduced in r3025
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
4181 |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4182 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
|
4183 "upstream stores \"%s\" to \"%s\"", |
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
4184 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
|
4185 |
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
4186 (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
|
4187 |
9de5820bb3e0
Upstream: ngx_http_upstream_store() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5757
diff
changeset
|
4188 u->store = 0; |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4189 } |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4190 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4191 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4192 static void |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
4193 ngx_http_upstream_dummy_handler(ngx_http_request_t *r, ngx_http_upstream_t *u) |
479 | 4194 { |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
4195 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
479 | 4196 "http upstream dummy handler"); |
4197 } | |
4198 | |
4199 | |
487 | 4200 static void |
4201 ngx_http_upstream_next(ngx_http_request_t *r, ngx_http_upstream_t *u, | |
4202 ngx_uint_t ft_type) | |
479 | 4203 { |
5832
d09b689911ac
Upstream: limited next_upstream time and tries (ticket #544).
Roman Arutyunyan <arut@nginx.com>
parents:
5827
diff
changeset
|
4204 ngx_msec_t timeout; |
884 | 4205 ngx_uint_t status, state; |
479 | 4206 |
4207 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
884 | 4208 "http next upstream, %xi", ft_type); |
479 | 4209 |
5132
9bcf89ca78d2
Upstream: only call peer.free() if peer.get() selected a peer.
Ruslan Ermilov <ru@nginx.com>
parents:
5121
diff
changeset
|
4210 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
|
4211 |
7429
e573d74299a0
Upstream: implemented $upstream_bytes_sent.
Ruslan Ermilov <ru@nginx.com>
parents:
7397
diff
changeset
|
4212 if (u->peer.connection) { |
e573d74299a0
Upstream: implemented $upstream_bytes_sent.
Ruslan Ermilov <ru@nginx.com>
parents:
7397
diff
changeset
|
4213 u->state->bytes_sent = u->peer.connection->sent; |
e573d74299a0
Upstream: implemented $upstream_bytes_sent.
Ruslan Ermilov <ru@nginx.com>
parents:
7397
diff
changeset
|
4214 } |
e573d74299a0
Upstream: implemented $upstream_bytes_sent.
Ruslan Ermilov <ru@nginx.com>
parents:
7397
diff
changeset
|
4215 |
5231
05c53652e7b4
Upstream: http_403 support in proxy_next_upstream (and friends).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5217
diff
changeset
|
4216 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
|
4217 || 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
|
4218 { |
5132
9bcf89ca78d2
Upstream: only call peer.free() if peer.get() selected a peer.
Ruslan Ermilov <ru@nginx.com>
parents:
5121
diff
changeset
|
4219 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
|
4220 |
5132
9bcf89ca78d2
Upstream: only call peer.free() if peer.get() selected a peer.
Ruslan Ermilov <ru@nginx.com>
parents:
5121
diff
changeset
|
4221 } else { |
9bcf89ca78d2
Upstream: only call peer.free() if peer.get() selected a peer.
Ruslan Ermilov <ru@nginx.com>
parents:
5121
diff
changeset
|
4222 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
|
4223 } |
9bcf89ca78d2
Upstream: only call peer.free() if peer.get() selected a peer.
Ruslan Ermilov <ru@nginx.com>
parents:
5121
diff
changeset
|
4224 |
1378 | 4225 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
|
4226 u->peer.sockaddr = NULL; |
1378 | 4227 } |
525 | 4228 |
479 | 4229 if (ft_type == NGX_HTTP_UPSTREAM_FT_TIMEOUT) { |
4230 ngx_log_error(NGX_LOG_ERR, r->connection->log, NGX_ETIMEDOUT, | |
4231 "upstream timed out"); | |
4232 } | |
577 | 4233 |
6466
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4234 if (u->peer.cached && ft_type == NGX_HTTP_UPSTREAM_FT_ERROR) { |
4115
70a45a504905
Workaround for cpu hog on errors with cached connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4114
diff
changeset
|
4235 /* TODO: inform balancer instead */ |
70a45a504905
Workaround for cpu hog on errors with cached connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4114
diff
changeset
|
4236 u->peer.tries++; |
6466
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4237 } |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4238 |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4239 switch (ft_type) { |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4240 |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4241 case NGX_HTTP_UPSTREAM_FT_TIMEOUT: |
7130
882ad033d43c
Upstream: fixed $upstream_status when upstream returns 503/504.
Ruslan Ermilov <ru@nginx.com>
parents:
7126
diff
changeset
|
4242 case NGX_HTTP_UPSTREAM_FT_HTTP_504: |
6466
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4243 status = NGX_HTTP_GATEWAY_TIME_OUT; |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4244 break; |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4245 |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4246 case NGX_HTTP_UPSTREAM_FT_HTTP_500: |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4247 status = NGX_HTTP_INTERNAL_SERVER_ERROR; |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4248 break; |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4249 |
7130
882ad033d43c
Upstream: fixed $upstream_status when upstream returns 503/504.
Ruslan Ermilov <ru@nginx.com>
parents:
7126
diff
changeset
|
4250 case NGX_HTTP_UPSTREAM_FT_HTTP_503: |
882ad033d43c
Upstream: fixed $upstream_status when upstream returns 503/504.
Ruslan Ermilov <ru@nginx.com>
parents:
7126
diff
changeset
|
4251 status = NGX_HTTP_SERVICE_UNAVAILABLE; |
882ad033d43c
Upstream: fixed $upstream_status when upstream returns 503/504.
Ruslan Ermilov <ru@nginx.com>
parents:
7126
diff
changeset
|
4252 break; |
882ad033d43c
Upstream: fixed $upstream_status when upstream returns 503/504.
Ruslan Ermilov <ru@nginx.com>
parents:
7126
diff
changeset
|
4253 |
6466
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4254 case NGX_HTTP_UPSTREAM_FT_HTTP_403: |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4255 status = NGX_HTTP_FORBIDDEN; |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4256 break; |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4257 |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4258 case NGX_HTTP_UPSTREAM_FT_HTTP_404: |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4259 status = NGX_HTTP_NOT_FOUND; |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4260 break; |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4261 |
6966
fa56ab75cffc
Upstream: allow recovery from "429 Too Many Requests" response.
Piotr Sikora <piotrsikora@google.com>
parents:
6961
diff
changeset
|
4262 case NGX_HTTP_UPSTREAM_FT_HTTP_429: |
fa56ab75cffc
Upstream: allow recovery from "429 Too Many Requests" response.
Piotr Sikora <piotrsikora@google.com>
parents:
6961
diff
changeset
|
4263 status = NGX_HTTP_TOO_MANY_REQUESTS; |
fa56ab75cffc
Upstream: allow recovery from "429 Too Many Requests" response.
Piotr Sikora <piotrsikora@google.com>
parents:
6961
diff
changeset
|
4264 break; |
fa56ab75cffc
Upstream: allow recovery from "429 Too Many Requests" response.
Piotr Sikora <piotrsikora@google.com>
parents:
6961
diff
changeset
|
4265 |
6466
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4266 /* |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4267 * NGX_HTTP_UPSTREAM_FT_BUSY_LOCK and NGX_HTTP_UPSTREAM_FT_MAX_WAITING |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4268 * never reach here |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4269 */ |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4270 |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4271 default: |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4272 status = NGX_HTTP_BAD_GATEWAY; |
479 | 4273 } |
4274 | |
583 | 4275 if (r->connection->error) { |
479 | 4276 ngx_http_upstream_finalize_request(r, u, |
4277 NGX_HTTP_CLIENT_CLOSED_REQUEST); | |
4278 return; | |
4279 } | |
4280 | |
6466
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4281 u->state->status = status; |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4282 |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4283 timeout = u->conf->next_upstream_timeout; |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4284 |
6467
91c8d990fb45
Upstream: proxy_next_upstream non_idempotent.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6466
diff
changeset
|
4285 if (u->request_sent |
91c8d990fb45
Upstream: proxy_next_upstream non_idempotent.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6466
diff
changeset
|
4286 && (r->method & (NGX_HTTP_POST|NGX_HTTP_LOCK|NGX_HTTP_PATCH))) |
91c8d990fb45
Upstream: proxy_next_upstream non_idempotent.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6466
diff
changeset
|
4287 { |
91c8d990fb45
Upstream: proxy_next_upstream non_idempotent.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6466
diff
changeset
|
4288 ft_type |= NGX_HTTP_UPSTREAM_FT_NON_IDEMPOTENT; |
91c8d990fb45
Upstream: proxy_next_upstream non_idempotent.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6466
diff
changeset
|
4289 } |
91c8d990fb45
Upstream: proxy_next_upstream non_idempotent.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6466
diff
changeset
|
4290 |
6466
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4291 if (u->peer.tries == 0 |
6467
91c8d990fb45
Upstream: proxy_next_upstream non_idempotent.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6466
diff
changeset
|
4292 || ((u->conf->next_upstream & ft_type) != ft_type) |
6466
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4293 || (u->request_sent && r->request_body_no_buffering) |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4294 || (timeout && ngx_current_msec - u->peer.start_time >= timeout)) |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4295 { |
479 | 4296 #if (NGX_HTTP_CACHE) |
4297 | |
6466
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4298 if (u->cache_status == NGX_HTTP_CACHE_EXPIRED |
6905
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4299 && ((u->conf->cache_use_stale & ft_type) || r->cache->stale_error)) |
6466
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4300 { |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4301 ngx_int_t rc; |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4302 |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4303 rc = u->reinit_request(r); |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4304 |
7126
77fe752b4586
Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7125
diff
changeset
|
4305 if (rc != NGX_OK) { |
77fe752b4586
Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7125
diff
changeset
|
4306 ngx_http_upstream_finalize_request(r, u, rc); |
77fe752b4586
Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7125
diff
changeset
|
4307 return; |
77fe752b4586
Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7125
diff
changeset
|
4308 } |
77fe752b4586
Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7125
diff
changeset
|
4309 |
77fe752b4586
Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7125
diff
changeset
|
4310 u->cache_status = NGX_HTTP_CACHE_STALE; |
77fe752b4586
Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7125
diff
changeset
|
4311 rc = ngx_http_upstream_cache_send(r, u); |
77fe752b4586
Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7125
diff
changeset
|
4312 |
77fe752b4586
Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7125
diff
changeset
|
4313 if (rc == NGX_DONE) { |
77fe752b4586
Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7125
diff
changeset
|
4314 return; |
77fe752b4586
Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7125
diff
changeset
|
4315 } |
77fe752b4586
Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7125
diff
changeset
|
4316 |
77fe752b4586
Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7125
diff
changeset
|
4317 if (rc == NGX_HTTP_UPSTREAM_INVALID_HEADER) { |
77fe752b4586
Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7125
diff
changeset
|
4318 rc = NGX_HTTP_INTERNAL_SERVER_ERROR; |
479 | 4319 } |
6466
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4320 |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4321 ngx_http_upstream_finalize_request(r, u, rc); |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4322 return; |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4323 } |
479 | 4324 #endif |
4325 | |
6466
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4326 ngx_http_upstream_finalize_request(r, u, status); |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4327 return; |
479 | 4328 } |
4329 | |
4330 if (u->peer.connection) { | |
4331 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
4332 "close http upstream connection: %d", | |
4333 u->peer.connection->fd); | |
577 | 4334 #if (NGX_HTTP_SSL) |
884 | 4335 |
577 | 4336 if (u->peer.connection->ssl) { |
884 | 4337 u->peer.connection->ssl->no_wait_shutdown = 1; |
4338 u->peer.connection->ssl->no_send_shutdown = 1; | |
4339 | |
4340 (void) ngx_ssl_shutdown(u->peer.connection); | |
577 | 4341 } |
4342 #endif | |
884 | 4343 |
4138
70e1ee2307f9
Fix of separate pool for upstream connections (r4117).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4124
diff
changeset
|
4344 if (u->peer.connection->pool) { |
70e1ee2307f9
Fix of separate pool for upstream connections (r4117).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4124
diff
changeset
|
4345 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
|
4346 } |
70e1ee2307f9
Fix of separate pool for upstream connections (r4117).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4124
diff
changeset
|
4347 |
479 | 4348 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
|
4349 u->peer.connection = NULL; |
479 | 4350 } |
4351 | |
4352 ngx_http_upstream_connect(r, u); | |
4353 } | |
4354 | |
4355 | |
487 | 4356 static void |
569 | 4357 ngx_http_upstream_cleanup(void *data) |
4358 { | |
4359 ngx_http_request_t *r = data; | |
4360 | |
4361 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
4362 "cleanup http upstream request: \"%V\"", &r->uri); | |
4363 | |
5167
85ee9d858dcb
Upstream: removed surplus ngx_resolve_name_done() call.
Valentin Bartenev <vbart@nginx.com>
parents:
5142
diff
changeset
|
4364 ngx_http_upstream_finalize_request(r, r->upstream, NGX_DONE); |
569 | 4365 } |
4366 | |
4367 | |
4368 static void | |
487 | 4369 ngx_http_upstream_finalize_request(ngx_http_request_t *r, |
4370 ngx_http_upstream_t *u, ngx_int_t rc) | |
479 | 4371 { |
6146
59fc60585f1e
Upstream: times to obtain header/response are stored as ngx_msec_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6125
diff
changeset
|
4372 ngx_uint_t flush; |
563 | 4373 |
483 | 4374 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
4375 "finalize http upstream request: %i", rc); | |
479 | 4376 |
5994
5abf5af257a7
Upstream: avoid duplicate finalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5992
diff
changeset
|
4377 if (u->cleanup == NULL) { |
5abf5af257a7
Upstream: avoid duplicate finalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5992
diff
changeset
|
4378 /* the request was already finalized */ |
5abf5af257a7
Upstream: avoid duplicate finalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5992
diff
changeset
|
4379 ngx_http_finalize_request(r, NGX_DONE); |
5abf5af257a7
Upstream: avoid duplicate finalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5992
diff
changeset
|
4380 return; |
5abf5af257a7
Upstream: avoid duplicate finalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5992
diff
changeset
|
4381 } |
5abf5af257a7
Upstream: avoid duplicate finalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5992
diff
changeset
|
4382 |
5abf5af257a7
Upstream: avoid duplicate finalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5992
diff
changeset
|
4383 *u->cleanup = NULL; |
5abf5af257a7
Upstream: avoid duplicate finalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5992
diff
changeset
|
4384 u->cleanup = NULL; |
569 | 4385 |
3169
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
4386 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
|
4387 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
|
4388 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
|
4389 } |
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
4390 |
7397
860d3907da1c
Upstream: revised upstream response time variables.
Vladimir Homutov <vl@nginx.com>
parents:
7371
diff
changeset
|
4391 if (u->state && u->state->response_time == (ngx_msec_t) -1) { |
860d3907da1c
Upstream: revised upstream response time variables.
Vladimir Homutov <vl@nginx.com>
parents:
7371
diff
changeset
|
4392 u->state->response_time = ngx_current_msec - u->start_time; |
2402 | 4393 |
5169
f6bbe77794aa
Upstream: fixed $upstream_response_length without buffering.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5167
diff
changeset
|
4394 if (u->pipe && u->pipe->read_length) { |
6654
c131f20c9562
Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6594
diff
changeset
|
4395 u->state->bytes_received += u->pipe->read_length |
c131f20c9562
Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6594
diff
changeset
|
4396 - u->pipe->preread_size; |
2402 | 4397 u->state->response_length = u->pipe->read_length; |
4398 } | |
7429
e573d74299a0
Upstream: implemented $upstream_bytes_sent.
Ruslan Ermilov <ru@nginx.com>
parents:
7397
diff
changeset
|
4399 |
e573d74299a0
Upstream: implemented $upstream_bytes_sent.
Ruslan Ermilov <ru@nginx.com>
parents:
7397
diff
changeset
|
4400 if (u->peer.connection) { |
e573d74299a0
Upstream: implemented $upstream_bytes_sent.
Ruslan Ermilov <ru@nginx.com>
parents:
7397
diff
changeset
|
4401 u->state->bytes_sent = u->peer.connection->sent; |
e573d74299a0
Upstream: implemented $upstream_bytes_sent.
Ruslan Ermilov <ru@nginx.com>
parents:
7397
diff
changeset
|
4402 } |
563 | 4403 } |
4404 | |
479 | 4405 u->finalize_request(r, rc); |
4406 | |
5132
9bcf89ca78d2
Upstream: only call peer.free() if peer.get() selected a peer.
Ruslan Ermilov <ru@nginx.com>
parents:
5121
diff
changeset
|
4407 if (u->peer.free && u->peer.sockaddr) { |
1658 | 4408 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
|
4409 u->peer.sockaddr = NULL; |
1658 | 4410 } |
884 | 4411 |
479 | 4412 if (u->peer.connection) { |
884 | 4413 |
577 | 4414 #if (NGX_HTTP_SSL) |
4415 | |
4416 /* TODO: do not shutdown persistent connection */ | |
4417 | |
4418 if (u->peer.connection->ssl) { | |
884 | 4419 |
4420 /* | |
4421 * We send the "close notify" shutdown alert to the upstream only | |
4422 * and do not wait its "close notify" shutdown alert. | |
4423 * It is acceptable according to the TLS standard. | |
4424 */ | |
4425 | |
4426 u->peer.connection->ssl->no_wait_shutdown = 1; | |
4427 | |
4428 (void) ngx_ssl_shutdown(u->peer.connection); | |
577 | 4429 } |
4430 #endif | |
884 | 4431 |
4432 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
4433 "close http upstream connection: %d", | |
4434 u->peer.connection->fd); | |
4435 | |
4138
70e1ee2307f9
Fix of separate pool for upstream connections (r4117).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4124
diff
changeset
|
4436 if (u->peer.connection->pool) { |
70e1ee2307f9
Fix of separate pool for upstream connections (r4117).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4124
diff
changeset
|
4437 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
|
4438 } |
70e1ee2307f9
Fix of separate pool for upstream connections (r4117).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4124
diff
changeset
|
4439 |
479 | 4440 ngx_close_connection(u->peer.connection); |
4441 } | |
4442 | |
483 | 4443 u->peer.connection = NULL; |
4444 | |
581 | 4445 if (u->pipe && u->pipe->temp_file) { |
479 | 4446 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
4447 "http upstream temp fd: %d", | |
581 | 4448 u->pipe->temp_file->file.fd); |
479 | 4449 } |
4450 | |
4469
24c0dca04eb9
Fix for proxy_store leaving temporary files for subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4464
diff
changeset
|
4451 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
|
4452 && 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
|
4453 { |
24c0dca04eb9
Fix for proxy_store leaving temporary files for subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4464
diff
changeset
|
4454 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
|
4455 == NGX_FILE_ERROR) |
24c0dca04eb9
Fix for proxy_store leaving temporary files for subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4464
diff
changeset
|
4456 { |
24c0dca04eb9
Fix for proxy_store leaving temporary files for subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4464
diff
changeset
|
4457 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
|
4458 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
|
4459 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
|
4460 } |
24c0dca04eb9
Fix for proxy_store leaving temporary files for subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4464
diff
changeset
|
4461 } |
24c0dca04eb9
Fix for proxy_store leaving temporary files for subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4464
diff
changeset
|
4462 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4463 #if (NGX_HTTP_CACHE) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4464 |
3940
22f3e9197096
revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents:
3934
diff
changeset
|
4465 if (r->cache) { |
22f3e9197096
revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents:
3934
diff
changeset
|
4466 |
22f3e9197096
revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents:
3934
diff
changeset
|
4467 if (u->cacheable) { |
22f3e9197096
revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents:
3934
diff
changeset
|
4468 |
22f3e9197096
revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents:
3934
diff
changeset
|
4469 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
|
4470 time_t valid; |
22f3e9197096
revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents:
3934
diff
changeset
|
4471 |
22f3e9197096
revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents:
3934
diff
changeset
|
4472 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
|
4473 |
22f3e9197096
revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents:
3934
diff
changeset
|
4474 if (valid) { |
22f3e9197096
revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents:
3934
diff
changeset
|
4475 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
|
4476 r->cache->error = rc; |
22f3e9197096
revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents:
3934
diff
changeset
|
4477 } |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4478 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4479 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4480 |
3711
ce6ba077c270
several changes in cache cleanup handling:
Igor Sysoev <igor@sysoev.ru>
parents:
3709
diff
changeset
|
4481 ngx_http_file_cache_free(r->cache, u->pipe->temp_file); |
479 | 4482 } |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4483 |
479 | 4484 #endif |
4485 | |
6909
5850fed24639
Upstream: read handler cleared on upstream finalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6906
diff
changeset
|
4486 r->read_event_handler = ngx_http_block_reading; |
5850fed24639
Upstream: read handler cleared on upstream finalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6906
diff
changeset
|
4487 |
515 | 4488 if (rc == NGX_DECLINED) { |
4489 return; | |
4490 } | |
4491 | |
483 | 4492 r->connection->log->action = "sending to client"; |
4493 | |
5303
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
4494 if (!u->header_sent |
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
4495 || rc == NGX_HTTP_REQUEST_TIME_OUT |
7188
93abb5a855d6
Upstream: fixed "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7174
diff
changeset
|
4496 || rc == NGX_HTTP_CLIENT_CLOSED_REQUEST) |
4151
3549db8ceaf2
Cache: fix for sending of stale responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4143
diff
changeset
|
4497 { |
5303
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
4498 ngx_http_finalize_request(r, rc); |
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
4499 return; |
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
4500 } |
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
4501 |
5304
d3eab5e2df5f
Upstream: no last buffer on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5303
diff
changeset
|
4502 flush = 0; |
d3eab5e2df5f
Upstream: no last buffer on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5303
diff
changeset
|
4503 |
d3eab5e2df5f
Upstream: no last buffer on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5303
diff
changeset
|
4504 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) { |
d3eab5e2df5f
Upstream: no last buffer on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5303
diff
changeset
|
4505 rc = NGX_ERROR; |
d3eab5e2df5f
Upstream: no last buffer on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5303
diff
changeset
|
4506 flush = 1; |
5303
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
4507 } |
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
4508 |
7188
93abb5a855d6
Upstream: fixed "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7174
diff
changeset
|
4509 if (r->header_only |
93abb5a855d6
Upstream: fixed "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7174
diff
changeset
|
4510 || (u->pipe && u->pipe->downstream_error)) |
93abb5a855d6
Upstream: fixed "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7174
diff
changeset
|
4511 { |
5303
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
4512 ngx_http_finalize_request(r, rc); |
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
4513 return; |
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
4514 } |
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
4515 |
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
4516 if (rc == 0) { |
7230
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
4517 |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
4518 if (ngx_http_upstream_process_trailers(r, u) != NGX_OK) { |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
4519 ngx_http_finalize_request(r, NGX_ERROR); |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
4520 return; |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
4521 } |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
4522 |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
4523 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
|
4524 |
d3eab5e2df5f
Upstream: no last buffer on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5303
diff
changeset
|
4525 } else if (flush) { |
d3eab5e2df5f
Upstream: no last buffer on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5303
diff
changeset
|
4526 r->keepalive = 0; |
d3eab5e2df5f
Upstream: no last buffer on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5303
diff
changeset
|
4527 rc = ngx_http_send_special(r, NGX_HTTP_FLUSH); |
479 | 4528 } |
4529 | |
4530 ngx_http_finalize_request(r, rc); | |
4531 } | |
4532 | |
4533 | |
509 | 4534 static ngx_int_t |
4535 ngx_http_upstream_process_header_line(ngx_http_request_t *r, ngx_table_elt_t *h, | |
4536 ngx_uint_t offset) | |
577 | 4537 { |
509 | 4538 ngx_table_elt_t **ph; |
577 | 4539 |
509 | 4540 ph = (ngx_table_elt_t **) ((char *) &r->upstream->headers_in + offset); |
4541 | |
4542 if (*ph == NULL) { | |
4543 *ph = h; | |
4544 } | |
4545 | |
4546 return NGX_OK; | |
4547 } | |
4548 | |
4549 | |
4550 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
|
4551 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
|
4552 ngx_uint_t offset) |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4553 { |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4554 return NGX_OK; |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4555 } |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4556 |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4557 |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4558 static ngx_int_t |
4117
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
4559 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
|
4560 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
|
4561 { |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
4562 ngx_http_upstream_t *u; |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
4563 |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
4564 u = r->upstream; |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
4565 |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
4566 u->headers_in.content_length = h; |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
4567 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
|
4568 |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
4569 return NGX_OK; |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
4570 } |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
4571 |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
4572 |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
4573 static ngx_int_t |
5732
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
4574 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
|
4575 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
|
4576 { |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
4577 ngx_http_upstream_t *u; |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
4578 |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
4579 u = r->upstream; |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
4580 |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
4581 u->headers_in.last_modified = h; |
7093
acc2cddc7b45
Upstream: unconditional parsing of last_modified_time.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7077
diff
changeset
|
4582 u->headers_in.last_modified_time = ngx_parse_http_time(h->value.data, |
acc2cddc7b45
Upstream: unconditional parsing of last_modified_time.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7077
diff
changeset
|
4583 h->value.len); |
5732
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
4584 |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
4585 return NGX_OK; |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
4586 } |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
4587 |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
4588 |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
4589 static ngx_int_t |
3669
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
4590 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
|
4591 ngx_uint_t offset) |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
4592 { |
5677
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4593 ngx_array_t *pa; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4594 ngx_table_elt_t **ph; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4595 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
|
4596 |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
4597 u = r->upstream; |
5677
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4598 pa = &u->headers_in.cookies; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4599 |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4600 if (pa->elts == NULL) { |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4601 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
|
4602 { |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4603 return NGX_ERROR; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4604 } |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4605 } |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4606 |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4607 ph = ngx_array_push(pa); |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4608 if (ph == NULL) { |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4609 return NGX_ERROR; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4610 } |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4611 |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4612 *ph = h; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4613 |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4614 #if (NGX_HTTP_CACHE) |
3669
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
4615 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
|
4616 u->cacheable = 0; |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
4617 } |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
4618 #endif |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
4619 |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
4620 return NGX_OK; |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
4621 } |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
4622 |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
4623 |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
4624 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
|
4625 ngx_http_upstream_process_cache_control(ngx_http_request_t *r, |
509 | 4626 ngx_table_elt_t *h, ngx_uint_t offset) |
4627 { | |
2786
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4628 ngx_array_t *pa; |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4629 ngx_table_elt_t **ph; |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4630 ngx_http_upstream_t *u; |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4631 |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4632 u = r->upstream; |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4633 pa = &u->headers_in.cache_control; |
509 | 4634 |
4635 if (pa->elts == NULL) { | |
6474 | 4636 if (ngx_array_init(pa, r->pool, 2, sizeof(ngx_table_elt_t *)) != NGX_OK) |
4637 { | |
4638 return NGX_ERROR; | |
4639 } | |
509 | 4640 } |
4641 | |
4642 ph = ngx_array_push(pa); | |
4643 if (ph == NULL) { | |
4644 return NGX_ERROR; | |
4645 } | |
4646 | |
4647 *ph = h; | |
4648 | |
2708
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
4649 #if (NGX_HTTP_CACHE) |
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
4650 { |
5911
88d55e5934f7
Cache: add support for Cache-Control's s-maxage response directive.
Piotr Sikora <piotr@cloudflare.com>
parents:
5905
diff
changeset
|
4651 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
|
4652 ngx_int_t n; |
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
4653 |
2786
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4654 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
|
4655 return NGX_OK; |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4656 } |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4657 |
2669
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4658 if (r->cache == NULL) { |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4659 return NGX_OK; |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4660 } |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4661 |
5500
6a3ab6fdd70f
Upstream: Cache-Control preferred over Expires.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5489
diff
changeset
|
4662 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
|
4663 return NGX_OK; |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4664 } |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4665 |
5911
88d55e5934f7
Cache: add support for Cache-Control's s-maxage response directive.
Piotr Sikora <piotr@cloudflare.com>
parents:
5905
diff
changeset
|
4666 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
|
4667 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
|
4668 |
88d55e5934f7
Cache: add support for Cache-Control's s-maxage response directive.
Piotr Sikora <piotr@cloudflare.com>
parents:
5905
diff
changeset
|
4669 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
|
4670 || 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
|
4671 || 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
|
4672 { |
2786
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4673 u->cacheable = 0; |
2669
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4674 return NGX_OK; |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4675 } |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4676 |
5911
88d55e5934f7
Cache: add support for Cache-Control's s-maxage response directive.
Piotr Sikora <piotr@cloudflare.com>
parents:
5905
diff
changeset
|
4677 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
|
4678 offset = 9; |
88d55e5934f7
Cache: add support for Cache-Control's s-maxage response directive.
Piotr Sikora <piotr@cloudflare.com>
parents:
5905
diff
changeset
|
4679 |
88d55e5934f7
Cache: add support for Cache-Control's s-maxage response directive.
Piotr Sikora <piotr@cloudflare.com>
parents:
5905
diff
changeset
|
4680 if (p == NULL) { |
88d55e5934f7
Cache: add support for Cache-Control's s-maxage response directive.
Piotr Sikora <piotr@cloudflare.com>
parents:
5905
diff
changeset
|
4681 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
|
4682 offset = 8; |
88d55e5934f7
Cache: add support for Cache-Control's s-maxage response directive.
Piotr Sikora <piotr@cloudflare.com>
parents:
5905
diff
changeset
|
4683 } |
2669
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4684 |
6905
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4685 if (p) { |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4686 n = 0; |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4687 |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4688 for (p += offset; p < last; p++) { |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4689 if (*p == ',' || *p == ';' || *p == ' ') { |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4690 break; |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4691 } |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4692 |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4693 if (*p >= '0' && *p <= '9') { |
7067
e3723f2a11b7
Parenthesized ASCII-related calculations.
Valentin Bartenev <vbart@nginx.com>
parents:
7042
diff
changeset
|
4694 n = n * 10 + (*p - '0'); |
6905
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4695 continue; |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4696 } |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4697 |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4698 u->cacheable = 0; |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4699 return NGX_OK; |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4700 } |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4701 |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4702 if (n == 0) { |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4703 u->cacheable = 0; |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4704 return NGX_OK; |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4705 } |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4706 |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4707 r->cache->valid_sec = ngx_time() + n; |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4708 } |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4709 |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4710 p = ngx_strlcasestrn(start, last, (u_char *) "stale-while-revalidate=", |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4711 23 - 1); |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4712 |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4713 if (p) { |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4714 n = 0; |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4715 |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4716 for (p += 23; p < last; p++) { |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4717 if (*p == ',' || *p == ';' || *p == ' ') { |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4718 break; |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4719 } |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4720 |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4721 if (*p >= '0' && *p <= '9') { |
7067
e3723f2a11b7
Parenthesized ASCII-related calculations.
Valentin Bartenev <vbart@nginx.com>
parents:
7042
diff
changeset
|
4722 n = n * 10 + (*p - '0'); |
6905
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4723 continue; |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4724 } |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4725 |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4726 u->cacheable = 0; |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4727 return NGX_OK; |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4728 } |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4729 |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4730 r->cache->updating_sec = n; |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4731 r->cache->error_sec = n; |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4732 } |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4733 |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4734 p = ngx_strlcasestrn(start, last, (u_char *) "stale-if-error=", 15 - 1); |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4735 |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4736 if (p) { |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4737 n = 0; |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4738 |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4739 for (p += 15; p < last; p++) { |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4740 if (*p == ',' || *p == ';' || *p == ' ') { |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4741 break; |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4742 } |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4743 |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4744 if (*p >= '0' && *p <= '9') { |
7067
e3723f2a11b7
Parenthesized ASCII-related calculations.
Valentin Bartenev <vbart@nginx.com>
parents:
7042
diff
changeset
|
4745 n = n * 10 + (*p - '0'); |
6905
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4746 continue; |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4747 } |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4748 |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4749 u->cacheable = 0; |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4750 return NGX_OK; |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4751 } |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4752 |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4753 r->cache->error_sec = n; |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4754 } |
2708
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
4755 } |
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
4756 #endif |
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
4757 |
509 | 4758 return NGX_OK; |
4759 } | |
4760 | |
4761 | |
4762 static ngx_int_t | |
2666 | 4763 ngx_http_upstream_process_expires(ngx_http_request_t *r, ngx_table_elt_t *h, |
4764 ngx_uint_t offset) | |
4765 { | |
2786
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4766 ngx_http_upstream_t *u; |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4767 |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4768 u = r->upstream; |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4769 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
|
4770 |
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
4771 #if (NGX_HTTP_CACHE) |
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
4772 { |
2666 | 4773 time_t expires; |
4774 | |
2786
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4775 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
|
4776 return NGX_OK; |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4777 } |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4778 |
2666 | 4779 if (r->cache == NULL) { |
4780 return NGX_OK; | |
4781 } | |
4782 | |
4783 if (r->cache->valid_sec != 0) { | |
4784 return NGX_OK; | |
4785 } | |
4786 | |
6180
8b6fa4842133
Moved ngx_http_parse_time() to core, renamed accordingly.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6147
diff
changeset
|
4787 expires = ngx_parse_http_time(h->value.data, h->value.len); |
2666 | 4788 |
4789 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
|
4790 u->cacheable = 0; |
2666 | 4791 return NGX_OK; |
4792 } | |
4793 | |
4794 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
|
4795 } |
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
4796 #endif |
2666 | 4797 |
4798 return NGX_OK; | |
4799 } | |
4800 | |
4801 | |
4802 static ngx_int_t | |
2663
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4803 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
|
4804 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
|
4805 { |
2786
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4806 ngx_http_upstream_t *u; |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4807 |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4808 u = r->upstream; |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4809 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
|
4810 |
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
4811 #if (NGX_HTTP_CACHE) |
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
4812 { |
2663
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4813 u_char *p; |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4814 size_t len; |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4815 ngx_int_t n; |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4816 |
2786
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4817 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
|
4818 return NGX_OK; |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4819 } |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4820 |
2663
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4821 if (r->cache == NULL) { |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4822 return NGX_OK; |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4823 } |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4824 |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4825 len = h->value.len; |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4826 p = h->value.data; |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4827 |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4828 if (p[0] != '@') { |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4829 n = ngx_atoi(p, len); |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4830 |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4831 switch (n) { |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4832 case 0: |
2786
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4833 u->cacheable = 0; |
4546
4988fa232629
For the sake of case/switch code readability, 'fall through'
Maxim Konovalov <maxim@nginx.com>
parents:
4499
diff
changeset
|
4834 /* fall through */ |
4988fa232629
For the sake of case/switch code readability, 'fall through'
Maxim Konovalov <maxim@nginx.com>
parents:
4499
diff
changeset
|
4835 |
2663
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4836 case NGX_ERROR: |
2667 | 4837 return NGX_OK; |
2663
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4838 |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4839 default: |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4840 r->cache->valid_sec = ngx_time() + n; |
2667 | 4841 return NGX_OK; |
2663
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4842 } |
2667 | 4843 } |
4844 | |
4845 p++; | |
4846 len--; | |
4847 | |
4848 n = ngx_atoi(p, len); | |
4849 | |
4850 if (n != NGX_ERROR) { | |
4851 r->cache->valid_sec = n; | |
2663
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4852 } |
2708
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
4853 } |
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
4854 #endif |
2663
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4855 |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4856 return NGX_OK; |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4857 } |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4858 |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4859 |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4860 static ngx_int_t |
527 | 4861 ngx_http_upstream_process_limit_rate(ngx_http_request_t *r, ngx_table_elt_t *h, |
4862 ngx_uint_t offset) | |
577 | 4863 { |
4197
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4864 ngx_int_t n; |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4865 ngx_http_upstream_t *u; |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4866 |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4867 u = r->upstream; |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4868 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
|
4869 |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4870 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
|
4871 return NGX_OK; |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4872 } |
527 | 4873 |
4874 n = ngx_atoi(h->value.data, h->value.len); | |
4875 | |
4876 if (n != NGX_ERROR) { | |
4877 r->limit_rate = (size_t) n; | |
7504
c19ca381b2e6
Variables support in limit_rate and limit_rate_after (ticket #293).
Ruslan Ermilov <ru@nginx.com>
parents:
7456
diff
changeset
|
4878 r->limit_rate_set = 1; |
527 | 4879 } |
4880 | |
4881 return NGX_OK; | |
4882 } | |
4883 | |
4884 | |
4885 static ngx_int_t | |
649 | 4886 ngx_http_upstream_process_buffering(ngx_http_request_t *r, ngx_table_elt_t *h, |
4887 ngx_uint_t offset) | |
4888 { | |
4197
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4889 u_char c0, c1, c2; |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4890 ngx_http_upstream_t *u; |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4891 |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4892 u = r->upstream; |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4893 |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4894 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
|
4895 return NGX_OK; |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4896 } |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4897 |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4898 if (u->conf->change_buffering) { |
649 | 4899 |
4900 if (h->value.len == 2) { | |
4901 c0 = ngx_tolower(h->value.data[0]); | |
4902 c1 = ngx_tolower(h->value.data[1]); | |
4903 | |
4904 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
|
4905 u->buffering = 0; |
649 | 4906 } |
4907 | |
4908 } else if (h->value.len == 3) { | |
4909 c0 = ngx_tolower(h->value.data[0]); | |
4910 c1 = ngx_tolower(h->value.data[1]); | |
4911 c2 = ngx_tolower(h->value.data[2]); | |
4912 | |
4913 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
|
4914 u->buffering = 1; |
649 | 4915 } |
4916 } | |
4917 } | |
4918 | |
4919 return NGX_OK; | |
4920 } | |
4921 | |
4922 | |
4923 static ngx_int_t | |
657 | 4924 ngx_http_upstream_process_charset(ngx_http_request_t *r, ngx_table_elt_t *h, |
4925 ngx_uint_t offset) | |
4926 { | |
4197
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4927 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
|
4928 return NGX_OK; |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4929 } |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4930 |
657 | 4931 r->headers_out.override_charset = &h->value; |
4932 | |
4933 return NGX_OK; | |
4934 } | |
4935 | |
4936 | |
4937 static ngx_int_t | |
4124
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4938 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
|
4939 ngx_uint_t offset) |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4940 { |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4941 r->upstream->headers_in.connection = h; |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4942 |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4943 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
|
4944 (u_char *) "close", 5 - 1) |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4945 != NULL) |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4946 { |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4947 r->upstream->headers_in.connection_close = 1; |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4948 } |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4949 |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4950 return NGX_OK; |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4951 } |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4952 |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4953 |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4954 static ngx_int_t |
4123
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4955 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
|
4956 ngx_table_elt_t *h, ngx_uint_t offset) |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4957 { |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4958 r->upstream->headers_in.transfer_encoding = h; |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4959 |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4960 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
|
4961 (u_char *) "chunked", 7 - 1) |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4962 != NULL) |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4963 { |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4964 r->upstream->headers_in.chunked = 1; |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4965 } |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4966 |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4967 return NGX_OK; |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4968 } |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4969 |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4970 |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4971 static ngx_int_t |
5877
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4972 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
|
4973 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
|
4974 { |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4975 ngx_http_upstream_t *u; |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4976 |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4977 u = r->upstream; |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4978 u->headers_in.vary = h; |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4979 |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4980 #if (NGX_HTTP_CACHE) |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4981 |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4982 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
|
4983 return NGX_OK; |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4984 } |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4985 |
5878
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5877
diff
changeset
|
4986 if (r->cache == NULL) { |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5877
diff
changeset
|
4987 return NGX_OK; |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5877
diff
changeset
|
4988 } |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5877
diff
changeset
|
4989 |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5877
diff
changeset
|
4990 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
|
4991 || (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
|
4992 { |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5877
diff
changeset
|
4993 u->cacheable = 0; |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5877
diff
changeset
|
4994 } |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5877
diff
changeset
|
4995 |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5877
diff
changeset
|
4996 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
|
4997 |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4998 #endif |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4999 |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
5000 return NGX_OK; |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
5001 } |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
5002 |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
5003 |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
5004 static ngx_int_t |
509 | 5005 ngx_http_upstream_copy_header_line(ngx_http_request_t *r, ngx_table_elt_t *h, |
5006 ngx_uint_t offset) | |
5007 { | |
573 | 5008 ngx_table_elt_t *ho, **ph; |
509 | 5009 |
5010 ho = ngx_list_push(&r->headers_out.headers); | |
5011 if (ho == NULL) { | |
5012 return NGX_ERROR; | |
5013 } | |
5014 | |
5015 *ho = *h; | |
5016 | |
573 | 5017 if (offset) { |
5018 ph = (ngx_table_elt_t **) ((char *) &r->headers_out + offset); | |
5019 *ph = ho; | |
5020 } | |
5021 | |
509 | 5022 return NGX_OK; |
5023 } | |
5024 | |
5025 | |
5026 static ngx_int_t | |
5027 ngx_http_upstream_copy_multi_header_lines(ngx_http_request_t *r, | |
5028 ngx_table_elt_t *h, ngx_uint_t offset) | |
5029 { | |
5030 ngx_array_t *pa; | |
5031 ngx_table_elt_t *ho, **ph; | |
5032 | |
5033 pa = (ngx_array_t *) ((char *) &r->headers_out + offset); | |
5034 | |
5035 if (pa->elts == NULL) { | |
5036 if (ngx_array_init(pa, r->pool, 2, sizeof(ngx_table_elt_t *)) != NGX_OK) | |
5037 { | |
5038 return NGX_ERROR; | |
5039 } | |
5040 } | |
5041 | |
5042 ho = ngx_list_push(&r->headers_out.headers); | |
5043 if (ho == NULL) { | |
5044 return NGX_ERROR; | |
5045 } | |
5046 | |
5047 *ho = *h; | |
6986
0cdee26605f3
Cleaned up r->headers_out.headers allocation error handling.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6966
diff
changeset
|
5048 |
0cdee26605f3
Cleaned up r->headers_out.headers allocation error handling.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6966
diff
changeset
|
5049 ph = ngx_array_push(pa); |
0cdee26605f3
Cleaned up r->headers_out.headers allocation error handling.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6966
diff
changeset
|
5050 if (ph == NULL) { |
0cdee26605f3
Cleaned up r->headers_out.headers allocation error handling.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6966
diff
changeset
|
5051 return NGX_ERROR; |
0cdee26605f3
Cleaned up r->headers_out.headers allocation error handling.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6966
diff
changeset
|
5052 } |
0cdee26605f3
Cleaned up r->headers_out.headers allocation error handling.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6966
diff
changeset
|
5053 |
509 | 5054 *ph = ho; |
5055 | |
5056 return NGX_OK; | |
5057 } | |
5058 | |
5059 | |
5060 static ngx_int_t | |
5061 ngx_http_upstream_copy_content_type(ngx_http_request_t *r, ngx_table_elt_t *h, | |
5062 ngx_uint_t offset) | |
5063 { | |
657 | 5064 u_char *p, *last; |
5065 | |
5066 r->headers_out.content_type_len = h->value.len; | |
509 | 5067 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
|
5068 r->headers_out.content_type_lowcase = NULL; |
509 | 5069 |
657 | 5070 for (p = h->value.data; *p; p++) { |
5071 | |
5072 if (*p != ';') { | |
5073 continue; | |
5074 } | |
5075 | |
5076 last = p; | |
5077 | |
5078 while (*++p == ' ') { /* void */ } | |
5079 | |
1968 | 5080 if (*p == '\0') { |
5081 return NGX_OK; | |
5082 } | |
5083 | |
1107
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1098
diff
changeset
|
5084 if (ngx_strncasecmp(p, (u_char *) "charset=", 8) != 0) { |
657 | 5085 continue; |
5086 } | |
5087 | |
5088 p += 8; | |
5089 | |
5090 r->headers_out.content_type_len = last - h->value.data; | |
5091 | |
2244 | 5092 if (*p == '"') { |
5093 p++; | |
5094 } | |
5095 | |
5096 last = h->value.data + h->value.len; | |
5097 | |
5098 if (*(last - 1) == '"') { | |
5099 last--; | |
5100 } | |
5101 | |
5102 r->headers_out.charset.len = last - p; | |
657 | 5103 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
|
5104 |
c6c42497106c
fix segfault if upstream sends trailing ";" in "charset="
Igor Sysoev <igor@sysoev.ru>
parents:
1109
diff
changeset
|
5105 return NGX_OK; |
657 | 5106 } |
5107 | |
509 | 5108 return NGX_OK; |
5109 } | |
5110 | |
5111 | |
5112 static ngx_int_t | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5113 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
|
5114 ngx_uint_t offset) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5115 { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5116 ngx_table_elt_t *ho; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5117 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5118 ho = ngx_list_push(&r->headers_out.headers); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5119 if (ho == NULL) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5120 return NGX_ERROR; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5121 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5122 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5123 *ho = *h; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5124 |
3004
4121acaf7a04
fix handling "Last-Modified" and "Accept-Ranges" for upstream responses
Igor Sysoev <igor@sysoev.ru>
parents:
3003
diff
changeset
|
5125 r->headers_out.last_modified = ho; |
7093
acc2cddc7b45
Upstream: unconditional parsing of last_modified_time.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7077
diff
changeset
|
5126 r->headers_out.last_modified_time = |
5732
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
5127 r->upstream->headers_in.last_modified_time; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5128 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5129 return NGX_OK; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5130 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5131 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5132 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5133 static ngx_int_t |
509 | 5134 ngx_http_upstream_rewrite_location(ngx_http_request_t *r, ngx_table_elt_t *h, |
5135 ngx_uint_t offset) | |
5136 { | |
5137 ngx_int_t rc; | |
5138 ngx_table_elt_t *ho; | |
5139 | |
5140 ho = ngx_list_push(&r->headers_out.headers); | |
5141 if (ho == NULL) { | |
5142 return NGX_ERROR; | |
5143 } | |
5144 | |
5145 *ho = *h; | |
5146 | |
5147 if (r->upstream->rewrite_redirect) { | |
5148 rc = r->upstream->rewrite_redirect(r, ho, 0); | |
5149 | |
529 | 5150 if (rc == NGX_DECLINED) { |
5151 return NGX_OK; | |
5152 } | |
5153 | |
509 | 5154 if (rc == NGX_OK) { |
5155 r->headers_out.location = ho; | |
5156 | |
5157 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
5158 "rewritten location: \"%V\"", &ho->value); | |
5159 } | |
5160 | |
5161 return rc; | |
5162 } | |
5163 | |
1653
ea681a6a0c61
set r->headers_out.location for non-local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
5164 if (ho->value.data[0] != '/') { |
ea681a6a0c61
set r->headers_out.location for non-local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
5165 r->headers_out.location = ho; |
ea681a6a0c61
set r->headers_out.location for non-local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
5166 } |
ea681a6a0c61
set r->headers_out.location for non-local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
5167 |
509 | 5168 /* |
6853
c85dfd99a2dd
Fixed missing "Location" field with some relative redirects.
Ruslan Ermilov <ru@nginx.com>
parents:
6799
diff
changeset
|
5169 * we do not set r->headers_out.location here to avoid handling |
c85dfd99a2dd
Fixed missing "Location" field with some relative redirects.
Ruslan Ermilov <ru@nginx.com>
parents:
6799
diff
changeset
|
5170 * relative redirects in ngx_http_header_filter() |
509 | 5171 */ |
5172 | |
5173 return NGX_OK; | |
5174 } | |
5175 | |
5176 | |
5177 static ngx_int_t | |
5178 ngx_http_upstream_rewrite_refresh(ngx_http_request_t *r, ngx_table_elt_t *h, | |
5179 ngx_uint_t offset) | |
5180 { | |
5181 u_char *p; | |
5182 ngx_int_t rc; | |
5183 ngx_table_elt_t *ho; | |
5184 | |
5185 ho = ngx_list_push(&r->headers_out.headers); | |
5186 if (ho == NULL) { | |
5187 return NGX_ERROR; | |
5188 } | |
5189 | |
5190 *ho = *h; | |
5191 | |
5192 if (r->upstream->rewrite_redirect) { | |
5193 | |
1549 | 5194 p = ngx_strcasestrn(ho->value.data, "url=", 4 - 1); |
509 | 5195 |
5196 if (p) { | |
5197 rc = r->upstream->rewrite_redirect(r, ho, p + 4 - ho->value.data); | |
5198 | |
5199 } else { | |
5200 return NGX_OK; | |
5201 } | |
5202 | |
529 | 5203 if (rc == NGX_DECLINED) { |
5204 return NGX_OK; | |
5205 } | |
5206 | |
509 | 5207 if (rc == NGX_OK) { |
1654 | 5208 r->headers_out.refresh = ho; |
5209 | |
509 | 5210 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
5211 "rewritten refresh: \"%V\"", &ho->value); | |
5212 } | |
5213 | |
5214 return rc; | |
5215 } | |
5216 | |
1654 | 5217 r->headers_out.refresh = ho; |
5218 | |
509 | 5219 return NGX_OK; |
5220 } | |
5221 | |
5222 | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5223 static ngx_int_t |
4464
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
5224 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
|
5225 ngx_uint_t offset) |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
5226 { |
4650
b38fea6f9a15
Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents:
4572
diff
changeset
|
5227 ngx_int_t rc; |
4464
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
5228 ngx_table_elt_t *ho; |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
5229 |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
5230 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
|
5231 if (ho == NULL) { |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
5232 return NGX_ERROR; |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
5233 } |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
5234 |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
5235 *ho = *h; |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
5236 |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
5237 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
|
5238 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
|
5239 |
b38fea6f9a15
Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents:
4572
diff
changeset
|
5240 if (rc == NGX_DECLINED) { |
b38fea6f9a15
Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents:
4572
diff
changeset
|
5241 return NGX_OK; |
b38fea6f9a15
Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents:
4572
diff
changeset
|
5242 } |
b38fea6f9a15
Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents:
4572
diff
changeset
|
5243 |
b38fea6f9a15
Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents:
4572
diff
changeset
|
5244 #if (NGX_DEBUG) |
b38fea6f9a15
Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents:
4572
diff
changeset
|
5245 if (rc == NGX_OK) { |
b38fea6f9a15
Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents:
4572
diff
changeset
|
5246 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
|
5247 "rewritten cookie: \"%V\"", &ho->value); |
b38fea6f9a15
Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents:
4572
diff
changeset
|
5248 } |
b38fea6f9a15
Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents:
4572
diff
changeset
|
5249 #endif |
b38fea6f9a15
Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents:
4572
diff
changeset
|
5250 |
b38fea6f9a15
Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents:
4572
diff
changeset
|
5251 return rc; |
4464
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
5252 } |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
5253 |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
5254 return NGX_OK; |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
5255 } |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
5256 |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
5257 |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
5258 static ngx_int_t |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5259 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
|
5260 ngx_table_elt_t *h, ngx_uint_t offset) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5261 { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5262 ngx_table_elt_t *ho; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5263 |
5874
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
5264 if (r->upstream->conf->force_ranges) { |
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
5265 return NGX_OK; |
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
5266 } |
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
5267 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5268 #if (NGX_HTTP_CACHE) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5269 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5270 if (r->cached) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5271 r->allow_ranges = 1; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5272 return NGX_OK; |
5621
345e4fd4bb64
Range filter: single_range flag in request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5581
diff
changeset
|
5273 } |
345e4fd4bb64
Range filter: single_range flag in request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5581
diff
changeset
|
5274 |
345e4fd4bb64
Range filter: single_range flag in request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5581
diff
changeset
|
5275 if (r->upstream->cacheable) { |
345e4fd4bb64
Range filter: single_range flag in request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5581
diff
changeset
|
5276 r->allow_ranges = 1; |
345e4fd4bb64
Range filter: single_range flag in request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5581
diff
changeset
|
5277 r->single_range = 1; |
345e4fd4bb64
Range filter: single_range flag in request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5581
diff
changeset
|
5278 return NGX_OK; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5279 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5280 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5281 #endif |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5282 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5283 ho = ngx_list_push(&r->headers_out.headers); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5284 if (ho == NULL) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5285 return NGX_ERROR; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5286 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5287 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5288 *ho = *h; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5289 |
3004
4121acaf7a04
fix handling "Last-Modified" and "Accept-Ranges" for upstream responses
Igor Sysoev <igor@sysoev.ru>
parents:
3003
diff
changeset
|
5290 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
|
5291 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5292 return NGX_OK; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5293 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5294 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5295 |
509 | 5296 #if (NGX_HTTP_GZIP) |
5297 | |
5298 static ngx_int_t | |
5299 ngx_http_upstream_copy_content_encoding(ngx_http_request_t *r, | |
5300 ngx_table_elt_t *h, ngx_uint_t offset) | |
5301 { | |
5302 ngx_table_elt_t *ho; | |
5303 | |
5304 ho = ngx_list_push(&r->headers_out.headers); | |
5305 if (ho == NULL) { | |
5306 return NGX_ERROR; | |
5307 } | |
5308 | |
5309 *ho = *h; | |
5310 | |
5311 r->headers_out.content_encoding = ho; | |
5312 | |
5313 return NGX_OK; | |
5314 } | |
5315 | |
5316 #endif | |
5317 | |
5318 | |
487 | 5319 static ngx_int_t |
573 | 5320 ngx_http_upstream_add_variables(ngx_conf_t *cf) |
479 | 5321 { |
880 | 5322 ngx_http_variable_t *var, *v; |
479 | 5323 |
573 | 5324 for (v = ngx_http_upstream_vars; v->name.len; v++) { |
5325 var = ngx_http_add_variable(cf, &v->name, v->flags); | |
5326 if (var == NULL) { | |
5327 return NGX_ERROR; | |
5328 } | |
5329 | |
637 | 5330 var->get_handler = v->get_handler; |
573 | 5331 var->data = v->data; |
5332 } | |
5333 | |
479 | 5334 return NGX_OK; |
5335 } | |
509 | 5336 |
5337 | |
573 | 5338 static ngx_int_t |
1181 | 5339 ngx_http_upstream_addr_variable(ngx_http_request_t *r, |
5340 ngx_http_variable_value_t *v, uintptr_t data) | |
5341 { | |
5342 u_char *p; | |
5343 size_t len; | |
5344 ngx_uint_t i; | |
5345 ngx_http_upstream_state_t *state; | |
5346 | |
5347 v->valid = 1; | |
1565 | 5348 v->no_cacheable = 0; |
1181 | 5349 v->not_found = 0; |
5350 | |
5351 if (r->upstream_states == NULL || r->upstream_states->nelts == 0) { | |
5352 v->not_found = 1; | |
5353 return NGX_OK; | |
5354 } | |
5355 | |
5356 len = 0; | |
5357 state = r->upstream_states->elts; | |
5358 | |
5359 for (i = 0; i < r->upstream_states->nelts; i++) { | |
5360 if (state[i].peer) { | |
5361 len += state[i].peer->len + 2; | |
5362 | |
5363 } else { | |
5364 len += 3; | |
5365 } | |
5366 } | |
5367 | |
2049 | 5368 p = ngx_pnalloc(r->pool, len); |
1181 | 5369 if (p == NULL) { |
5370 return NGX_ERROR; | |
5371 } | |
5372 | |
5373 v->data = p; | |
5374 | |
5375 i = 0; | |
5376 | |
5377 for ( ;; ) { | |
5378 if (state[i].peer) { | |
5379 p = ngx_cpymem(p, state[i].peer->data, state[i].peer->len); | |
5380 } | |
5381 | |
5382 if (++i == r->upstream_states->nelts) { | |
5383 break; | |
5384 } | |
5385 | |
5386 if (state[i].peer) { | |
5387 *p++ = ','; | |
5388 *p++ = ' '; | |
5389 | |
5390 } else { | |
5391 *p++ = ' '; | |
5392 *p++ = ':'; | |
5393 *p++ = ' '; | |
5394 | |
5395 if (++i == r->upstream_states->nelts) { | |
5396 break; | |
5397 } | |
5398 | |
5399 continue; | |
5400 } | |
5401 } | |
5402 | |
5403 v->len = p - v->data; | |
5404 | |
5405 return NGX_OK; | |
5406 } | |
5407 | |
5408 | |
5409 static ngx_int_t | |
573 | 5410 ngx_http_upstream_status_variable(ngx_http_request_t *r, |
5411 ngx_http_variable_value_t *v, uintptr_t data) | |
5412 { | |
5413 u_char *p; | |
5414 size_t len; | |
5415 ngx_uint_t i; | |
5416 ngx_http_upstream_state_t *state; | |
5417 | |
5418 v->valid = 1; | |
1565 | 5419 v->no_cacheable = 0; |
573 | 5420 v->not_found = 0; |
5421 | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5422 if (r->upstream_states == NULL || r->upstream_states->nelts == 0) { |
573 | 5423 v->not_found = 1; |
5424 return NGX_OK; | |
5425 } | |
5426 | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5427 len = r->upstream_states->nelts * (3 + 2); |
573 | 5428 |
2049 | 5429 p = ngx_pnalloc(r->pool, len); |
573 | 5430 if (p == NULL) { |
5431 return NGX_ERROR; | |
5432 } | |
5433 | |
5434 v->data = p; | |
5435 | |
5436 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
|
5437 state = r->upstream_states->elts; |
573 | 5438 |
5439 for ( ;; ) { | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5440 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
|
5441 p = ngx_sprintf(p, "%ui", state[i].status); |
573 | 5442 |
5443 } else { | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5444 *p++ = '-'; |
573 | 5445 } |
5446 | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5447 if (++i == r->upstream_states->nelts) { |
573 | 5448 break; |
5449 } | |
5450 | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5451 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
|
5452 *p++ = ','; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5453 *p++ = ' '; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5454 |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5455 } else { |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5456 *p++ = ' '; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5457 *p++ = ':'; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5458 *p++ = ' '; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5459 |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5460 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
|
5461 break; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5462 } |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5463 |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5464 continue; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5465 } |
573 | 5466 } |
5467 | |
5468 v->len = p - v->data; | |
5469 | |
5470 return NGX_OK; | |
5471 } | |
5472 | |
5473 | |
5474 static ngx_int_t | |
5475 ngx_http_upstream_response_time_variable(ngx_http_request_t *r, | |
5476 ngx_http_variable_value_t *v, uintptr_t data) | |
5477 { | |
5478 u_char *p; | |
5479 size_t len; | |
5480 ngx_uint_t i; | |
889
a9a7e4b1a72b
the previous fix does not actually fix overflow
Igor Sysoev <igor@sysoev.ru>
parents:
888
diff
changeset
|
5481 ngx_msec_int_t ms; |
573 | 5482 ngx_http_upstream_state_t *state; |
5483 | |
5484 v->valid = 1; | |
1565 | 5485 v->no_cacheable = 0; |
573 | 5486 v->not_found = 0; |
5487 | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5488 if (r->upstream_states == NULL || r->upstream_states->nelts == 0) { |
573 | 5489 v->not_found = 1; |
5490 return NGX_OK; | |
5491 } | |
5492 | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5493 len = r->upstream_states->nelts * (NGX_TIME_T_LEN + 4 + 2); |
573 | 5494 |
2049 | 5495 p = ngx_pnalloc(r->pool, len); |
573 | 5496 if (p == NULL) { |
5497 return NGX_ERROR; | |
5498 } | |
5499 | |
5500 v->data = p; | |
5501 | |
5502 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
|
5503 state = r->upstream_states->elts; |
573 | 5504 |
5505 for ( ;; ) { | |
7397
860d3907da1c
Upstream: revised upstream response time variables.
Vladimir Homutov <vl@nginx.com>
parents:
7371
diff
changeset
|
5506 |
860d3907da1c
Upstream: revised upstream response time variables.
Vladimir Homutov <vl@nginx.com>
parents:
7371
diff
changeset
|
5507 if (data == 1) { |
860d3907da1c
Upstream: revised upstream response time variables.
Vladimir Homutov <vl@nginx.com>
parents:
7371
diff
changeset
|
5508 ms = state[i].header_time; |
860d3907da1c
Upstream: revised upstream response time variables.
Vladimir Homutov <vl@nginx.com>
parents:
7371
diff
changeset
|
5509 |
860d3907da1c
Upstream: revised upstream response time variables.
Vladimir Homutov <vl@nginx.com>
parents:
7371
diff
changeset
|
5510 } else if (data == 2) { |
860d3907da1c
Upstream: revised upstream response time variables.
Vladimir Homutov <vl@nginx.com>
parents:
7371
diff
changeset
|
5511 ms = state[i].connect_time; |
860d3907da1c
Upstream: revised upstream response time variables.
Vladimir Homutov <vl@nginx.com>
parents:
7371
diff
changeset
|
5512 |
860d3907da1c
Upstream: revised upstream response time variables.
Vladimir Homutov <vl@nginx.com>
parents:
7371
diff
changeset
|
5513 } else { |
860d3907da1c
Upstream: revised upstream response time variables.
Vladimir Homutov <vl@nginx.com>
parents:
7371
diff
changeset
|
5514 ms = state[i].response_time; |
860d3907da1c
Upstream: revised upstream response time variables.
Vladimir Homutov <vl@nginx.com>
parents:
7371
diff
changeset
|
5515 } |
860d3907da1c
Upstream: revised upstream response time variables.
Vladimir Homutov <vl@nginx.com>
parents:
7371
diff
changeset
|
5516 |
860d3907da1c
Upstream: revised upstream response time variables.
Vladimir Homutov <vl@nginx.com>
parents:
7371
diff
changeset
|
5517 if (ms != -1) { |
3515 | 5518 ms = ngx_max(ms, 0); |
5368
cd46297325bd
Upstream: fixed $upstream_response_time format specifiers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5353
diff
changeset
|
5519 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
|
5520 |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5521 } else { |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5522 *p++ = '-'; |
573 | 5523 } |
5524 | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5525 if (++i == r->upstream_states->nelts) { |
573 | 5526 break; |
5527 } | |
5528 | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5529 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
|
5530 *p++ = ','; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5531 *p++ = ' '; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5532 |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5533 } else { |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5534 *p++ = ' '; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5535 *p++ = ':'; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5536 *p++ = ' '; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5537 |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5538 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
|
5539 break; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5540 } |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5541 |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5542 continue; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5543 } |
573 | 5544 } |
5545 | |
5546 v->len = p - v->data; | |
5547 | |
5548 return NGX_OK; | |
5549 } | |
5550 | |
5551 | |
2402 | 5552 static ngx_int_t |
5553 ngx_http_upstream_response_length_variable(ngx_http_request_t *r, | |
5554 ngx_http_variable_value_t *v, uintptr_t data) | |
5555 { | |
5556 u_char *p; | |
5557 size_t len; | |
5558 ngx_uint_t i; | |
5559 ngx_http_upstream_state_t *state; | |
5560 | |
5561 v->valid = 1; | |
5562 v->no_cacheable = 0; | |
5563 v->not_found = 0; | |
5564 | |
5565 if (r->upstream_states == NULL || r->upstream_states->nelts == 0) { | |
5566 v->not_found = 1; | |
5567 return NGX_OK; | |
5568 } | |
5569 | |
5570 len = r->upstream_states->nelts * (NGX_OFF_T_LEN + 2); | |
5571 | |
5572 p = ngx_pnalloc(r->pool, len); | |
5573 if (p == NULL) { | |
5574 return NGX_ERROR; | |
5575 } | |
5576 | |
5577 v->data = p; | |
5578 | |
5579 i = 0; | |
5580 state = r->upstream_states->elts; | |
5581 | |
5582 for ( ;; ) { | |
6654
c131f20c9562
Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6594
diff
changeset
|
5583 |
c131f20c9562
Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6594
diff
changeset
|
5584 if (data == 1) { |
c131f20c9562
Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6594
diff
changeset
|
5585 p = ngx_sprintf(p, "%O", state[i].bytes_received); |
c131f20c9562
Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6594
diff
changeset
|
5586 |
7429
e573d74299a0
Upstream: implemented $upstream_bytes_sent.
Ruslan Ermilov <ru@nginx.com>
parents:
7397
diff
changeset
|
5587 } else if (data == 2) { |
e573d74299a0
Upstream: implemented $upstream_bytes_sent.
Ruslan Ermilov <ru@nginx.com>
parents:
7397
diff
changeset
|
5588 p = ngx_sprintf(p, "%O", state[i].bytes_sent); |
e573d74299a0
Upstream: implemented $upstream_bytes_sent.
Ruslan Ermilov <ru@nginx.com>
parents:
7397
diff
changeset
|
5589 |
6654
c131f20c9562
Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6594
diff
changeset
|
5590 } else { |
c131f20c9562
Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6594
diff
changeset
|
5591 p = ngx_sprintf(p, "%O", state[i].response_length); |
c131f20c9562
Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6594
diff
changeset
|
5592 } |
2402 | 5593 |
5594 if (++i == r->upstream_states->nelts) { | |
5595 break; | |
5596 } | |
5597 | |
5598 if (state[i].peer) { | |
5599 *p++ = ','; | |
5600 *p++ = ' '; | |
5601 | |
5602 } else { | |
5603 *p++ = ' '; | |
5604 *p++ = ':'; | |
5605 *p++ = ' '; | |
5606 | |
5607 if (++i == r->upstream_states->nelts) { | |
5608 break; | |
5609 } | |
5610 | |
5611 continue; | |
5612 } | |
5613 } | |
5614 | |
5615 v->len = p - v->data; | |
5616 | |
5617 return NGX_OK; | |
5618 } | |
5619 | |
5620 | |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6876
diff
changeset
|
5621 static ngx_int_t |
1162 | 5622 ngx_http_upstream_header_variable(ngx_http_request_t *r, |
5623 ngx_http_variable_value_t *v, uintptr_t data) | |
5624 { | |
5625 if (r->upstream == NULL) { | |
5626 v->not_found = 1; | |
5627 return NGX_OK; | |
5628 } | |
5629 | |
5630 return ngx_http_variable_unknown_header(v, (ngx_str_t *) data, | |
5631 &r->upstream->headers_in.headers.part, | |
5632 sizeof("upstream_http_") - 1); | |
5633 } | |
5634 | |
5635 | |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6876
diff
changeset
|
5636 static ngx_int_t |
7230
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
5637 ngx_http_upstream_trailer_variable(ngx_http_request_t *r, |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
5638 ngx_http_variable_value_t *v, uintptr_t data) |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
5639 { |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
5640 if (r->upstream == NULL) { |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
5641 v->not_found = 1; |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
5642 return NGX_OK; |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
5643 } |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
5644 |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
5645 return ngx_http_variable_unknown_header(v, (ngx_str_t *) data, |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
5646 &r->upstream->headers_in.trailers.part, |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
5647 sizeof("upstream_trailer_") - 1); |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
5648 } |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
5649 |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
5650 |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
5651 static ngx_int_t |
5677
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5652 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
|
5653 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
|
5654 { |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5655 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
|
5656 |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5657 ngx_str_t cookie, s; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5658 |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5659 if (r->upstream == NULL) { |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5660 v->not_found = 1; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5661 return NGX_OK; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5662 } |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5663 |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5664 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
|
5665 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
|
5666 |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5667 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
|
5668 &s, &cookie) |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5669 == NGX_DECLINED) |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5670 { |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5671 v->not_found = 1; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5672 return NGX_OK; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5673 } |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5674 |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5675 v->len = cookie.len; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5676 v->valid = 1; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5677 v->no_cacheable = 0; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5678 v->not_found = 0; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5679 v->data = cookie.data; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5680 |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5681 return NGX_OK; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5682 } |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5683 |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5684 |
2952 | 5685 #if (NGX_HTTP_CACHE) |
5686 | |
6923
fbdaad9b0e7b
Added missing "static" specifiers found by gcc -Wtraditional.
Ruslan Ermilov <ru@nginx.com>
parents:
6922
diff
changeset
|
5687 static ngx_int_t |
2952 | 5688 ngx_http_upstream_cache_status(ngx_http_request_t *r, |
5689 ngx_http_variable_value_t *v, uintptr_t data) | |
5690 { | |
5691 ngx_uint_t n; | |
5692 | |
5693 if (r->upstream == NULL || r->upstream->cache_status == 0) { | |
5694 v->not_found = 1; | |
5695 return NGX_OK; | |
5696 } | |
5697 | |
5698 n = r->upstream->cache_status - 1; | |
5699 | |
5700 v->valid = 1; | |
5701 v->no_cacheable = 0; | |
5702 v->not_found = 0; | |
5703 v->len = ngx_http_cache_status[n].len; | |
5704 v->data = ngx_http_cache_status[n].data; | |
5705 | |
5706 return NGX_OK; | |
5707 } | |
5708 | |
5441
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5709 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5710 static ngx_int_t |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5711 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
|
5712 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
|
5713 { |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5714 u_char *p; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5715 |
5453
b7b8e2fa7ebd
Fixed null pointer dereference with $upstream_cache_last_modified.
Ruslan Ermilov <ru@nginx.com>
parents:
5441
diff
changeset
|
5716 if (r->upstream == NULL |
b7b8e2fa7ebd
Fixed null pointer dereference with $upstream_cache_last_modified.
Ruslan Ermilov <ru@nginx.com>
parents:
5441
diff
changeset
|
5717 || !r->upstream->conf->cache_revalidate |
5441
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5718 || r->upstream->cache_status != NGX_HTTP_CACHE_EXPIRED |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5719 || r->cache->last_modified == -1) |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5720 { |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5721 v->not_found = 1; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5722 return NGX_OK; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5723 } |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5724 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5725 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
|
5726 if (p == NULL) { |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5727 return NGX_ERROR; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5728 } |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5729 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5730 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
|
5731 v->valid = 1; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5732 v->no_cacheable = 0; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5733 v->not_found = 0; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5734 v->data = p; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5735 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5736 return NGX_OK; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5737 } |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5738 |
5738
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5739 |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5740 static ngx_int_t |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5741 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
|
5742 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
|
5743 { |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5744 if (r->upstream == NULL |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5745 || !r->upstream->conf->cache_revalidate |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5746 || 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
|
5747 || r->cache->etag.len == 0) |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5748 { |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5749 v->not_found = 1; |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5750 return NGX_OK; |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5751 } |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5752 |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5753 v->valid = 1; |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5754 v->no_cacheable = 0; |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5755 v->not_found = 0; |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5756 v->len = r->cache->etag.len; |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5757 v->data = r->cache->etag.data; |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5758 |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5759 return NGX_OK; |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5760 } |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5761 |
2952 | 5762 #endif |
5763 | |
5764 | |
651 | 5765 static char * |
5766 ngx_http_upstream(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy) | |
5767 { | |
884 | 5768 char *rv; |
5769 void *mconf; | |
5770 ngx_str_t *value; | |
5771 ngx_url_t u; | |
5772 ngx_uint_t m; | |
5773 ngx_conf_t pcf; | |
5774 ngx_http_module_t *module; | |
5775 ngx_http_conf_ctx_t *ctx, *http_ctx; | |
5776 ngx_http_upstream_srv_conf_t *uscf; | |
5777 | |
5778 ngx_memzero(&u, sizeof(ngx_url_t)); | |
5779 | |
5780 value = cf->args->elts; | |
5781 u.host = value[1]; | |
5782 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
|
5783 u.no_port = 1; |
884 | 5784 |
5785 uscf = ngx_http_upstream_add(cf, &u, NGX_HTTP_UPSTREAM_CREATE | |
5786 |NGX_HTTP_UPSTREAM_WEIGHT | |
6705 | 5787 |NGX_HTTP_UPSTREAM_MAX_CONNS |
884 | 5788 |NGX_HTTP_UPSTREAM_MAX_FAILS |
5789 |NGX_HTTP_UPSTREAM_FAIL_TIMEOUT | |
5790 |NGX_HTTP_UPSTREAM_DOWN | |
5791 |NGX_HTTP_UPSTREAM_BACKUP); | |
5792 if (uscf == NULL) { | |
5793 return NGX_CONF_ERROR; | |
5794 } | |
5795 | |
651 | 5796 |
5797 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)); | |
5798 if (ctx == NULL) { | |
5799 return NGX_CONF_ERROR; | |
5800 } | |
5801 | |
884 | 5802 http_ctx = cf->ctx; |
5803 ctx->main_conf = http_ctx->main_conf; | |
651 | 5804 |
5805 /* the upstream{}'s srv_conf */ | |
5806 | |
5807 ctx->srv_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module); | |
5808 if (ctx->srv_conf == NULL) { | |
5809 return NGX_CONF_ERROR; | |
5810 } | |
5811 | |
5812 ctx->srv_conf[ngx_http_upstream_module.ctx_index] = uscf; | |
5813 | |
884 | 5814 uscf->srv_conf = ctx->srv_conf; |
5815 | |
651 | 5816 |
5817 /* the upstream{}'s loc_conf */ | |
5818 | |
5819 ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module); | |
5820 if (ctx->loc_conf == NULL) { | |
5821 return NGX_CONF_ERROR; | |
5822 } | |
5823 | |
6379
cf5e822cf470
Dynamic modules: changed ngx_modules to cycle->modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6334
diff
changeset
|
5824 for (m = 0; cf->cycle->modules[m]; m++) { |
cf5e822cf470
Dynamic modules: changed ngx_modules to cycle->modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6334
diff
changeset
|
5825 if (cf->cycle->modules[m]->type != NGX_HTTP_MODULE) { |
651 | 5826 continue; |
5827 } | |
5828 | |
6379
cf5e822cf470
Dynamic modules: changed ngx_modules to cycle->modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6334
diff
changeset
|
5829 module = cf->cycle->modules[m]->ctx; |
651 | 5830 |
884 | 5831 if (module->create_srv_conf) { |
5832 mconf = module->create_srv_conf(cf); | |
5833 if (mconf == NULL) { | |
5834 return NGX_CONF_ERROR; | |
5835 } | |
5836 | |
6379
cf5e822cf470
Dynamic modules: changed ngx_modules to cycle->modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6334
diff
changeset
|
5837 ctx->srv_conf[cf->cycle->modules[m]->ctx_index] = mconf; |
884 | 5838 } |
5839 | |
651 | 5840 if (module->create_loc_conf) { |
5841 mconf = module->create_loc_conf(cf); | |
5842 if (mconf == NULL) { | |
5843 return NGX_CONF_ERROR; | |
5844 } | |
5845 | |
6379
cf5e822cf470
Dynamic modules: changed ngx_modules to cycle->modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6334
diff
changeset
|
5846 ctx->loc_conf[cf->cycle->modules[m]->ctx_index] = mconf; |
651 | 5847 } |
5848 } | |
5849 | |
5728
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5850 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
|
5851 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
|
5852 if (uscf->servers == NULL) { |
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5853 return NGX_CONF_ERROR; |
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5854 } |
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5855 |
651 | 5856 |
5857 /* parse inside upstream{} */ | |
5858 | |
5859 pcf = *cf; | |
5860 cf->ctx = ctx; | |
5861 cf->cmd_type = NGX_HTTP_UPS_CONF; | |
5862 | |
5863 rv = ngx_conf_parse(cf, NULL); | |
5864 | |
5865 *cf = pcf; | |
5866 | |
5867 if (rv != NGX_CONF_OK) { | |
5868 return rv; | |
5869 } | |
5870 | |
5728
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5871 if (uscf->servers->nelts == 0) { |
651 | 5872 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
5873 "no servers are inside upstream"); | |
5874 return NGX_CONF_ERROR; | |
5875 } | |
5876 | |
5877 return rv; | |
5878 } | |
5879 | |
5880 | |
5881 static char * | |
5882 ngx_http_upstream_server(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
5883 { | |
5884 ngx_http_upstream_srv_conf_t *uscf = conf; | |
5885 | |
884 | 5886 time_t fail_timeout; |
5887 ngx_str_t *value, s; | |
5888 ngx_url_t u; | |
6705 | 5889 ngx_int_t weight, max_conns, max_fails; |
884 | 5890 ngx_uint_t i; |
5891 ngx_http_upstream_server_t *us; | |
651 | 5892 |
884 | 5893 us = ngx_array_push(uscf->servers); |
5894 if (us == NULL) { | |
651 | 5895 return NGX_CONF_ERROR; |
5896 } | |
5897 | |
884 | 5898 ngx_memzero(us, sizeof(ngx_http_upstream_server_t)); |
5899 | |
651 | 5900 value = cf->args->elts; |
5901 | |
663 | 5902 weight = 1; |
6705 | 5903 max_conns = 0; |
884 | 5904 max_fails = 1; |
5905 fail_timeout = 10; | |
5906 | |
5907 for (i = 2; i < cf->args->nelts; i++) { | |
5908 | |
5909 if (ngx_strncmp(value[i].data, "weight=", 7) == 0) { | |
5910 | |
5911 if (!(uscf->flags & NGX_HTTP_UPSTREAM_WEIGHT)) { | |
5818
fe8bafab5b49
Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents:
5774
diff
changeset
|
5912 goto not_supported; |
884 | 5913 } |
5914 | |
5915 weight = ngx_atoi(&value[i].data[7], value[i].len - 7); | |
663 | 5916 |
5917 if (weight == NGX_ERROR || weight == 0) { | |
5918 goto invalid; | |
5919 } | |
5920 | |
884 | 5921 continue; |
5922 } | |
5923 | |
6705 | 5924 if (ngx_strncmp(value[i].data, "max_conns=", 10) == 0) { |
5925 | |
5926 if (!(uscf->flags & NGX_HTTP_UPSTREAM_MAX_CONNS)) { | |
5927 goto not_supported; | |
5928 } | |
5929 | |
5930 max_conns = ngx_atoi(&value[i].data[10], value[i].len - 10); | |
5931 | |
5932 if (max_conns == NGX_ERROR) { | |
5933 goto invalid; | |
5934 } | |
5935 | |
5936 continue; | |
5937 } | |
5938 | |
884 | 5939 if (ngx_strncmp(value[i].data, "max_fails=", 10) == 0) { |
5940 | |
5941 if (!(uscf->flags & NGX_HTTP_UPSTREAM_MAX_FAILS)) { | |
5818
fe8bafab5b49
Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents:
5774
diff
changeset
|
5942 goto not_supported; |
884 | 5943 } |
5944 | |
5945 max_fails = ngx_atoi(&value[i].data[10], value[i].len - 10); | |
5946 | |
5947 if (max_fails == NGX_ERROR) { | |
5948 goto invalid; | |
5949 } | |
5950 | |
5951 continue; | |
663 | 5952 } |
884 | 5953 |
5954 if (ngx_strncmp(value[i].data, "fail_timeout=", 13) == 0) { | |
5955 | |
5956 if (!(uscf->flags & NGX_HTTP_UPSTREAM_FAIL_TIMEOUT)) { | |
5818
fe8bafab5b49
Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents:
5774
diff
changeset
|
5957 goto not_supported; |
884 | 5958 } |
5959 | |
5960 s.len = value[i].len - 13; | |
5961 s.data = &value[i].data[13]; | |
5962 | |
5963 fail_timeout = ngx_parse_time(&s, 1); | |
5964 | |
4474 | 5965 if (fail_timeout == (time_t) NGX_ERROR) { |
884 | 5966 goto invalid; |
5967 } | |
5968 | |
5969 continue; | |
5970 } | |
5971 | |
5410
16b68c724438
Upstream: fixed "down" and "backup" parsing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5392
diff
changeset
|
5972 if (ngx_strcmp(value[i].data, "backup") == 0) { |
1378 | 5973 |
5974 if (!(uscf->flags & NGX_HTTP_UPSTREAM_BACKUP)) { | |
5818
fe8bafab5b49
Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents:
5774
diff
changeset
|
5975 goto not_supported; |
1378 | 5976 } |
5977 | |
5978 us->backup = 1; | |
5979 | |
5980 continue; | |
5981 } | |
5982 | |
5410
16b68c724438
Upstream: fixed "down" and "backup" parsing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5392
diff
changeset
|
5983 if (ngx_strcmp(value[i].data, "down") == 0) { |
884 | 5984 |
5985 if (!(uscf->flags & NGX_HTTP_UPSTREAM_DOWN)) { | |
5818
fe8bafab5b49
Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents:
5774
diff
changeset
|
5986 goto not_supported; |
884 | 5987 } |
5988 | |
5989 us->down = 1; | |
5990 | |
5991 continue; | |
5992 } | |
5993 | |
5994 goto invalid; | |
663 | 5995 } |
5996 | |
5728
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5997 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
|
5998 |
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5999 u.url = value[1]; |
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
6000 u.default_port = 80; |
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
6001 |
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
6002 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
|
6003 if (u.err) { |
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
6004 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
|
6005 "%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
|
6006 } |
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
6007 |
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
6008 return NGX_CONF_ERROR; |
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
6009 } |
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
6010 |
5717
efc84a5723b3
Upstream: generic hash module.
Roman Arutyunyan <arut@nginx.com>
parents:
5682
diff
changeset
|
6011 us->name = u.url; |
884 | 6012 us->addrs = u.addrs; |
6013 us->naddrs = u.naddrs; | |
6014 us->weight = weight; | |
6705 | 6015 us->max_conns = max_conns; |
884 | 6016 us->max_fails = max_fails; |
6017 us->fail_timeout = fail_timeout; | |
651 | 6018 |
6019 return NGX_CONF_OK; | |
663 | 6020 |
6021 invalid: | |
6022 | |
884 | 6023 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
6024 "invalid parameter \"%V\"", &value[i]); | |
663 | 6025 |
6026 return NGX_CONF_ERROR; | |
5818
fe8bafab5b49
Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents:
5774
diff
changeset
|
6027 |
fe8bafab5b49
Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents:
5774
diff
changeset
|
6028 not_supported: |
fe8bafab5b49
Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents:
5774
diff
changeset
|
6029 |
fe8bafab5b49
Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents:
5774
diff
changeset
|
6030 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
fe8bafab5b49
Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents:
5774
diff
changeset
|
6031 "balancing method does not support parameter \"%V\"", |
fe8bafab5b49
Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents:
5774
diff
changeset
|
6032 &value[i]); |
fe8bafab5b49
Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents:
5774
diff
changeset
|
6033 |
fe8bafab5b49
Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents:
5774
diff
changeset
|
6034 return NGX_CONF_ERROR; |
651 | 6035 } |
6036 | |
6037 | |
6038 ngx_http_upstream_srv_conf_t * | |
884 | 6039 ngx_http_upstream_add(ngx_conf_t *cf, ngx_url_t *u, ngx_uint_t flags) |
651 | 6040 { |
6041 ngx_uint_t i; | |
884 | 6042 ngx_http_upstream_server_t *us; |
651 | 6043 ngx_http_upstream_srv_conf_t *uscf, **uscfp; |
6044 ngx_http_upstream_main_conf_t *umcf; | |
6045 | |
884 | 6046 if (!(flags & NGX_HTTP_UPSTREAM_CREATE)) { |
6047 | |
1559
fe11e2a3946d
use pool instead of ngx_conf_t
Igor Sysoev <igor@sysoev.ru>
parents:
1558
diff
changeset
|
6048 if (ngx_parse_url(cf->pool, u) != NGX_OK) { |
651 | 6049 if (u->err) { |
6050 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
6051 "%s in upstream \"%V\"", u->err, &u->url); | |
6052 } | |
6053 | |
6054 return NULL; | |
6055 } | |
6056 } | |
6057 | |
6058 umcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_upstream_module); | |
6059 | |
6060 uscfp = umcf->upstreams.elts; | |
6061 | |
6062 for (i = 0; i < umcf->upstreams.nelts; i++) { | |
906 | 6063 |
6064 if (uscfp[i]->host.len != u->host.len | |
884 | 6065 || ngx_strncasecmp(uscfp[i]->host.data, u->host.data, u->host.len) |
6066 != 0) | |
6067 { | |
651 | 6068 continue; |
6069 } | |
6070 | |
884 | 6071 if ((flags & NGX_HTTP_UPSTREAM_CREATE) |
6072 && (uscfp[i]->flags & NGX_HTTP_UPSTREAM_CREATE)) | |
651 | 6073 { |
884 | 6074 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
6075 "duplicate upstream \"%V\"", &u->host); | |
6076 return NULL; | |
651 | 6077 } |
884 | 6078 |
5005
c9059bd5445b
Fixed "proxy_pass" with IP address and no port (ticket #276).
Ruslan Ermilov <ru@nginx.com>
parents:
4990
diff
changeset
|
6079 if ((uscfp[i]->flags & NGX_HTTP_UPSTREAM_CREATE) && !u->no_port) { |
6699
9cf2dce316e5
Fixed log levels of configuration parsing errors.
Valentin Bartenev <vbart@nginx.com>
parents:
6654
diff
changeset
|
6080 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
906 | 6081 "upstream \"%V\" may not have port %d", |
6082 &u->host, u->port); | |
6083 return NULL; | |
6084 } | |
6085 | |
5005
c9059bd5445b
Fixed "proxy_pass" with IP address and no port (ticket #276).
Ruslan Ermilov <ru@nginx.com>
parents:
4990
diff
changeset
|
6086 if ((flags & NGX_HTTP_UPSTREAM_CREATE) && !uscfp[i]->no_port) { |
6699
9cf2dce316e5
Fixed log levels of configuration parsing errors.
Valentin Bartenev <vbart@nginx.com>
parents:
6654
diff
changeset
|
6087 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, |
906 | 6088 "upstream \"%V\" may not have port %d in %s:%ui", |
6089 &u->host, uscfp[i]->port, | |
1489
56f1ea5baabb
u_char* is enough to keep file name
Igor Sysoev <igor@sysoev.ru>
parents:
1469
diff
changeset
|
6090 uscfp[i]->file_name, uscfp[i]->line); |
906 | 6091 return NULL; |
6092 } | |
6093 | |
5005
c9059bd5445b
Fixed "proxy_pass" with IP address and no port (ticket #276).
Ruslan Ermilov <ru@nginx.com>
parents:
4990
diff
changeset
|
6094 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
|
6095 && 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
|
6096 { |
906 | 6097 continue; |
884 | 6098 } |
6099 | |
4152
65c1c241d70e
Better handling of late upstream creation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4151
diff
changeset
|
6100 if (flags & NGX_HTTP_UPSTREAM_CREATE) { |
65c1c241d70e
Better handling of late upstream creation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4151
diff
changeset
|
6101 uscfp[i]->flags = flags; |
6787
640e1e778de6
Upstream: consistently initialize explicit upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6786
diff
changeset
|
6102 uscfp[i]->port = 0; |
4152
65c1c241d70e
Better handling of late upstream creation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4151
diff
changeset
|
6103 } |
65c1c241d70e
Better handling of late upstream creation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4151
diff
changeset
|
6104 |
884 | 6105 return uscfp[i]; |
651 | 6106 } |
6107 | |
6108 uscf = ngx_pcalloc(cf->pool, sizeof(ngx_http_upstream_srv_conf_t)); | |
6109 if (uscf == NULL) { | |
6110 return NULL; | |
6111 } | |
6112 | |
884 | 6113 uscf->flags = flags; |
651 | 6114 uscf->host = u->host; |
1489
56f1ea5baabb
u_char* is enough to keep file name
Igor Sysoev <igor@sysoev.ru>
parents:
1469
diff
changeset
|
6115 uscf->file_name = cf->conf_file->file.name.data; |
651 | 6116 uscf->line = cf->conf_file->line; |
906 | 6117 uscf->port = u->port; |
5005
c9059bd5445b
Fixed "proxy_pass" with IP address and no port (ticket #276).
Ruslan Ermilov <ru@nginx.com>
parents:
4990
diff
changeset
|
6118 uscf->no_port = u->no_port; |
884 | 6119 |
5977
26c127bab5ef
Upstream: detect port absence in fastcgi_pass with IP literal.
Ruslan Ermilov <ru@nginx.com>
parents:
5968
diff
changeset
|
6120 if (u->naddrs == 1 && (u->port || u->family == AF_UNIX)) { |
884 | 6121 uscf->servers = ngx_array_create(cf->pool, 1, |
6122 sizeof(ngx_http_upstream_server_t)); | |
6123 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
|
6124 return NULL; |
884 | 6125 } |
6126 | |
6127 us = ngx_array_push(uscf->servers); | |
6128 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
|
6129 return NULL; |
884 | 6130 } |
6131 | |
6132 ngx_memzero(us, sizeof(ngx_http_upstream_server_t)); | |
6133 | |
6134 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
|
6135 us->naddrs = 1; |
884 | 6136 } |
651 | 6137 |
6138 uscfp = ngx_array_push(&umcf->upstreams); | |
6139 if (uscfp == NULL) { | |
6140 return NULL; | |
6141 } | |
6142 | |
6143 *uscfp = uscf; | |
6144 | |
6145 return uscf; | |
6146 } | |
6147 | |
6148 | |
3271
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3198
diff
changeset
|
6149 char * |
3399 | 6150 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
|
6151 void *conf) |
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3198
diff
changeset
|
6152 { |
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3198
diff
changeset
|
6153 char *p = conf; |
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3198
diff
changeset
|
6154 |
5008
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6155 ngx_int_t rc; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6156 ngx_str_t *value; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6157 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
|
6158 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
|
6159 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
|
6160 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6161 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
|
6162 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6163 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
|
6164 return "is duplicate"; |
3271
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3198
diff
changeset
|
6165 } |
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3198
diff
changeset
|
6166 |
3272
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3271
diff
changeset
|
6167 value = cf->args->elts; |
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3271
diff
changeset
|
6168 |
6530
1d0e03db9f8e
Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6528
diff
changeset
|
6169 if (cf->args->nelts == 2 && ngx_strcmp(value[1].data, "off") == 0) { |
5008
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6170 *plocal = NULL; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6171 return NGX_CONF_OK; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6172 } |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6173 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6174 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
|
6175 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6176 ccv.cf = cf; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6177 ccv.value = &value[1]; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6178 ccv.complex_value = &cv; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6179 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6180 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
|
6181 return NGX_CONF_ERROR; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6182 } |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6183 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6184 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
|
6185 if (local == NULL) { |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6186 return NGX_CONF_ERROR; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6187 } |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6188 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6189 *plocal = local; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6190 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6191 if (cv.lengths) { |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6192 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
|
6193 if (local->value == NULL) { |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6194 return NGX_CONF_ERROR; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6195 } |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6196 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6197 *local->value = cv; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6198 |
6528
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6199 } else { |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6200 local->addr = ngx_palloc(cf->pool, sizeof(ngx_addr_t)); |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6201 if (local->addr == NULL) { |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6202 return NGX_CONF_ERROR; |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6203 } |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6204 |
6594
3c87b82b17d4
Upstream: support for port in proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6536
diff
changeset
|
6205 rc = ngx_parse_addr_port(cf->pool, local->addr, value[1].data, |
3c87b82b17d4
Upstream: support for port in proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6536
diff
changeset
|
6206 value[1].len); |
6528
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6207 |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6208 switch (rc) { |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6209 case NGX_OK: |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6210 local->addr->name = value[1]; |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6211 break; |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6212 |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6213 case NGX_DECLINED: |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6214 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6215 "invalid address \"%V\"", &value[1]); |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6216 /* fall through */ |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6217 |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6218 default: |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6219 return NGX_CONF_ERROR; |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6220 } |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6221 } |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6222 |
6530
1d0e03db9f8e
Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6528
diff
changeset
|
6223 if (cf->args->nelts > 2) { |
1d0e03db9f8e
Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6528
diff
changeset
|
6224 if (ngx_strcmp(value[2].data, "transparent") == 0) { |
1d0e03db9f8e
Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6528
diff
changeset
|
6225 #if (NGX_HAVE_TRANSPARENT_PROXY) |
7174
84e53e4735a4
Retain CAP_NET_RAW capability for transparent proxying.
Roman Arutyunyan <arut@nginx.com>
parents:
7166
diff
changeset
|
6226 ngx_core_conf_t *ccf; |
84e53e4735a4
Retain CAP_NET_RAW capability for transparent proxying.
Roman Arutyunyan <arut@nginx.com>
parents:
7166
diff
changeset
|
6227 |
84e53e4735a4
Retain CAP_NET_RAW capability for transparent proxying.
Roman Arutyunyan <arut@nginx.com>
parents:
7166
diff
changeset
|
6228 ccf = (ngx_core_conf_t *) ngx_get_conf(cf->cycle->conf_ctx, |
84e53e4735a4
Retain CAP_NET_RAW capability for transparent proxying.
Roman Arutyunyan <arut@nginx.com>
parents:
7166
diff
changeset
|
6229 ngx_core_module); |
84e53e4735a4
Retain CAP_NET_RAW capability for transparent proxying.
Roman Arutyunyan <arut@nginx.com>
parents:
7166
diff
changeset
|
6230 |
84e53e4735a4
Retain CAP_NET_RAW capability for transparent proxying.
Roman Arutyunyan <arut@nginx.com>
parents:
7166
diff
changeset
|
6231 ccf->transparent = 1; |
6530
1d0e03db9f8e
Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6528
diff
changeset
|
6232 local->transparent = 1; |
1d0e03db9f8e
Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6528
diff
changeset
|
6233 #else |
1d0e03db9f8e
Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6528
diff
changeset
|
6234 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
1d0e03db9f8e
Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6528
diff
changeset
|
6235 "transparent proxying is not supported " |
1d0e03db9f8e
Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6528
diff
changeset
|
6236 "on this platform, ignored"); |
1d0e03db9f8e
Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6528
diff
changeset
|
6237 #endif |
1d0e03db9f8e
Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6528
diff
changeset
|
6238 } else { |
1d0e03db9f8e
Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6528
diff
changeset
|
6239 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
1d0e03db9f8e
Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6528
diff
changeset
|
6240 "invalid parameter \"%V\"", &value[2]); |
1d0e03db9f8e
Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6528
diff
changeset
|
6241 return NGX_CONF_ERROR; |
1d0e03db9f8e
Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6528
diff
changeset
|
6242 } |
1d0e03db9f8e
Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6528
diff
changeset
|
6243 } |
1d0e03db9f8e
Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6528
diff
changeset
|
6244 |
6528
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6245 return NGX_CONF_OK; |
3271
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3198
diff
changeset
|
6246 } |
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3198
diff
changeset
|
6247 |
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3198
diff
changeset
|
6248 |
6528
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6249 static ngx_int_t |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6250 ngx_http_upstream_set_local(ngx_http_request_t *r, ngx_http_upstream_t *u, |
5008
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6251 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
|
6252 { |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6253 ngx_int_t rc; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6254 ngx_str_t val; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6255 ngx_addr_t *addr; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6256 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6257 if (local == NULL) { |
6528
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6258 u->peer.local = NULL; |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6259 return NGX_OK; |
5008
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6260 } |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6261 |
6530
1d0e03db9f8e
Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6528
diff
changeset
|
6262 #if (NGX_HAVE_TRANSPARENT_PROXY) |
1d0e03db9f8e
Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6528
diff
changeset
|
6263 u->peer.transparent = local->transparent; |
1d0e03db9f8e
Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6528
diff
changeset
|
6264 #endif |
1d0e03db9f8e
Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6528
diff
changeset
|
6265 |
5008
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6266 if (local->value == NULL) { |
6528
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6267 u->peer.local = local->addr; |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6268 return NGX_OK; |
5008
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6269 } |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6270 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6271 if (ngx_http_complex_value(r, local->value, &val) != NGX_OK) { |
6528
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6272 return NGX_ERROR; |
5008
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6273 } |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6274 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6275 if (val.len == 0) { |
6528
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6276 return NGX_OK; |
5008
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6277 } |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6278 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6279 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
|
6280 if (addr == NULL) { |
6528
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6281 return NGX_ERROR; |
5008
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6282 } |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6283 |
6594
3c87b82b17d4
Upstream: support for port in proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6536
diff
changeset
|
6284 rc = ngx_parse_addr_port(r->pool, addr, val.data, val.len); |
6528
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6285 if (rc == NGX_ERROR) { |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6286 return NGX_ERROR; |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6287 } |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6288 |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6289 if (rc != NGX_OK) { |
5008
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6290 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
|
6291 "invalid local address \"%V\"", &val); |
6528
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6292 return NGX_OK; |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6293 } |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6294 |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6295 addr->name = val; |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6296 u->peer.local = addr; |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6297 |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6298 return NGX_OK; |
5008
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6299 } |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6300 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6301 |
4328
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6302 char * |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6303 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
|
6304 void *conf) |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6305 { |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6306 char *p = conf; |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6307 |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6308 ngx_str_t *value; |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6309 ngx_array_t **a; |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6310 ngx_http_upstream_param_t *param; |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6311 |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6312 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
|
6313 |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6314 if (*a == NULL) { |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6315 *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
|
6316 if (*a == NULL) { |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6317 return NGX_CONF_ERROR; |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6318 } |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6319 } |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6320 |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6321 param = ngx_array_push(*a); |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6322 if (param == NULL) { |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6323 return NGX_CONF_ERROR; |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6324 } |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6325 |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6326 value = cf->args->elts; |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6327 |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6328 param->key = value[1]; |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6329 param->value = value[2]; |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6330 param->skip_empty = 0; |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6331 |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6332 if (cf->args->nelts == 4) { |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6333 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
|
6334 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
|
6335 "invalid parameter \"%V\"", &value[3]); |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6336 return NGX_CONF_ERROR; |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6337 } |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6338 |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6339 param->skip_empty = 1; |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6340 } |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6341 |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6342 return NGX_CONF_OK; |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6343 } |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6344 |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6345 |
1701
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6346 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
|
6347 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
|
6348 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
|
6349 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
|
6350 { |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6351 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
|
6352 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
|
6353 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
|
6354 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
|
6355 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6356 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
|
6357 && 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
|
6358 { |
4769
f88555d76886
Upstream: hide_headers/pass_headers inheritance fix.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4766
diff
changeset
|
6359 conf->hide_headers = prev->hide_headers; |
f88555d76886
Upstream: hide_headers/pass_headers inheritance fix.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4766
diff
changeset
|
6360 conf->pass_headers = prev->pass_headers; |
f88555d76886
Upstream: hide_headers/pass_headers inheritance fix.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4766
diff
changeset
|
6361 |
1701
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6362 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
|
6363 |
6744
7e5199f172fb
Upstream: hide_headers_hash inherited regardless of cache settings.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6705
diff
changeset
|
6364 if (conf->hide_headers_hash.buckets) { |
1701
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6365 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
|
6366 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6367 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6368 } else { |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6369 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
|
6370 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
|
6371 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6372 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6373 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
|
6374 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
|
6375 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6376 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6377 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6378 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
|
6379 != NGX_OK) |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6380 { |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6381 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
|
6382 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6383 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6384 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
|
6385 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
|
6386 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
|
6387 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
|
6388 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6389 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6390 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
|
6391 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
|
6392 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
|
6393 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6394 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6395 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
|
6396 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6397 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
|
6398 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6399 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
|
6400 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6401 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
|
6402 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6403 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
|
6404 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
|
6405 goto exist; |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6406 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6407 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6408 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6409 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
|
6410 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
|
6411 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
|
6412 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6413 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6414 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
|
6415 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
|
6416 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
|
6417 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6418 exist: |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6419 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6420 continue; |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6421 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6422 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6423 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6424 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
|
6425 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6426 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
|
6427 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
|
6428 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6429 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
|
6430 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
|
6431 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6432 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
|
6433 continue; |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6434 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6435 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6436 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
|
6437 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
|
6438 break; |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6439 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6440 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6441 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6442 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6443 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6444 hash->hash = &conf->hide_headers_hash; |
1706
9242e21d2f8d
style fix: remove trailing spaces
Igor Sysoev <igor@sysoev.ru>
parents:
1705
diff
changeset
|
6445 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
|
6446 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
|
6447 hash->temp_pool = NULL; |
1706
9242e21d2f8d
style fix: remove trailing spaces
Igor Sysoev <igor@sysoev.ru>
parents:
1705
diff
changeset
|
6448 |
6745
93121485c39b
Upstream: hide_headers_hash handling at http level.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6744
diff
changeset
|
6449 if (ngx_hash_init(hash, hide_headers.elts, hide_headers.nelts) != NGX_OK) { |
93121485c39b
Upstream: hide_headers_hash handling at http level.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6744
diff
changeset
|
6450 return NGX_ERROR; |
93121485c39b
Upstream: hide_headers_hash handling at http level.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6744
diff
changeset
|
6451 } |
93121485c39b
Upstream: hide_headers_hash handling at http level.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6744
diff
changeset
|
6452 |
93121485c39b
Upstream: hide_headers_hash handling at http level.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6744
diff
changeset
|
6453 /* |
93121485c39b
Upstream: hide_headers_hash handling at http level.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6744
diff
changeset
|
6454 * special handling to preserve conf->hide_headers_hash |
93121485c39b
Upstream: hide_headers_hash handling at http level.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6744
diff
changeset
|
6455 * in the "http" section to inherit it to all servers |
93121485c39b
Upstream: hide_headers_hash handling at http level.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6744
diff
changeset
|
6456 */ |
93121485c39b
Upstream: hide_headers_hash handling at http level.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6744
diff
changeset
|
6457 |
93121485c39b
Upstream: hide_headers_hash handling at http level.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6744
diff
changeset
|
6458 if (prev->hide_headers_hash.buckets == NULL |
93121485c39b
Upstream: hide_headers_hash handling at http level.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6744
diff
changeset
|
6459 && conf->hide_headers == prev->hide_headers |
93121485c39b
Upstream: hide_headers_hash handling at http level.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6744
diff
changeset
|
6460 && conf->pass_headers == prev->pass_headers) |
93121485c39b
Upstream: hide_headers_hash handling at http level.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6744
diff
changeset
|
6461 { |
93121485c39b
Upstream: hide_headers_hash handling at http level.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6744
diff
changeset
|
6462 prev->hide_headers_hash = conf->hide_headers_hash; |
93121485c39b
Upstream: hide_headers_hash handling at http level.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6744
diff
changeset
|
6463 } |
93121485c39b
Upstream: hide_headers_hash handling at http level.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6744
diff
changeset
|
6464 |
93121485c39b
Upstream: hide_headers_hash handling at http level.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6744
diff
changeset
|
6465 return NGX_OK; |
1701
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6466 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6467 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6468 |
509 | 6469 static void * |
6470 ngx_http_upstream_create_main_conf(ngx_conf_t *cf) | |
6471 { | |
6472 ngx_http_upstream_main_conf_t *umcf; | |
6473 | |
6474 umcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_upstream_main_conf_t)); | |
6475 if (umcf == NULL) { | |
6476 return NULL; | |
6477 } | |
6478 | |
651 | 6479 if (ngx_array_init(&umcf->upstreams, cf->pool, 4, |
6480 sizeof(ngx_http_upstream_srv_conf_t *)) | |
6481 != NGX_OK) | |
6482 { | |
2912
c7d57b539248
return NULL instead of NGX_CONF_ERROR on a create conf failure
Igor Sysoev <igor@sysoev.ru>
parents:
2882
diff
changeset
|
6483 return NULL; |
651 | 6484 } |
6485 | |
509 | 6486 return umcf; |
6487 } | |
6488 | |
6489 | |
6490 static char * | |
651 | 6491 ngx_http_upstream_init_main_conf(ngx_conf_t *cf, void *conf) |
509 | 6492 { |
6493 ngx_http_upstream_main_conf_t *umcf = conf; | |
6494 | |
651 | 6495 ngx_uint_t i; |
6496 ngx_array_t headers_in; | |
6497 ngx_hash_key_t *hk; | |
6498 ngx_hash_init_t hash; | |
884 | 6499 ngx_http_upstream_init_pt init; |
651 | 6500 ngx_http_upstream_header_t *header; |
6501 ngx_http_upstream_srv_conf_t **uscfp; | |
6502 | |
6503 uscfp = umcf->upstreams.elts; | |
6504 | |
6505 for (i = 0; i < umcf->upstreams.nelts; i++) { | |
884 | 6506 |
6507 init = uscfp[i]->peer.init_upstream ? uscfp[i]->peer.init_upstream: | |
6508 ngx_http_upstream_init_round_robin; | |
6509 | |
6510 if (init(cf, uscfp[i]) != NGX_OK) { | |
651 | 6511 return NGX_CONF_ERROR; |
6512 } | |
6513 } | |
649 | 6514 |
663 | 6515 |
884 | 6516 /* upstream_headers_in_hash */ |
6517 | |
649 | 6518 if (ngx_array_init(&headers_in, cf->temp_pool, 32, sizeof(ngx_hash_key_t)) |
6519 != NGX_OK) | |
509 | 6520 { |
6521 return NGX_CONF_ERROR; | |
6522 } | |
6523 | |
649 | 6524 for (header = ngx_http_upstream_headers_in; header->name.len; header++) { |
6525 hk = ngx_array_push(&headers_in); | |
6526 if (hk == NULL) { | |
6527 return NGX_CONF_ERROR; | |
6528 } | |
6529 | |
6530 hk->key = header->name; | |
6531 hk->key_hash = ngx_hash_key_lc(header->name.data, header->name.len); | |
6532 hk->value = header; | |
6533 } | |
6534 | |
6535 hash.hash = &umcf->headers_in_hash; | |
6536 hash.key = ngx_hash_key_lc; | |
6537 hash.max_size = 512; | |
751
bae59a740c40
align hash bucket size to cache line
Igor Sysoev <igor@sysoev.ru>
parents:
750
diff
changeset
|
6538 hash.bucket_size = ngx_align(64, ngx_cacheline_size); |
649 | 6539 hash.name = "upstream_headers_in_hash"; |
6540 hash.pool = cf->pool; | |
6541 hash.temp_pool = NULL; | |
6542 | |
6543 if (ngx_hash_init(&hash, headers_in.elts, headers_in.nelts) != NGX_OK) { | |
6544 return NGX_CONF_ERROR; | |
6545 } | |
509 | 6546 |
6547 return NGX_CONF_OK; | |
6548 } |