Mercurial > hg > nginx
annotate src/http/ngx_http_upstream.c @ 7349:f6047a579ca1
gRPC: improved keepalive handling.
The code is now able to parse additional control frames after
the response is received, and can send control frames as well.
This fixes keepalive problems as observed with grpc-c, which can
send window update and ping frames after the response, see
http://mailman.nginx.org/pipermail/nginx/2018-August/056620.html.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 03 Sep 2018 19:34:01 +0300 |
parents | 15ea84e65d07 |
children | 8b68d50090e4 |
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); |
581 | 80 static ngx_int_t ngx_http_upstream_non_buffered_filter_init(void *data); |
81 static ngx_int_t ngx_http_upstream_non_buffered_filter(void *data, | |
82 ssize_t bytes); | |
6443
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
83 #if (NGX_THREADS) |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
84 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
|
85 ngx_file_t *file); |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
86 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
|
87 #endif |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
88 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
|
89 ngx_chain_t *chain); |
509 | 90 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
|
91 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
|
92 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
|
93 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
|
94 ngx_http_upstream_t *u); |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
95 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
|
96 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
|
97 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
|
98 ngx_http_upstream_t *u); |
479 | 99 static void ngx_http_upstream_next(ngx_http_request_t *r, |
487 | 100 ngx_http_upstream_t *u, ngx_uint_t ft_type); |
569 | 101 static void ngx_http_upstream_cleanup(void *data); |
479 | 102 static void ngx_http_upstream_finalize_request(ngx_http_request_t *r, |
487 | 103 ngx_http_upstream_t *u, ngx_int_t rc); |
479 | 104 |
509 | 105 static ngx_int_t ngx_http_upstream_process_header_line(ngx_http_request_t *r, |
106 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
|
107 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
|
108 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
|
109 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
|
110 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
|
111 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
|
112 ngx_table_elt_t *h, ngx_uint_t offset); |
509 | 113 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
|
114 ngx_http_upstream_process_cache_control(ngx_http_request_t *r, |
509 | 115 ngx_table_elt_t *h, ngx_uint_t offset); |
116 static ngx_int_t ngx_http_upstream_ignore_header_line(ngx_http_request_t *r, | |
117 ngx_table_elt_t *h, ngx_uint_t offset); | |
2666 | 118 static ngx_int_t ngx_http_upstream_process_expires(ngx_http_request_t *r, |
119 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
|
120 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
|
121 ngx_table_elt_t *h, ngx_uint_t offset); |
527 | 122 static ngx_int_t ngx_http_upstream_process_limit_rate(ngx_http_request_t *r, |
123 ngx_table_elt_t *h, ngx_uint_t offset); | |
649 | 124 static ngx_int_t ngx_http_upstream_process_buffering(ngx_http_request_t *r, |
509 | 125 ngx_table_elt_t *h, ngx_uint_t offset); |
657 | 126 static ngx_int_t ngx_http_upstream_process_charset(ngx_http_request_t *r, |
127 ngx_table_elt_t *h, ngx_uint_t offset); | |
4124
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
128 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
|
129 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
|
130 static ngx_int_t |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
131 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
|
132 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
|
133 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
|
134 ngx_table_elt_t *h, ngx_uint_t offset); |
649 | 135 static ngx_int_t ngx_http_upstream_copy_header_line(ngx_http_request_t *r, |
509 | 136 ngx_table_elt_t *h, ngx_uint_t offset); |
137 static ngx_int_t | |
138 ngx_http_upstream_copy_multi_header_lines(ngx_http_request_t *r, | |
139 ngx_table_elt_t *h, ngx_uint_t offset); | |
140 static ngx_int_t ngx_http_upstream_copy_content_type(ngx_http_request_t *r, | |
141 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
|
142 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
|
143 ngx_table_elt_t *h, ngx_uint_t offset); |
509 | 144 static ngx_int_t ngx_http_upstream_rewrite_location(ngx_http_request_t *r, |
145 ngx_table_elt_t *h, ngx_uint_t offset); | |
146 static ngx_int_t ngx_http_upstream_rewrite_refresh(ngx_http_request_t *r, | |
147 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
|
148 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
|
149 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
|
150 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
|
151 ngx_table_elt_t *h, ngx_uint_t offset); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
152 |
509 | 153 #if (NGX_HTTP_GZIP) |
154 static ngx_int_t ngx_http_upstream_copy_content_encoding(ngx_http_request_t *r, | |
155 ngx_table_elt_t *h, ngx_uint_t offset); | |
156 #endif | |
157 | |
573 | 158 static ngx_int_t ngx_http_upstream_add_variables(ngx_conf_t *cf); |
1181 | 159 static ngx_int_t ngx_http_upstream_addr_variable(ngx_http_request_t *r, |
160 ngx_http_variable_value_t *v, uintptr_t data); | |
573 | 161 static ngx_int_t ngx_http_upstream_status_variable(ngx_http_request_t *r, |
162 ngx_http_variable_value_t *v, uintptr_t data); | |
163 static ngx_int_t ngx_http_upstream_response_time_variable(ngx_http_request_t *r, | |
164 ngx_http_variable_value_t *v, uintptr_t data); | |
2402 | 165 static ngx_int_t ngx_http_upstream_response_length_variable( |
166 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
|
167 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
|
168 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
|
169 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
|
170 ngx_http_variable_value_t *v, uintptr_t data); |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6876
diff
changeset
|
171 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
|
172 ngx_http_variable_value_t *v, uintptr_t data); |
573 | 173 |
651 | 174 static char *ngx_http_upstream(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy); |
175 static char *ngx_http_upstream_server(ngx_conf_t *cf, ngx_command_t *cmd, | |
176 void *conf); | |
177 | |
6528
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
178 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
|
179 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
|
180 |
509 | 181 static void *ngx_http_upstream_create_main_conf(ngx_conf_t *cf); |
651 | 182 static char *ngx_http_upstream_init_main_conf(ngx_conf_t *cf, void *conf); |
509 | 183 |
577 | 184 #if (NGX_HTTP_SSL) |
591 | 185 static void ngx_http_upstream_ssl_init_connection(ngx_http_request_t *, |
186 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
|
187 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
|
188 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
|
189 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
|
190 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
|
191 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
|
192 ngx_http_upstream_t *u, ngx_connection_t *c); |
577 | 193 #endif |
194 | |
509 | 195 |
6922
a72886067bbb
Added missing static specifiers.
Eran Kornblau <erankor@gmail.com>
parents:
6909
diff
changeset
|
196 static ngx_http_upstream_header_t ngx_http_upstream_headers_in[] = { |
509 | 197 |
198 { ngx_string("Status"), | |
199 ngx_http_upstream_process_header_line, | |
200 offsetof(ngx_http_upstream_headers_in_t, status), | |
649 | 201 ngx_http_upstream_copy_header_line, 0, 0 }, |
509 | 202 |
203 { ngx_string("Content-Type"), | |
204 ngx_http_upstream_process_header_line, | |
205 offsetof(ngx_http_upstream_headers_in_t, content_type), | |
673 | 206 ngx_http_upstream_copy_content_type, 0, 1 }, |
509 | 207 |
208 { ngx_string("Content-Length"), | |
5731
02674312be45
Upstream: removed unused offset to content_length.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5730
diff
changeset
|
209 ngx_http_upstream_process_content_length, 0, |
4117
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
210 ngx_http_upstream_ignore_header_line, 0, 0 }, |
509 | 211 |
212 { ngx_string("Date"), | |
213 ngx_http_upstream_process_header_line, | |
214 offsetof(ngx_http_upstream_headers_in_t, date), | |
649 | 215 ngx_http_upstream_copy_header_line, |
216 offsetof(ngx_http_headers_out_t, date), 0 }, | |
509 | 217 |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
218 { ngx_string("Last-Modified"), |
5732
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
219 ngx_http_upstream_process_last_modified, 0, |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
220 ngx_http_upstream_copy_last_modified, 0, 0 }, |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
221 |
3037 | 222 { ngx_string("ETag"), |
223 ngx_http_upstream_process_header_line, | |
224 offsetof(ngx_http_upstream_headers_in_t, etag), | |
225 ngx_http_upstream_copy_header_line, | |
226 offsetof(ngx_http_headers_out_t, etag), 0 }, | |
227 | |
509 | 228 { ngx_string("Server"), |
229 ngx_http_upstream_process_header_line, | |
230 offsetof(ngx_http_upstream_headers_in_t, server), | |
649 | 231 ngx_http_upstream_copy_header_line, |
232 offsetof(ngx_http_headers_out_t, server), 0 }, | |
509 | 233 |
529 | 234 { ngx_string("WWW-Authenticate"), |
235 ngx_http_upstream_process_header_line, | |
236 offsetof(ngx_http_upstream_headers_in_t, www_authenticate), | |
237 ngx_http_upstream_copy_header_line, 0, 0 }, | |
238 | |
509 | 239 { ngx_string("Location"), |
2140
dce5ddef5af9
if upstream sent a location header without status use 302
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
240 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
|
241 offsetof(ngx_http_upstream_headers_in_t, location), |
515 | 242 ngx_http_upstream_rewrite_location, 0, 0 }, |
509 | 243 |
244 { ngx_string("Refresh"), | |
245 ngx_http_upstream_ignore_header_line, 0, | |
515 | 246 ngx_http_upstream_rewrite_refresh, 0, 0 }, |
247 | |
248 { ngx_string("Set-Cookie"), | |
5677
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
249 ngx_http_upstream_process_set_cookie, |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
250 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
|
251 ngx_http_upstream_rewrite_set_cookie, 0, 1 }, |
531 | 252 |
253 { ngx_string("Content-Disposition"), | |
254 ngx_http_upstream_ignore_header_line, 0, | |
255 ngx_http_upstream_copy_header_line, 0, 1 }, | |
509 | 256 |
257 { 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
|
258 ngx_http_upstream_process_cache_control, 0, |
509 | 259 ngx_http_upstream_copy_multi_header_lines, |
515 | 260 offsetof(ngx_http_headers_out_t, cache_control), 1 }, |
509 | 261 |
573 | 262 { ngx_string("Expires"), |
2666 | 263 ngx_http_upstream_process_expires, 0, |
573 | 264 ngx_http_upstream_copy_header_line, |
265 offsetof(ngx_http_headers_out_t, expires), 1 }, | |
266 | |
577 | 267 { ngx_string("Accept-Ranges"), |
268 ngx_http_upstream_process_header_line, | |
269 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
|
270 ngx_http_upstream_copy_allow_ranges, |
577 | 271 offsetof(ngx_http_headers_out_t, accept_ranges), 1 }, |
272 | |
6316
f44de0d12143
Upstream: fill r->headers_out.content_range from upstream response.
Roman Arutyunyan <arut@nginx.com>
parents:
6313
diff
changeset
|
273 { ngx_string("Content-Range"), |
f44de0d12143
Upstream: fill r->headers_out.content_range from upstream response.
Roman Arutyunyan <arut@nginx.com>
parents:
6313
diff
changeset
|
274 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
|
275 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
|
276 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
|
277 |
509 | 278 { ngx_string("Connection"), |
4124
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
279 ngx_http_upstream_process_connection, 0, |
515 | 280 ngx_http_upstream_ignore_header_line, 0, 0 }, |
509 | 281 |
641 | 282 { ngx_string("Keep-Alive"), |
283 ngx_http_upstream_ignore_header_line, 0, | |
284 ngx_http_upstream_ignore_header_line, 0, 0 }, | |
285 | |
5877
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
286 { ngx_string("Vary"), |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
287 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
|
288 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
|
289 |
7199
6ba68ad8b24c
Basic support of the Link response header.
Ruslan Ermilov <ru@nginx.com>
parents:
7194
diff
changeset
|
290 { ngx_string("Link"), |
6ba68ad8b24c
Basic support of the Link response header.
Ruslan Ermilov <ru@nginx.com>
parents:
7194
diff
changeset
|
291 ngx_http_upstream_ignore_header_line, 0, |
6ba68ad8b24c
Basic support of the Link response header.
Ruslan Ermilov <ru@nginx.com>
parents:
7194
diff
changeset
|
292 ngx_http_upstream_copy_multi_header_lines, |
6ba68ad8b24c
Basic support of the Link response header.
Ruslan Ermilov <ru@nginx.com>
parents:
7194
diff
changeset
|
293 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
|
294 |
509 | 295 { ngx_string("X-Accel-Expires"), |
2664 | 296 ngx_http_upstream_process_accel_expires, 0, |
649 | 297 ngx_http_upstream_copy_header_line, 0, 0 }, |
515 | 298 |
299 { ngx_string("X-Accel-Redirect"), | |
300 ngx_http_upstream_process_header_line, | |
301 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
|
302 ngx_http_upstream_copy_header_line, 0, 0 }, |
509 | 303 |
527 | 304 { ngx_string("X-Accel-Limit-Rate"), |
305 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
|
306 ngx_http_upstream_copy_header_line, 0, 0 }, |
527 | 307 |
649 | 308 { ngx_string("X-Accel-Buffering"), |
309 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
|
310 ngx_http_upstream_copy_header_line, 0, 0 }, |
649 | 311 |
657 | 312 { ngx_string("X-Accel-Charset"), |
313 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
|
314 ngx_http_upstream_copy_header_line, 0, 0 }, |
657 | 315 |
4123
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
316 { ngx_string("Transfer-Encoding"), |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
317 ngx_http_upstream_process_transfer_encoding, 0, |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
318 ngx_http_upstream_ignore_header_line, 0, 0 }, |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
319 |
509 | 320 #if (NGX_HTTP_GZIP) |
321 { ngx_string("Content-Encoding"), | |
322 ngx_http_upstream_process_header_line, | |
323 offsetof(ngx_http_upstream_headers_in_t, content_encoding), | |
515 | 324 ngx_http_upstream_copy_content_encoding, 0, 0 }, |
509 | 325 #endif |
326 | |
515 | 327 { ngx_null_string, NULL, 0, NULL, 0, 0 } |
509 | 328 }; |
479 | 329 |
330 | |
651 | 331 static ngx_command_t ngx_http_upstream_commands[] = { |
332 | |
333 { ngx_string("upstream"), | |
334 NGX_HTTP_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_TAKE1, | |
335 ngx_http_upstream, | |
336 0, | |
337 0, | |
338 NULL }, | |
339 | |
340 { ngx_string("server"), | |
884 | 341 NGX_HTTP_UPS_CONF|NGX_CONF_1MORE, |
651 | 342 ngx_http_upstream_server, |
343 NGX_HTTP_SRV_CONF_OFFSET, | |
344 0, | |
345 NULL }, | |
346 | |
347 ngx_null_command | |
348 }; | |
349 | |
350 | |
351 static ngx_http_module_t ngx_http_upstream_module_ctx = { | |
573 | 352 ngx_http_upstream_add_variables, /* preconfiguration */ |
509 | 353 NULL, /* postconfiguration */ |
354 | |
355 ngx_http_upstream_create_main_conf, /* create main configuration */ | |
651 | 356 ngx_http_upstream_init_main_conf, /* init main configuration */ |
479 | 357 |
358 NULL, /* create server configuration */ | |
359 NULL, /* merge server configuration */ | |
360 | |
361 NULL, /* create location configuration */ | |
362 NULL /* merge location configuration */ | |
363 }; | |
577 | 364 |
479 | 365 |
366 ngx_module_t ngx_http_upstream_module = { | |
509 | 367 NGX_MODULE_V1, |
479 | 368 &ngx_http_upstream_module_ctx, /* module context */ |
651 | 369 ngx_http_upstream_commands, /* module directives */ |
479 | 370 NGX_HTTP_MODULE, /* module type */ |
541 | 371 NULL, /* init master */ |
479 | 372 NULL, /* init module */ |
541 | 373 NULL, /* init process */ |
374 NULL, /* init thread */ | |
375 NULL, /* exit thread */ | |
376 NULL, /* exit process */ | |
377 NULL, /* exit master */ | |
378 NGX_MODULE_V1_PADDING | |
479 | 379 }; |
380 | |
381 | |
573 | 382 static ngx_http_variable_t ngx_http_upstream_vars[] = { |
383 | |
1181 | 384 { 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
|
385 ngx_http_upstream_addr_variable, 0, |
3898
bd1222fb0192
allow to use $upstream_... variables in SSI
Igor Sysoev <igor@sysoev.ru>
parents:
3879
diff
changeset
|
386 NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
1181 | 387 |
637 | 388 { 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
|
389 ngx_http_upstream_status_variable, 0, |
3898
bd1222fb0192
allow to use $upstream_... variables in SSI
Igor Sysoev <igor@sysoev.ru>
parents:
3879
diff
changeset
|
390 NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
573 | 391 |
6147
74b6ef56ea56
Upstream: $upstream_connect_time.
Ruslan Ermilov <ru@nginx.com>
parents:
6146
diff
changeset
|
392 { ngx_string("upstream_connect_time"), NULL, |
74b6ef56ea56
Upstream: $upstream_connect_time.
Ruslan Ermilov <ru@nginx.com>
parents:
6146
diff
changeset
|
393 ngx_http_upstream_response_time_variable, 2, |
74b6ef56ea56
Upstream: $upstream_connect_time.
Ruslan Ermilov <ru@nginx.com>
parents:
6146
diff
changeset
|
394 NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
74b6ef56ea56
Upstream: $upstream_connect_time.
Ruslan Ermilov <ru@nginx.com>
parents:
6146
diff
changeset
|
395 |
5964
0a198a517eaf
Upstream: $upstream_header_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
5960
diff
changeset
|
396 { ngx_string("upstream_header_time"), NULL, |
0a198a517eaf
Upstream: $upstream_header_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
5960
diff
changeset
|
397 ngx_http_upstream_response_time_variable, 1, |
0a198a517eaf
Upstream: $upstream_header_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
5960
diff
changeset
|
398 NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
0a198a517eaf
Upstream: $upstream_header_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
5960
diff
changeset
|
399 |
637 | 400 { 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
|
401 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
|
402 NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
573 | 403 |
2402 | 404 { ngx_string("upstream_response_length"), NULL, |
405 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
|
406 NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
2402 | 407 |
6654
c131f20c9562
Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6594
diff
changeset
|
408 { ngx_string("upstream_bytes_received"), NULL, |
c131f20c9562
Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6594
diff
changeset
|
409 ngx_http_upstream_response_length_variable, 1, |
c131f20c9562
Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6594
diff
changeset
|
410 NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
c131f20c9562
Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6594
diff
changeset
|
411 |
2957
b4f39842523b
fix building --without-http-cache, broken in r2953
Igor Sysoev <igor@sysoev.ru>
parents:
2953
diff
changeset
|
412 #if (NGX_HTTP_CACHE) |
b4f39842523b
fix building --without-http-cache, broken in r2953
Igor Sysoev <igor@sysoev.ru>
parents:
2953
diff
changeset
|
413 |
2952 | 414 { ngx_string("upstream_cache_status"), NULL, |
415 ngx_http_upstream_cache_status, 0, | |
3898
bd1222fb0192
allow to use $upstream_... variables in SSI
Igor Sysoev <igor@sysoev.ru>
parents:
3879
diff
changeset
|
416 NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
2952 | 417 |
5441
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
418 { ngx_string("upstream_cache_last_modified"), NULL, |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
419 ngx_http_upstream_cache_last_modified, 0, |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
420 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
|
421 |
5738
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
422 { ngx_string("upstream_cache_etag"), NULL, |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
423 ngx_http_upstream_cache_etag, 0, |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
424 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
|
425 |
2957
b4f39842523b
fix building --without-http-cache, broken in r2953
Igor Sysoev <igor@sysoev.ru>
parents:
2953
diff
changeset
|
426 #endif |
b4f39842523b
fix building --without-http-cache, broken in r2953
Igor Sysoev <igor@sysoev.ru>
parents:
2953
diff
changeset
|
427 |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6876
diff
changeset
|
428 { ngx_string("upstream_http_"), NULL, ngx_http_upstream_header_variable, |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6876
diff
changeset
|
429 0, NGX_HTTP_VAR_NOCACHEABLE|NGX_HTTP_VAR_PREFIX, 0 }, |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6876
diff
changeset
|
430 |
7230
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
431 { 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
|
432 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
|
433 |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6876
diff
changeset
|
434 { ngx_string("upstream_cookie_"), NULL, ngx_http_upstream_cookie_variable, |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6876
diff
changeset
|
435 0, NGX_HTTP_VAR_NOCACHEABLE|NGX_HTTP_VAR_PREFIX, 0 }, |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6876
diff
changeset
|
436 |
7077
2a288909abc6
Variables: macros for null variables.
Ruslan Ermilov <ru@nginx.com>
parents:
7070
diff
changeset
|
437 ngx_http_null_variable |
573 | 438 }; |
439 | |
440 | |
2268
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
441 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
|
442 { 500, NGX_HTTP_UPSTREAM_FT_HTTP_500 }, |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
443 { 502, NGX_HTTP_UPSTREAM_FT_HTTP_502 }, |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
444 { 503, NGX_HTTP_UPSTREAM_FT_HTTP_503 }, |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
445 { 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
|
446 { 403, NGX_HTTP_UPSTREAM_FT_HTTP_403 }, |
2268
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
447 { 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
|
448 { 429, NGX_HTTP_UPSTREAM_FT_HTTP_429 }, |
2268
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
449 { 0, 0 } |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
450 }; |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
451 |
2875
6e1941b321b7
proxy_cache_methods and fastcgi_cache_methods
Igor Sysoev <igor@sysoev.ru>
parents:
2874
diff
changeset
|
452 |
6e1941b321b7
proxy_cache_methods and fastcgi_cache_methods
Igor Sysoev <igor@sysoev.ru>
parents:
2874
diff
changeset
|
453 ngx_conf_bitmask_t ngx_http_upstream_cache_method_mask[] = { |
6439 | 454 { ngx_string("GET"), NGX_HTTP_GET }, |
455 { ngx_string("HEAD"), NGX_HTTP_HEAD }, | |
456 { ngx_string("POST"), NGX_HTTP_POST }, | |
457 { ngx_null_string, 0 } | |
2875
6e1941b321b7
proxy_cache_methods and fastcgi_cache_methods
Igor Sysoev <igor@sysoev.ru>
parents:
2874
diff
changeset
|
458 }; |
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 |
3667
12bd9e26fadb
use shared ngx_http_upstream_ignore_headers_masks[]
Igor Sysoev <igor@sysoev.ru>
parents:
3527
diff
changeset
|
461 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
|
462 { 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
|
463 { 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
|
464 { 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
|
465 { 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
|
466 { 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
|
467 { 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
|
468 { 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
|
469 { 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
|
470 { 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
|
471 { ngx_null_string, 0 } |
12bd9e26fadb
use shared ngx_http_upstream_ignore_headers_masks[]
Igor Sysoev <igor@sysoev.ru>
parents:
3527
diff
changeset
|
472 }; |
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 |
3006
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
475 ngx_int_t |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
476 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
|
477 { |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
478 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
|
479 |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
480 u = r->upstream; |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
481 |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
482 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
|
483 r->main->count++; |
3006
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
484 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
|
485 } |
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 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
|
488 if (u == NULL) { |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
489 return NGX_ERROR; |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
490 } |
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 r->upstream = u; |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
493 |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
494 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
|
495 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
|
496 |
3056
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
497 #if (NGX_HTTP_CACHE) |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
498 r->cache = NULL; |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
499 #endif |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
500 |
4117
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
501 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
|
502 u->headers_in.last_modified_time = -1; |
4117
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
503 |
3006
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
504 return NGX_OK; |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
505 } |
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 |
487 | 508 void |
509 ngx_http_upstream_init(ngx_http_request_t *r) | |
479 | 510 { |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
511 ngx_connection_t *c; |
479 | 512 |
513 c = r->connection; | |
514 | |
515 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
516 "http init upstream, client timer: %d", c->read->timer_set); | |
517 | |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
6242
diff
changeset
|
518 #if (NGX_HTTP_V2) |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
6242
diff
changeset
|
519 if (r->stream) { |
5121
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
5113
diff
changeset
|
520 ngx_http_upstream_init_request(r); |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
5113
diff
changeset
|
521 return; |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
5113
diff
changeset
|
522 } |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
5113
diff
changeset
|
523 #endif |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
5113
diff
changeset
|
524 |
479 | 525 if (c->read->timer_set) { |
526 ngx_del_timer(c->read); | |
527 } | |
528 | |
529 if (ngx_event_flags & NGX_USE_CLEAR_EVENT) { | |
530 | |
531 if (!c->write->active) { | |
531 | 532 if (ngx_add_event(c->write, NGX_WRITE_EVENT, NGX_CLEAR_EVENT) |
533 == NGX_ERROR) | |
479 | 534 { |
535 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | |
536 return; | |
537 } | |
538 } | |
539 } | |
540 | |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
541 ngx_http_upstream_init_request(r); |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
542 } |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
543 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
544 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
545 static void |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
546 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
|
547 { |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
548 ngx_str_t *host; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
549 ngx_uint_t i; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
550 ngx_resolver_ctx_t *ctx, temp; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
551 ngx_http_cleanup_t *cln; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
552 ngx_http_upstream_t *u; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
553 ngx_http_core_loc_conf_t *clcf; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
554 ngx_http_upstream_srv_conf_t *uscf, **uscfp; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
555 ngx_http_upstream_main_conf_t *umcf; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
556 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
557 if (r->aio) { |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
558 return; |
537 | 559 } |
509 | 560 |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
561 u = r->upstream; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
562 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
563 #if (NGX_HTTP_CACHE) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
564 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
565 if (u->conf->cache) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
566 ngx_int_t rc; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
567 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
568 rc = ngx_http_upstream_cache(r, u); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
569 |
3055
92b6cfaa3c27
fix sending a cached file using AIO
Igor Sysoev <igor@sysoev.ru>
parents:
3053
diff
changeset
|
570 if (rc == NGX_BUSY) { |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
571 r->write_event_handler = ngx_http_upstream_init_request; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
572 return; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
573 } |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
574 |
3055
92b6cfaa3c27
fix sending a cached file using AIO
Igor Sysoev <igor@sysoev.ru>
parents:
3053
diff
changeset
|
575 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
|
576 |
5827
54e9b83d00f0
Upstream: avoided directly terminating the connection.
FengGu <flygoast@126.com>
parents:
5818
diff
changeset
|
577 if (rc == NGX_ERROR) { |
54e9b83d00f0
Upstream: avoided directly terminating the connection.
FengGu <flygoast@126.com>
parents:
5818
diff
changeset
|
578 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
|
579 return; |
54e9b83d00f0
Upstream: avoided directly terminating the connection.
FengGu <flygoast@126.com>
parents:
5818
diff
changeset
|
580 } |
54e9b83d00f0
Upstream: avoided directly terminating the connection.
FengGu <flygoast@126.com>
parents:
5818
diff
changeset
|
581 |
6242
0e3a45ec2a3a
Upstream: fixed cache send error handling.
Roman Arutyunyan <arut@nginx.com>
parents:
6180
diff
changeset
|
582 if (rc == NGX_OK) { |
0e3a45ec2a3a
Upstream: fixed cache send error handling.
Roman Arutyunyan <arut@nginx.com>
parents:
6180
diff
changeset
|
583 rc = ngx_http_upstream_cache_send(r, u); |
0e3a45ec2a3a
Upstream: fixed cache send error handling.
Roman Arutyunyan <arut@nginx.com>
parents:
6180
diff
changeset
|
584 |
0e3a45ec2a3a
Upstream: fixed cache send error handling.
Roman Arutyunyan <arut@nginx.com>
parents:
6180
diff
changeset
|
585 if (rc == NGX_DONE) { |
0e3a45ec2a3a
Upstream: fixed cache send error handling.
Roman Arutyunyan <arut@nginx.com>
parents:
6180
diff
changeset
|
586 return; |
0e3a45ec2a3a
Upstream: fixed cache send error handling.
Roman Arutyunyan <arut@nginx.com>
parents:
6180
diff
changeset
|
587 } |
0e3a45ec2a3a
Upstream: fixed cache send error handling.
Roman Arutyunyan <arut@nginx.com>
parents:
6180
diff
changeset
|
588 |
0e3a45ec2a3a
Upstream: fixed cache send error handling.
Roman Arutyunyan <arut@nginx.com>
parents:
6180
diff
changeset
|
589 if (rc == NGX_HTTP_UPSTREAM_INVALID_HEADER) { |
0e3a45ec2a3a
Upstream: fixed cache send error handling.
Roman Arutyunyan <arut@nginx.com>
parents:
6180
diff
changeset
|
590 rc = NGX_DECLINED; |
0e3a45ec2a3a
Upstream: fixed cache send error handling.
Roman Arutyunyan <arut@nginx.com>
parents:
6180
diff
changeset
|
591 r->cached = 0; |
7116
46ddff109e72
Upstream: better handling of invalid headers in cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7093
diff
changeset
|
592 u->buffer.start = NULL; |
46ddff109e72
Upstream: better handling of invalid headers in cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7093
diff
changeset
|
593 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
|
594 u->request_sent = 1; |
6242
0e3a45ec2a3a
Upstream: fixed cache send error handling.
Roman Arutyunyan <arut@nginx.com>
parents:
6180
diff
changeset
|
595 } |
6906
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
596 |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
597 if (ngx_http_upstream_cache_background_update(r, u) != NGX_OK) { |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
598 rc = NGX_ERROR; |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
599 } |
6242
0e3a45ec2a3a
Upstream: fixed cache send error handling.
Roman Arutyunyan <arut@nginx.com>
parents:
6180
diff
changeset
|
600 } |
0e3a45ec2a3a
Upstream: fixed cache send error handling.
Roman Arutyunyan <arut@nginx.com>
parents:
6180
diff
changeset
|
601 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
602 if (rc != NGX_DECLINED) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
603 ngx_http_finalize_request(r, rc); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
604 return; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
605 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
606 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
607 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
608 #endif |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
609 |
5947
d9025ea1f5a5
Upstream: simplified proxy_store and friends configuration code.
Valentin Bartenev <vbart@nginx.com>
parents:
5935
diff
changeset
|
610 u->store = u->conf->store; |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
611 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
612 if (!u->store && !r->post_action && !u->conf->ignore_client_abort) { |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
613 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
|
614 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
|
615 } |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
616 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
617 if (r->request_body) { |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
618 u->request_bufs = r->request_body->bufs; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
619 } |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
620 |
537 | 621 if (u->create_request(r) != NGX_OK) { |
479 | 622 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); |
623 return; | |
624 } | |
625 | |
6528
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
626 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
|
627 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
|
628 return; |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
629 } |
3271
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3198
diff
changeset
|
630 |
509 | 631 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
479 | 632 |
3053 | 633 u->output.alignment = clcf->directio_alignment; |
479 | 634 u->output.pool = r->pool; |
635 u->output.bufs.num = 1; | |
509 | 636 u->output.bufs.size = clcf->client_body_buffer_size; |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
637 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
638 if (u->output.output_filter == NULL) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
639 u->output.output_filter = ngx_chain_writer; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
640 u->output.filter_ctx = &u->writer; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
641 } |
479 | 642 |
643 u->writer.pool = r->pool; | |
644 | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
645 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
|
646 |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
647 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
|
648 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
|
649 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
|
650 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
|
651 return; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
652 } |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
653 |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
654 } else { |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
655 |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
656 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
|
657 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
|
658 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
|
659 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
|
660 return; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
661 } |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
662 |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
663 ngx_memzero(u->state, sizeof(ngx_http_upstream_state_t)); |
479 | 664 } |
665 | |
593 | 666 cln = ngx_http_cleanup_add(r, 0); |
569 | 667 if (cln == NULL) { |
668 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | |
669 return; | |
670 } | |
671 | |
672 cln->handler = ngx_http_upstream_cleanup; | |
673 cln->data = r; | |
674 u->cleanup = &cln->handler; | |
675 | |
1658 | 676 if (u->resolved == NULL) { |
677 | |
678 uscf = u->conf->upstream; | |
679 | |
680 } else { | |
681 | |
5660
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
682 #if (NGX_HTTP_SSL) |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
683 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
|
684 #endif |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
685 |
6303
a93345ee8f52
Upstream: fixed "no port" detection in evaluated upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6290
diff
changeset
|
686 host = &u->resolved->host; |
a93345ee8f52
Upstream: fixed "no port" detection in evaluated upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6290
diff
changeset
|
687 |
6786
906ac20234ed
Upstream: do not unnecessarily create per-request upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6777
diff
changeset
|
688 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
|
689 |
906ac20234ed
Upstream: do not unnecessarily create per-request upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6777
diff
changeset
|
690 uscfp = umcf->upstreams.elts; |
906ac20234ed
Upstream: do not unnecessarily create per-request upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6777
diff
changeset
|
691 |
906ac20234ed
Upstream: do not unnecessarily create per-request upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6777
diff
changeset
|
692 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
|
693 |
906ac20234ed
Upstream: do not unnecessarily create per-request upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6777
diff
changeset
|
694 uscf = uscfp[i]; |
906ac20234ed
Upstream: do not unnecessarily create per-request upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6777
diff
changeset
|
695 |
906ac20234ed
Upstream: do not unnecessarily create per-request upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6777
diff
changeset
|
696 if (uscf->host.len == host->len |
906ac20234ed
Upstream: do not unnecessarily create per-request upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6777
diff
changeset
|
697 && ((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
|
698 || uscf->port == u->resolved->port) |
906ac20234ed
Upstream: do not unnecessarily create per-request upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6777
diff
changeset
|
699 && 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
|
700 { |
906ac20234ed
Upstream: do not unnecessarily create per-request upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6777
diff
changeset
|
701 goto found; |
906ac20234ed
Upstream: do not unnecessarily create per-request upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6777
diff
changeset
|
702 } |
906ac20234ed
Upstream: do not unnecessarily create per-request upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6777
diff
changeset
|
703 } |
906ac20234ed
Upstream: do not unnecessarily create per-request upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6777
diff
changeset
|
704 |
2422
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2413
diff
changeset
|
705 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
|
706 |
6326
705c356ce664
Fixed fastcgi_pass with UNIX socket and variables (ticket #855).
Ruslan Ermilov <ru@nginx.com>
parents:
6316
diff
changeset
|
707 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
|
708 && 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
|
709 { |
6303
a93345ee8f52
Upstream: fixed "no port" detection in evaluated upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6290
diff
changeset
|
710 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
|
711 "no port in upstream \"%V\"", host); |
a93345ee8f52
Upstream: fixed "no port" detection in evaluated upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6290
diff
changeset
|
712 ngx_http_upstream_finalize_request(r, u, |
6313 | 713 NGX_HTTP_INTERNAL_SERVER_ERROR); |
6303
a93345ee8f52
Upstream: fixed "no port" detection in evaluated upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6290
diff
changeset
|
714 return; |
a93345ee8f52
Upstream: fixed "no port" detection in evaluated upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6290
diff
changeset
|
715 } |
a93345ee8f52
Upstream: fixed "no port" detection in evaluated upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6290
diff
changeset
|
716 |
2422
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2413
diff
changeset
|
717 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
|
718 != NGX_OK) |
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2413
diff
changeset
|
719 { |
3169
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
720 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
|
721 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
|
722 return; |
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2413
diff
changeset
|
723 } |
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2413
diff
changeset
|
724 |
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2413
diff
changeset
|
725 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
|
726 |
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2413
diff
changeset
|
727 return; |
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2413
diff
changeset
|
728 } |
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2413
diff
changeset
|
729 |
3879
502a6b0acf3f
fix case when a host in fastcgi_pass, scgi_pass, and uwsgi_pass
Igor Sysoev <igor@sysoev.ru>
parents:
3713
diff
changeset
|
730 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
|
731 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
|
732 "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
|
733 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
|
734 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
|
735 return; |
502a6b0acf3f
fix case when a host in fastcgi_pass, scgi_pass, and uwsgi_pass
Igor Sysoev <igor@sysoev.ru>
parents:
3713
diff
changeset
|
736 } |
502a6b0acf3f
fix case when a host in fastcgi_pass, scgi_pass, and uwsgi_pass
Igor Sysoev <igor@sysoev.ru>
parents:
3713
diff
changeset
|
737 |
1658 | 738 temp.name = *host; |
739 | |
740 ctx = ngx_resolve_start(clcf->resolver, &temp); | |
741 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
|
742 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
|
743 NGX_HTTP_INTERNAL_SERVER_ERROR); |
1658 | 744 return; |
745 } | |
746 | |
1683
1e0b028055ec
allow to use IP addresses without defined resolver
Igor Sysoev <igor@sysoev.ru>
parents:
1658
diff
changeset
|
747 if (ctx == NGX_NO_RESOLVER) { |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
748 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
|
749 "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
|
750 |
3169
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
751 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
|
752 return; |
1e0b028055ec
allow to use IP addresses without defined resolver
Igor Sysoev <igor@sysoev.ru>
parents:
1658
diff
changeset
|
753 } |
1e0b028055ec
allow to use IP addresses without defined resolver
Igor Sysoev <igor@sysoev.ru>
parents:
1658
diff
changeset
|
754 |
1658 | 755 ctx->name = *host; |
756 ctx->handler = ngx_http_upstream_resolve_handler; | |
757 ctx->data = r; | |
758 ctx->timeout = clcf->resolver_timeout; | |
759 | |
1959
4f16186f5603
quick resolving handles u->resolved->ctx by itself
Igor Sysoev <igor@sysoev.ru>
parents:
1958
diff
changeset
|
760 u->resolved->ctx = ctx; |
4f16186f5603
quick resolving handles u->resolved->ctx by itself
Igor Sysoev <igor@sysoev.ru>
parents:
1958
diff
changeset
|
761 |
1658 | 762 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
|
763 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
|
764 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
|
765 NGX_HTTP_INTERNAL_SERVER_ERROR); |
1658 | 766 return; |
767 } | |
768 | |
769 return; | |
770 } | |
771 | |
772 found: | |
773 | |
4964
2464ccebdb52
Upstream: fixed SIGSEGV with the "if" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4916
diff
changeset
|
774 if (uscf == NULL) { |
2464ccebdb52
Upstream: fixed SIGSEGV with the "if" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4916
diff
changeset
|
775 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
|
776 "no upstream configuration"); |
2464ccebdb52
Upstream: fixed SIGSEGV with the "if" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4916
diff
changeset
|
777 ngx_http_upstream_finalize_request(r, u, |
2464ccebdb52
Upstream: fixed SIGSEGV with the "if" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4916
diff
changeset
|
778 NGX_HTTP_INTERNAL_SERVER_ERROR); |
2464ccebdb52
Upstream: fixed SIGSEGV with the "if" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4916
diff
changeset
|
779 return; |
2464ccebdb52
Upstream: fixed SIGSEGV with the "if" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4916
diff
changeset
|
780 } |
2464ccebdb52
Upstream: fixed SIGSEGV with the "if" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4916
diff
changeset
|
781 |
6703
edcd9303a4d3
Upstream: introduced u->upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6699
diff
changeset
|
782 u->upstream = uscf; |
edcd9303a4d3
Upstream: introduced u->upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6699
diff
changeset
|
783 |
5682
110b50657d77
Upstream: restored workaround for "if".
Maxim Dounin <mdounin@mdounin.ru>
parents:
5677
diff
changeset
|
784 #if (NGX_HTTP_SSL) |
110b50657d77
Upstream: restored workaround for "if".
Maxim Dounin <mdounin@mdounin.ru>
parents:
5677
diff
changeset
|
785 u->ssl_name = uscf->host; |
110b50657d77
Upstream: restored workaround for "if".
Maxim Dounin <mdounin@mdounin.ru>
parents:
5677
diff
changeset
|
786 #endif |
110b50657d77
Upstream: restored workaround for "if".
Maxim Dounin <mdounin@mdounin.ru>
parents:
5677
diff
changeset
|
787 |
1658 | 788 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
|
789 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
|
790 NGX_HTTP_INTERNAL_SERVER_ERROR); |
1658 | 791 return; |
792 } | |
793 | |
5832
d09b689911ac
Upstream: limited next_upstream time and tries (ticket #544).
Roman Arutyunyan <arut@nginx.com>
parents:
5827
diff
changeset
|
794 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
|
795 |
d09b689911ac
Upstream: limited next_upstream time and tries (ticket #544).
Roman Arutyunyan <arut@nginx.com>
parents:
5827
diff
changeset
|
796 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
|
797 && 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
|
798 { |
d09b689911ac
Upstream: limited next_upstream time and tries (ticket #544).
Roman Arutyunyan <arut@nginx.com>
parents:
5827
diff
changeset
|
799 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
|
800 } |
d09b689911ac
Upstream: limited next_upstream time and tries (ticket #544).
Roman Arutyunyan <arut@nginx.com>
parents:
5827
diff
changeset
|
801 |
479 | 802 ngx_http_upstream_connect(r, u); |
803 } | |
804 | |
805 | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
806 #if (NGX_HTTP_CACHE) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
807 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
808 static ngx_int_t |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
809 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
|
810 { |
5951
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
811 ngx_int_t rc; |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
812 ngx_http_cache_t *c; |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
813 ngx_http_file_cache_t *cache; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
814 |
3056
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
815 c = r->cache; |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
816 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
817 if (c == NULL) { |
3056
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
818 |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
819 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
|
820 return NGX_DECLINED; |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
821 } |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
822 |
5951
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
823 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
|
824 |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
825 if (rc != NGX_OK) { |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
826 return rc; |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
827 } |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
828 |
6306
b1858fc47e3b
Style: unified request method checks.
Ruslan Ermilov <ru@nginx.com>
parents:
6303
diff
changeset
|
829 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
|
830 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
|
831 } |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
832 |
3698
d11227f0107f
rename ngx_http_file_cache_create() to ngx_http_file_cache_new()
Igor Sysoev <igor@sysoev.ru>
parents:
3697
diff
changeset
|
833 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
|
834 return NGX_ERROR; |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
835 } |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
836 |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
837 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
|
838 return NGX_ERROR; |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
839 } |
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 /* TODO: add keys */ |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
842 |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
843 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
|
844 |
3976
215fe9223419
update r3945 with more descriptive error message
Igor Sysoev <igor@sysoev.ru>
parents:
3963
diff
changeset
|
845 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
|
846 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
|
847 "%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
|
848 "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
|
849 &u->conf->module, u->conf->buffer_size, |
215fe9223419
update r3945 with more descriptive error message
Igor Sysoev <igor@sysoev.ru>
parents:
3963
diff
changeset
|
850 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
|
851 |
f1f194ceab16
fix segfault if cache key is larger than upstream buffer size
Igor Sysoev <igor@sysoev.ru>
parents:
3940
diff
changeset
|
852 r->cache = NULL; |
f1f194ceab16
fix segfault if cache key is larger than upstream buffer size
Igor Sysoev <igor@sysoev.ru>
parents:
3940
diff
changeset
|
853 return NGX_DECLINED; |
f1f194ceab16
fix segfault if cache key is larger than upstream buffer size
Igor Sysoev <igor@sysoev.ru>
parents:
3940
diff
changeset
|
854 } |
f1f194ceab16
fix segfault if cache key is larger than upstream buffer size
Igor Sysoev <igor@sysoev.ru>
parents:
3940
diff
changeset
|
855 |
4176
2b5151a2300b
Fixed cache bypass caching of non-cacheable replies (ticket #21).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4152
diff
changeset
|
856 u->cacheable = 1; |
2b5151a2300b
Fixed cache bypass caching of non-cacheable replies (ticket #21).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4152
diff
changeset
|
857 |
5950
eaeecf00d5d7
Upstream: preset some cache configuration when bypassing.
Valentin Bartenev <vbart@nginx.com>
parents:
5949
diff
changeset
|
858 c = r->cache; |
eaeecf00d5d7
Upstream: preset some cache configuration when bypassing.
Valentin Bartenev <vbart@nginx.com>
parents:
5949
diff
changeset
|
859 |
eaeecf00d5d7
Upstream: preset some cache configuration when bypassing.
Valentin Bartenev <vbart@nginx.com>
parents:
5949
diff
changeset
|
860 c->body_start = u->conf->buffer_size; |
eaeecf00d5d7
Upstream: preset some cache configuration when bypassing.
Valentin Bartenev <vbart@nginx.com>
parents:
5949
diff
changeset
|
861 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
|
862 c->file_cache = cache; |
5950
eaeecf00d5d7
Upstream: preset some cache configuration when bypassing.
Valentin Bartenev <vbart@nginx.com>
parents:
5949
diff
changeset
|
863 |
3917
2a70484a6580
fix a broken cached response if bypass/no_cache directive values are different,
Igor Sysoev <igor@sysoev.ru>
parents:
3898
diff
changeset
|
864 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
|
865 |
2a70484a6580
fix a broken cached response if bypass/no_cache directive values are different,
Igor Sysoev <igor@sysoev.ru>
parents:
3898
diff
changeset
|
866 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
|
867 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
|
868 |
2a70484a6580
fix a broken cached response if bypass/no_cache directive values are different,
Igor Sysoev <igor@sysoev.ru>
parents:
3898
diff
changeset
|
869 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
|
870 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
|
871 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
|
872 |
2a70484a6580
fix a broken cached response if bypass/no_cache directive values are different,
Igor Sysoev <igor@sysoev.ru>
parents:
3898
diff
changeset
|
873 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
|
874 break; |
2a70484a6580
fix a broken cached response if bypass/no_cache directive values are different,
Igor Sysoev <igor@sysoev.ru>
parents:
3898
diff
changeset
|
875 } |
2a70484a6580
fix a broken cached response if bypass/no_cache directive values are different,
Igor Sysoev <igor@sysoev.ru>
parents:
3898
diff
changeset
|
876 |
4385
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4375
diff
changeset
|
877 c->lock = u->conf->cache_lock; |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4375
diff
changeset
|
878 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
|
879 c->lock_age = u->conf->cache_lock_age; |
4385
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4375
diff
changeset
|
880 |
3056
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
881 u->cache_status = NGX_HTTP_CACHE_MISS; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
882 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
883 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
884 rc = ngx_http_file_cache_open(r); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
885 |
2926
80a314b63c56
delete useless r->cache->uses
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
886 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
|
887 "http upstream cache: %i", rc); |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
888 |
2952 | 889 switch (rc) { |
890 | |
6906
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
891 case NGX_HTTP_CACHE_STALE: |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
892 |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
893 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
|
894 || c->stale_updating) && !r->background |
6906
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
895 && u->conf->cache_background_update) |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
896 { |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
897 r->cache->background = 1; |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
898 u->cache_status = rc; |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
899 rc = NGX_OK; |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
900 } |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
901 |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
902 break; |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
903 |
2952 | 904 case NGX_HTTP_CACHE_UPDATING: |
905 | |
6906
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
906 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
|
907 || 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
|
908 { |
2952 | 909 u->cache_status = rc; |
2927
55ceaef03d34
proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents:
2926
diff
changeset
|
910 rc = NGX_OK; |
55ceaef03d34
proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents:
2926
diff
changeset
|
911 |
55ceaef03d34
proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents:
2926
diff
changeset
|
912 } else { |
55ceaef03d34
proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents:
2926
diff
changeset
|
913 rc = NGX_HTTP_CACHE_STALE; |
55ceaef03d34
proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents:
2926
diff
changeset
|
914 } |
2952 | 915 |
916 break; | |
917 | |
918 case NGX_OK: | |
919 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
|
920 } |
55ceaef03d34
proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents:
2926
diff
changeset
|
921 |
2952 | 922 switch (rc) { |
923 | |
924 case NGX_OK: | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
925 |
6242
0e3a45ec2a3a
Upstream: fixed cache send error handling.
Roman Arutyunyan <arut@nginx.com>
parents:
6180
diff
changeset
|
926 return NGX_OK; |
2952 | 927 |
928 case NGX_HTTP_CACHE_STALE: | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
929 |
2665
4d627567c324
fix r2664: ..._cache_valid did not work for stale responses
Igor Sysoev <igor@sysoev.ru>
parents:
2664
diff
changeset
|
930 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
|
931 c->updating_sec = 0; |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
932 c->error_sec = 0; |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
933 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
934 u->buffer.start = NULL; |
2952 | 935 u->cache_status = NGX_HTTP_CACHE_EXPIRED; |
936 | |
937 break; | |
938 | |
939 case NGX_DECLINED: | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
940 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
941 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
|
942 u->buffer.start = NULL; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
943 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
944 } else { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
945 u->buffer.pos = u->buffer.start + c->header_start; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
946 u->buffer.last = u->buffer.pos; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
947 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
948 |
2952 | 949 break; |
950 | |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
951 case NGX_HTTP_CACHE_SCARCE: |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
952 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
953 u->cacheable = 0; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
954 |
2952 | 955 break; |
956 | |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
957 case NGX_AGAIN: |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
958 |
3055
92b6cfaa3c27
fix sending a cached file using AIO
Igor Sysoev <igor@sysoev.ru>
parents:
3053
diff
changeset
|
959 return NGX_BUSY; |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
960 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
961 case NGX_ERROR: |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
962 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
963 return NGX_ERROR; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
964 |
2952 | 965 default: |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
966 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
967 /* 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
|
968 |
2952 | 969 u->cache_status = NGX_HTTP_CACHE_HIT; |
970 | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
971 return rc; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
972 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
973 |
6793
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
974 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
|
975 u->cacheable = 0; |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
976 } |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
977 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
978 r->cached = 0; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
979 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
980 return NGX_DECLINED; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
981 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
982 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
983 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
984 static ngx_int_t |
5951
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
985 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
|
986 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
|
987 { |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
988 ngx_str_t *name, val; |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
989 ngx_uint_t i; |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
990 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
|
991 |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
992 if (u->conf->cache_zone) { |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
993 *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
|
994 return NGX_OK; |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
995 } |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
996 |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
997 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
|
998 return NGX_ERROR; |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
999 } |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
1000 |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
1001 if (val.len == 0 |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
1002 || (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
|
1003 { |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
1004 return NGX_DECLINED; |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
1005 } |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
1006 |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
1007 caches = u->caches->elts; |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
1008 |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
1009 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
|
1010 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
|
1011 |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
1012 if (name->len == val.len |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
1013 && 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
|
1014 { |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
1015 *cache = caches[i]; |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
1016 return NGX_OK; |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
1017 } |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
1018 } |
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 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
|
1021 "cache \"%V\" not found", &val); |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
1022 |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
1023 return NGX_ERROR; |
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 |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
1026 |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
1027 static ngx_int_t |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1028 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
|
1029 { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1030 ngx_int_t rc; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1031 ngx_http_cache_t *c; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1032 |
2952 | 1033 r->cached = 1; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1034 c = r->cache; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1035 |
3369
479468a7d982
fix handling cached HTTP/0.9 response
Igor Sysoev <igor@sysoev.ru>
parents:
3272
diff
changeset
|
1036 if (c->header_start == c->body_start) { |
479468a7d982
fix handling cached HTTP/0.9 response
Igor Sysoev <igor@sysoev.ru>
parents:
3272
diff
changeset
|
1037 r->http_version = NGX_HTTP_VERSION_9; |
479468a7d982
fix handling cached HTTP/0.9 response
Igor Sysoev <igor@sysoev.ru>
parents:
3272
diff
changeset
|
1038 return ngx_http_cache_send(r); |
479468a7d982
fix handling cached HTTP/0.9 response
Igor Sysoev <igor@sysoev.ru>
parents:
3272
diff
changeset
|
1039 } |
479468a7d982
fix handling cached HTTP/0.9 response
Igor Sysoev <igor@sysoev.ru>
parents:
3272
diff
changeset
|
1040 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1041 /* TODO: cache stack */ |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1042 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1043 u->buffer = *c->buf; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1044 u->buffer.pos += c->header_start; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1045 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1046 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
|
1047 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
|
1048 u->headers_in.last_modified_time = -1; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1049 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1050 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
|
1051 sizeof(ngx_table_elt_t)) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1052 != NGX_OK) |
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 return NGX_ERROR; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1055 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1056 |
7230
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
1057 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
|
1058 sizeof(ngx_table_elt_t)) |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
1059 != NGX_OK) |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
1060 { |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
1061 return NGX_ERROR; |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
1062 } |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
1063 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1064 rc = u->process_header(r); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1065 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1066 if (rc == NGX_OK) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1067 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1068 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
|
1069 return NGX_DONE; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1070 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1071 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1072 return ngx_http_cache_send(r); |
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 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1075 if (rc == NGX_ERROR) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1076 return NGX_ERROR; |
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 |
7116
46ddff109e72
Upstream: better handling of invalid headers in cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7093
diff
changeset
|
1079 if (rc == NGX_AGAIN) { |
46ddff109e72
Upstream: better handling of invalid headers in cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7093
diff
changeset
|
1080 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
|
1081 } |
46ddff109e72
Upstream: better handling of invalid headers in cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7093
diff
changeset
|
1082 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1083 /* rc == NGX_HTTP_UPSTREAM_INVALID_HEADER */ |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1084 |
7116
46ddff109e72
Upstream: better handling of invalid headers in cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7093
diff
changeset
|
1085 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
|
1086 "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
|
1087 c->file.name.data); |
46ddff109e72
Upstream: better handling of invalid headers in cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7093
diff
changeset
|
1088 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1089 /* TODO: delete file */ |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1090 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1091 return rc; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1092 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1093 |
6793
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1094 |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1095 static ngx_int_t |
6906
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
1096 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
|
1097 ngx_http_upstream_t *u) |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
1098 { |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
1099 ngx_http_request_t *sr; |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
1100 |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
1101 if (!r->cached || !r->cache->background) { |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
1102 return NGX_OK; |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
1103 } |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
1104 |
7070
f583559aadc7
Upstream: keep request body file from removal if requested.
Roman Arutyunyan <arut@nginx.com>
parents:
7067
diff
changeset
|
1105 if (r == r->main) { |
f583559aadc7
Upstream: keep request body file from removal if requested.
Roman Arutyunyan <arut@nginx.com>
parents:
7067
diff
changeset
|
1106 r->preserve_body = 1; |
f583559aadc7
Upstream: keep request body file from removal if requested.
Roman Arutyunyan <arut@nginx.com>
parents:
7067
diff
changeset
|
1107 } |
f583559aadc7
Upstream: keep request body file from removal if requested.
Roman Arutyunyan <arut@nginx.com>
parents:
7067
diff
changeset
|
1108 |
6906
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
1109 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
|
1110 NGX_HTTP_SUBREQUEST_CLONE |
9552758a786e
Background subrequests for cache updates.
Roman Arutyunyan <arut@nginx.com>
parents:
6986
diff
changeset
|
1111 |NGX_HTTP_SUBREQUEST_BACKGROUND) |
6906
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
1112 != NGX_OK) |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
1113 { |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
1114 return NGX_ERROR; |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
1115 } |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
1116 |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
1117 sr->header_only = 1; |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
1118 |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
1119 return NGX_OK; |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
1120 } |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
1121 |
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 static ngx_int_t |
6793
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1124 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
|
1125 ngx_http_upstream_t *u) |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1126 { |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1127 off_t offset; |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1128 u_char *p, *start; |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1129 ngx_table_elt_t *h; |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1130 |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1131 h = r->headers_in.range; |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1132 |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1133 if (h == NULL |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1134 || !u->cacheable |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1135 || 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
|
1136 { |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1137 return NGX_OK; |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1138 } |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1139 |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1140 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
|
1141 return NGX_DECLINED; |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1142 } |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1143 |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1144 if (h->value.len < 7 |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1145 || 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
|
1146 { |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1147 return NGX_OK; |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1148 } |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1149 |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1150 p = h->value.data + 6; |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1151 |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1152 while (*p == ' ') { p++; } |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1153 |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1154 if (*p == '-') { |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1155 return NGX_DECLINED; |
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 |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1158 start = p; |
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 while (*p >= '0' && *p <= '9') { p++; } |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1161 |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1162 offset = ngx_atoof(start, p - start); |
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 (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
|
1165 return NGX_DECLINED; |
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 |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1168 return NGX_OK; |
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 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1171 #endif |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1172 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1173 |
487 | 1174 static void |
1658 | 1175 ngx_http_upstream_resolve_handler(ngx_resolver_ctx_t *ctx) |
1176 { | |
7041
6169dbad37d8
Upstream: fixed running posted requests (ticket #788).
Roman Arutyunyan <arut@nginx.com>
parents:
7018
diff
changeset
|
1177 ngx_uint_t run_posted; |
5113
08b36f2afc3f
Upstream: fixed previous commit.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5112
diff
changeset
|
1178 ngx_connection_t *c; |
1658 | 1179 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
|
1180 ngx_http_upstream_t *u; |
1658 | 1181 ngx_http_upstream_resolved_t *ur; |
1182 | |
7041
6169dbad37d8
Upstream: fixed running posted requests (ticket #788).
Roman Arutyunyan <arut@nginx.com>
parents:
7018
diff
changeset
|
1183 run_posted = ctx->async; |
6169dbad37d8
Upstream: fixed running posted requests (ticket #788).
Roman Arutyunyan <arut@nginx.com>
parents:
7018
diff
changeset
|
1184 |
1658 | 1185 r = ctx->data; |
5113
08b36f2afc3f
Upstream: fixed previous commit.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5112
diff
changeset
|
1186 c = r->connection; |
1658 | 1187 |
3169
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
1188 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
|
1189 ur = u->resolved; |
1658 | 1190 |
5928
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5911
diff
changeset
|
1191 ngx_http_set_log_request(c->log, r); |
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5911
diff
changeset
|
1192 |
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5911
diff
changeset
|
1193 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, |
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5911
diff
changeset
|
1194 "http upstream resolve: \"%V?%V\"", &r->uri, &r->args); |
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5911
diff
changeset
|
1195 |
1658 | 1196 if (ctx->state) { |
1197 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
1198 "%V could not be resolved (%i: %s)", | |
1199 &ctx->name, ctx->state, | |
1200 ngx_resolver_strerror(ctx->state)); | |
1201 | |
3169
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
1202 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
|
1203 goto failed; |
1658 | 1204 } |
1205 | |
1206 ur->naddrs = ctx->naddrs; | |
1207 ur->addrs = ctx->addrs; | |
1208 | |
1209 #if (NGX_DEBUG) | |
1210 { | |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5453
diff
changeset
|
1211 u_char text[NGX_SOCKADDR_STRLEN]; |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5453
diff
changeset
|
1212 ngx_str_t addr; |
1658 | 1213 ngx_uint_t i; |
1214 | |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5453
diff
changeset
|
1215 addr.data = text; |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5453
diff
changeset
|
1216 |
1658 | 1217 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
|
1218 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
|
1219 text, NGX_SOCKADDR_STRLEN, 0); |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5453
diff
changeset
|
1220 |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5453
diff
changeset
|
1221 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
|
1222 "name was resolved to %V", &addr); |
1658 | 1223 } |
1224 } | |
1225 #endif | |
1226 | |
1227 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
|
1228 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
|
1229 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
|
1230 goto failed; |
1658 | 1231 } |
1232 | |
1233 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
|
1234 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
|
1235 |
5885
5a042519bfe7
Upstream: limited next_upstream time and tries when resolving DNS.
Gu Feng <flygoast@126.com>
parents:
5883
diff
changeset
|
1236 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
|
1237 |
5a042519bfe7
Upstream: limited next_upstream time and tries when resolving DNS.
Gu Feng <flygoast@126.com>
parents:
5883
diff
changeset
|
1238 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
|
1239 && 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
|
1240 { |
5a042519bfe7
Upstream: limited next_upstream time and tries when resolving DNS.
Gu Feng <flygoast@126.com>
parents:
5883
diff
changeset
|
1241 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
|
1242 } |
5a042519bfe7
Upstream: limited next_upstream time and tries when resolving DNS.
Gu Feng <flygoast@126.com>
parents:
5883
diff
changeset
|
1243 |
3169
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
1244 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
|
1245 |
d3c15c7831eb
Upstream: call ngx_http_run_posted_requests() on resolve errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5104
diff
changeset
|
1246 failed: |
d3c15c7831eb
Upstream: call ngx_http_run_posted_requests() on resolve errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5104
diff
changeset
|
1247 |
7041
6169dbad37d8
Upstream: fixed running posted requests (ticket #788).
Roman Arutyunyan <arut@nginx.com>
parents:
7018
diff
changeset
|
1248 if (run_posted) { |
6169dbad37d8
Upstream: fixed running posted requests (ticket #788).
Roman Arutyunyan <arut@nginx.com>
parents:
7018
diff
changeset
|
1249 ngx_http_run_posted_requests(c); |
6169dbad37d8
Upstream: fixed running posted requests (ticket #788).
Roman Arutyunyan <arut@nginx.com>
parents:
7018
diff
changeset
|
1250 } |
1658 | 1251 } |
1252 | |
1253 | |
1254 static void | |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1255 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
|
1256 { |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1257 ngx_connection_t *c; |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1258 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
|
1259 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
|
1260 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1261 c = ev->data; |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1262 r = c->data; |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1263 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1264 u = r->upstream; |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1265 c = r->connection; |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1266 |
5928
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5911
diff
changeset
|
1267 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
|
1268 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1269 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
|
1270 "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
|
1271 |
6961
903fb1ddc07f
Moved handling of wev->delayed to the connection event handler.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6950
diff
changeset
|
1272 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
|
1273 ev->delayed = 0; |
903fb1ddc07f
Moved handling of wev->delayed to the connection event handler.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6950
diff
changeset
|
1274 ev->timedout = 0; |
903fb1ddc07f
Moved handling of wev->delayed to the connection event handler.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6950
diff
changeset
|
1275 } |
903fb1ddc07f
Moved handling of wev->delayed to the connection event handler.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6950
diff
changeset
|
1276 |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1277 if (ev->write) { |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1278 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
|
1279 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1280 } else { |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1281 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
|
1282 } |
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 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
|
1285 } |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1286 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1287 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1288 static void |
509 | 1289 ngx_http_upstream_rd_check_broken_connection(ngx_http_request_t *r) |
1290 { | |
1291 ngx_http_upstream_check_broken_connection(r, r->connection->read); | |
1292 } | |
1293 | |
1294 | |
1295 static void | |
1296 ngx_http_upstream_wr_check_broken_connection(ngx_http_request_t *r) | |
1297 { | |
1298 ngx_http_upstream_check_broken_connection(r, r->connection->write); | |
1299 } | |
1300 | |
1301 | |
1302 static void | |
1303 ngx_http_upstream_check_broken_connection(ngx_http_request_t *r, | |
1304 ngx_event_t *ev) | |
479 | 1305 { |
1306 int n; | |
1307 char buf[1]; | |
577 | 1308 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
|
1309 ngx_int_t event; |
479 | 1310 ngx_connection_t *c; |
1311 ngx_http_upstream_t *u; | |
1312 | |
527 | 1313 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, ev->log, 0, |
1314 "http upstream check client, write event:%d, \"%V\"", | |
1315 ev->write, &r->uri); | |
479 | 1316 |
509 | 1317 c = r->connection; |
483 | 1318 u = r->upstream; |
1319 | |
583 | 1320 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
|
1321 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
|
1322 |
6ad4bba6313e
delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents:
2805
diff
changeset
|
1323 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
|
1324 |
6ad4bba6313e
delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents:
2805
diff
changeset
|
1325 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
|
1326 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
|
1327 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
|
1328 return; |
6ad4bba6313e
delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents:
2805
diff
changeset
|
1329 } |
6ad4bba6313e
delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents:
2805
diff
changeset
|
1330 } |
6ad4bba6313e
delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents:
2805
diff
changeset
|
1331 |
2757
9cc973b46af1
get a full response if the response is cacheable or storable even
Igor Sysoev <igor@sysoev.ru>
parents:
2708
diff
changeset
|
1332 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
|
1333 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
|
1334 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
|
1335 } |
2807
6ad4bba6313e
delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents:
2805
diff
changeset
|
1336 |
527 | 1337 return; |
1338 } | |
1339 | |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
6242
diff
changeset
|
1340 #if (NGX_HTTP_V2) |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
6242
diff
changeset
|
1341 if (r->stream) { |
5121
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
5113
diff
changeset
|
1342 return; |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
5113
diff
changeset
|
1343 } |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
5113
diff
changeset
|
1344 #endif |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
5113
diff
changeset
|
1345 |
479 | 1346 #if (NGX_HAVE_KQUEUE) |
1347 | |
1348 if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) { | |
1349 | |
1350 if (!ev->pending_eof) { | |
1351 return; | |
1352 } | |
1353 | |
1354 ev->eof = 1; | |
583 | 1355 c->error = 1; |
479 | 1356 |
1357 if (ev->kq_errno) { | |
1358 ev->error = 1; | |
1359 } | |
1360 | |
2757
9cc973b46af1
get a full response if the response is cacheable or storable even
Igor Sysoev <igor@sysoev.ru>
parents:
2708
diff
changeset
|
1361 if (!u->cacheable && u->peer.connection) { |
479 | 1362 ngx_log_error(NGX_LOG_INFO, ev->log, ev->kq_errno, |
4182 | 1363 "kevent() reported that client prematurely closed " |
527 | 1364 "connection, so upstream connection is closed too"); |
479 | 1365 ngx_http_upstream_finalize_request(r, u, |
1366 NGX_HTTP_CLIENT_CLOSED_REQUEST); | |
1367 return; | |
1368 } | |
1369 | |
1370 ngx_log_error(NGX_LOG_INFO, ev->log, ev->kq_errno, | |
4182 | 1371 "kevent() reported that client prematurely closed " |
1372 "connection"); | |
479 | 1373 |
1374 if (u->peer.connection == NULL) { | |
1375 ngx_http_upstream_finalize_request(r, u, | |
1376 NGX_HTTP_CLIENT_CLOSED_REQUEST); | |
1377 } | |
1378 | |
1379 return; | |
1380 } | |
1381 | |
1382 #endif | |
1383 | |
5373
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1384 #if (NGX_HAVE_EPOLLRDHUP) |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1385 |
6536
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6530
diff
changeset
|
1386 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
|
1387 socklen_t len; |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1388 |
6536
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6530
diff
changeset
|
1389 if (!ev->pending_eof) { |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6530
diff
changeset
|
1390 return; |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6530
diff
changeset
|
1391 } |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6530
diff
changeset
|
1392 |
5373
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1393 ev->eof = 1; |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1394 c->error = 1; |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1395 |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1396 err = 0; |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1397 len = sizeof(ngx_err_t); |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1398 |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1399 /* |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1400 * 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
|
1401 * 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
|
1402 */ |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1403 |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1404 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
|
1405 == -1) |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1406 { |
5557
188481078faf
Use ngx_socket_errno where appropriate.
Piotr Sikora <piotr@cloudflare.com>
parents:
5546
diff
changeset
|
1407 err = ngx_socket_errno; |
5373
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1408 } |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1409 |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1410 if (err) { |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1411 ev->error = 1; |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1412 } |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1413 |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1414 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
|
1415 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
|
1416 "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
|
1417 "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
|
1418 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
|
1419 NGX_HTTP_CLIENT_CLOSED_REQUEST); |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1420 return; |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1421 } |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1422 |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1423 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
|
1424 "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
|
1425 "connection"); |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1426 |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1427 if (u->peer.connection == NULL) { |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1428 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
|
1429 NGX_HTTP_CLIENT_CLOSED_REQUEST); |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1430 } |
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 return; |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1433 } |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1434 |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1435 #endif |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1436 |
479 | 1437 n = recv(c->fd, buf, 1, MSG_PEEK); |
1438 | |
1439 err = ngx_socket_errno; | |
1440 | |
1109 | 1441 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ev->log, err, |
1442 "http upstream recv(): %d", n); | |
1443 | |
479 | 1444 if (ev->write && (n >= 0 || err == NGX_EAGAIN)) { |
1445 return; | |
1446 } | |
1447 | |
1448 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
|
1449 |
6ad4bba6313e
delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents:
2805
diff
changeset
|
1450 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
|
1451 |
6ad4bba6313e
delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents:
2805
diff
changeset
|
1452 if (ngx_del_event(ev, event, 0) != NGX_OK) { |
479 | 1453 ngx_http_upstream_finalize_request(r, u, |
1454 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
1455 return; | |
1456 } | |
1457 } | |
1458 | |
1459 if (n > 0) { | |
1460 return; | |
1461 } | |
1462 | |
1463 if (n == -1) { | |
1464 if (err == NGX_EAGAIN) { | |
1465 return; | |
1466 } | |
1467 | |
1468 ev->error = 1; | |
1469 | |
483 | 1470 } else { /* n == 0 */ |
479 | 1471 err = 0; |
1472 } | |
1473 | |
529 | 1474 ev->eof = 1; |
583 | 1475 c->error = 1; |
529 | 1476 |
2757
9cc973b46af1
get a full response if the response is cacheable or storable even
Igor Sysoev <igor@sysoev.ru>
parents:
2708
diff
changeset
|
1477 if (!u->cacheable && u->peer.connection) { |
479 | 1478 ngx_log_error(NGX_LOG_INFO, ev->log, err, |
4182 | 1479 "client prematurely closed connection, " |
479 | 1480 "so upstream connection is closed too"); |
1481 ngx_http_upstream_finalize_request(r, u, | |
1482 NGX_HTTP_CLIENT_CLOSED_REQUEST); | |
1483 return; | |
1484 } | |
1485 | |
1486 ngx_log_error(NGX_LOG_INFO, ev->log, err, | |
4182 | 1487 "client prematurely closed connection"); |
479 | 1488 |
1489 if (u->peer.connection == NULL) { | |
1490 ngx_http_upstream_finalize_request(r, u, | |
1491 NGX_HTTP_CLIENT_CLOSED_REQUEST); | |
1492 } | |
1493 } | |
1494 | |
1495 | |
487 | 1496 static void |
1497 ngx_http_upstream_connect(ngx_http_request_t *r, ngx_http_upstream_t *u) | |
479 | 1498 { |
591 | 1499 ngx_int_t rc; |
1500 ngx_connection_t *c; | |
479 | 1501 |
483 | 1502 r->connection->log->action = "connecting to upstream"; |
479 | 1503 |
6146
59fc60585f1e
Upstream: times to obtain header/response are stored as ngx_msec_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6125
diff
changeset
|
1504 if (u->state && u->state->response_time) { |
59fc60585f1e
Upstream: times to obtain header/response are stored as ngx_msec_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6125
diff
changeset
|
1505 u->state->response_time = ngx_current_msec - u->state->response_time; |
665 | 1506 } |
1507 | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
1508 u->state = ngx_array_push(r->upstream_states); |
665 | 1509 if (u->state == NULL) { |
1510 ngx_http_upstream_finalize_request(r, u, | |
1511 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
1512 return; | |
1513 } | |
1514 | |
1515 ngx_memzero(u->state, sizeof(ngx_http_upstream_state_t)); | |
1516 | |
6146
59fc60585f1e
Upstream: times to obtain header/response are stored as ngx_msec_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6125
diff
changeset
|
1517 u->state->response_time = ngx_current_msec; |
6147
74b6ef56ea56
Upstream: $upstream_connect_time.
Ruslan Ermilov <ru@nginx.com>
parents:
6146
diff
changeset
|
1518 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
|
1519 u->state->header_time = (ngx_msec_t) -1; |
665 | 1520 |
479 | 1521 rc = ngx_event_connect_peer(&u->peer); |
1522 | |
1523 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
1524 "http upstream connect: %i", rc); | |
1525 | |
1526 if (rc == NGX_ERROR) { | |
1527 ngx_http_upstream_finalize_request(r, u, | |
1528 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
1529 return; | |
1530 } | |
1531 | |
1707
f3188f6eae1f
$upstream_addr did not contain last address, the bug was introduced in r1659
Igor Sysoev <igor@sysoev.ru>
parents:
1706
diff
changeset
|
1532 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
|
1533 |
543 | 1534 if (rc == NGX_BUSY) { |
1535 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "no live upstreams"); | |
1378 | 1536 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_NOLIVE); |
1537 return; | |
543 | 1538 } |
1539 | |
1378 | 1540 if (rc == NGX_DECLINED) { |
479 | 1541 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR); |
1542 return; | |
1543 } | |
1544 | |
5261
af60a210cb78
Upstream: updated list of ngx_event_connect_peer() return values.
Ruslan Ermilov <ru@nginx.com>
parents:
5231
diff
changeset
|
1545 /* rc == NGX_OK || rc == NGX_AGAIN || rc == NGX_DONE */ |
577 | 1546 |
479 | 1547 c = u->peer.connection; |
1548 | |
7340
70c6b08973a0
Upstream keepalive: keepalive_requests directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7320
diff
changeset
|
1549 c->requests++; |
70c6b08973a0
Upstream keepalive: keepalive_requests directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7320
diff
changeset
|
1550 |
479 | 1551 c->data = r; |
591 | 1552 |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1553 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
|
1554 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
|
1555 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1556 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
|
1557 u->read_event_handler = ngx_http_upstream_process_header; |
479 | 1558 |
1397
6c25a49e548a
upstream sendfile bit was overridden by r->connection->sendfile
Igor Sysoev <igor@sysoev.ru>
parents:
1378
diff
changeset
|
1559 c->sendfile &= r->connection->sendfile; |
1958 | 1560 u->output.sendfile = c->sendfile; |
479 | 1561 |
7306
8eab05b83dde
Upstream: fixed unexpected tcp_nopush usage on peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7297
diff
changeset
|
1562 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
|
1563 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
|
1564 } |
8eab05b83dde
Upstream: fixed unexpected tcp_nopush usage on peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7297
diff
changeset
|
1565 |
4116
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1566 if (c->pool == NULL) { |
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1567 |
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1568 /* 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
|
1569 |
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1570 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
|
1571 if (c->pool == NULL) { |
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1572 ngx_http_upstream_finalize_request(r, u, |
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1573 NGX_HTTP_INTERNAL_SERVER_ERROR); |
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1574 return; |
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1575 } |
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1576 } |
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1577 |
2847 | 1578 c->log = r->connection->log; |
4116
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1579 c->pool->log = c->log; |
2847 | 1580 c->read->log = c->log; |
1581 c->write->log = c->log; | |
479 | 1582 |
1583 /* init or reinit the ngx_output_chain() and ngx_chain_writer() contexts */ | |
1584 | |
1585 u->writer.out = NULL; | |
1586 u->writer.last = &u->writer.out; | |
1587 u->writer.connection = c; | |
1588 u->writer.limit = 0; | |
1589 | |
1590 if (u->request_sent) { | |
509 | 1591 if (ngx_http_upstream_reinit(r, u) != NGX_OK) { |
1592 ngx_http_upstream_finalize_request(r, u, | |
1593 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
1594 return; | |
1595 } | |
479 | 1596 } |
1597 | |
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
|
1598 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
|
1599 && 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
|
1600 && 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
|
1601 && 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
|
1602 { |
573 | 1603 /* |
1604 * 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
|
1605 * the subrequests should allocate their own temporary bufs |
573 | 1606 */ |
1607 | |
1608 u->output.free = ngx_alloc_chain_link(r->pool); | |
1609 if (u->output.free == NULL) { | |
1610 ngx_http_upstream_finalize_request(r, u, | |
1611 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
1612 return; | |
479 | 1613 } |
573 | 1614 |
1615 u->output.free->buf = r->request_body->buf; | |
1616 u->output.free->next = NULL; | |
1617 u->output.allocated = 1; | |
1618 | |
1619 r->request_body->buf->pos = r->request_body->buf->start; | |
1620 r->request_body->buf->last = r->request_body->buf->start; | |
1621 r->request_body->buf->tag = u->output.tag; | |
479 | 1622 } |
1623 | |
1624 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
|
1625 u->request_body_sent = 0; |
7231
22f7bdbd96d3
Upstream: u->request_body_blocked flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7230
diff
changeset
|
1626 u->request_body_blocked = 0; |
479 | 1627 |
1628 if (rc == NGX_AGAIN) { | |
1629 ngx_add_timer(c->write, u->conf->connect_timeout); | |
1630 return; | |
1631 } | |
1632 | |
577 | 1633 #if (NGX_HTTP_SSL) |
1634 | |
1658 | 1635 if (u->ssl && c->ssl == NULL) { |
591 | 1636 ngx_http_upstream_ssl_init_connection(r, u, c); |
577 | 1637 return; |
1638 } | |
1639 | |
1640 #endif | |
1641 | |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1642 ngx_http_upstream_send_request(r, u, 1); |
479 | 1643 } |
1644 | |
1645 | |
577 | 1646 #if (NGX_HTTP_SSL) |
1647 | |
1648 static void | |
591 | 1649 ngx_http_upstream_ssl_init_connection(ngx_http_request_t *r, |
1650 ngx_http_upstream_t *u, ngx_connection_t *c) | |
1651 { | |
6068
643f2ce02f1c
Upstream: abbreviated SSL handshake may interact badly with Nagle.
Ruslan Ermilov <ru@nginx.com>
parents:
6050
diff
changeset
|
1652 ngx_int_t rc; |
643f2ce02f1c
Upstream: abbreviated SSL handshake may interact badly with Nagle.
Ruslan Ermilov <ru@nginx.com>
parents:
6050
diff
changeset
|
1653 ngx_http_core_loc_conf_t *clcf; |
591 | 1654 |
5305
12b750d35162
Upstream: reliably detect connection failures with SSL peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5304
diff
changeset
|
1655 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
|
1656 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
|
1657 return; |
12b750d35162
Upstream: reliably detect connection failures with SSL peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5304
diff
changeset
|
1658 } |
12b750d35162
Upstream: reliably detect connection failures with SSL peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5304
diff
changeset
|
1659 |
591 | 1660 if (ngx_ssl_create_connection(u->conf->ssl, c, |
1661 NGX_SSL_BUFFER|NGX_SSL_CLIENT) | |
2536
a6d6d762c554
small optimization: " == NGX_ERROR" > " != NGX_OK"
Igor Sysoev <igor@sysoev.ru>
parents:
2463
diff
changeset
|
1662 != NGX_OK) |
591 | 1663 { |
1664 ngx_http_upstream_finalize_request(r, u, | |
1665 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
1666 return; | |
1667 } | |
1668 | |
1669 c->sendfile = 0; | |
619 | 1670 u->output.sendfile = 0; |
591 | 1671 |
5661
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1672 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
|
1673 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
|
1674 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
|
1675 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
|
1676 return; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1677 } |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1678 } |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1679 |
2184 | 1680 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
|
1681 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
|
1682 |
2184 | 1683 if (u->peer.set_session(&u->peer, u->peer.data) != NGX_OK) { |
1684 ngx_http_upstream_finalize_request(r, u, | |
1685 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
1686 return; | |
1687 } | |
6068
643f2ce02f1c
Upstream: abbreviated SSL handshake may interact badly with Nagle.
Ruslan Ermilov <ru@nginx.com>
parents:
6050
diff
changeset
|
1688 |
643f2ce02f1c
Upstream: abbreviated SSL handshake may interact badly with Nagle.
Ruslan Ermilov <ru@nginx.com>
parents:
6050
diff
changeset
|
1689 /* 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
|
1690 |
643f2ce02f1c
Upstream: abbreviated SSL handshake may interact badly with Nagle.
Ruslan Ermilov <ru@nginx.com>
parents:
6050
diff
changeset
|
1691 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
|
1692 |
7007
ed1101bbf19f
Introduced ngx_tcp_nodelay().
Ruslan Ermilov <ru@nginx.com>
parents:
7006
diff
changeset
|
1693 if (clcf->tcp_nodelay && ngx_tcp_nodelay(c) != NGX_OK) { |
ed1101bbf19f
Introduced ngx_tcp_nodelay().
Ruslan Ermilov <ru@nginx.com>
parents:
7006
diff
changeset
|
1694 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
|
1695 NGX_HTTP_INTERNAL_SERVER_ERROR); |
7007
ed1101bbf19f
Introduced ngx_tcp_nodelay().
Ruslan Ermilov <ru@nginx.com>
parents:
7006
diff
changeset
|
1696 return; |
6068
643f2ce02f1c
Upstream: abbreviated SSL handshake may interact badly with Nagle.
Ruslan Ermilov <ru@nginx.com>
parents:
6050
diff
changeset
|
1697 } |
591 | 1698 } |
1699 | |
641 | 1700 r->connection->log->action = "SSL handshaking to upstream"; |
1701 | |
591 | 1702 rc = ngx_ssl_handshake(c); |
1703 | |
1704 if (rc == NGX_AGAIN) { | |
5774
9bf58a3da25b
Upstream: SSL handshake timeouts.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5770
diff
changeset
|
1705 |
9bf58a3da25b
Upstream: SSL handshake timeouts.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5770
diff
changeset
|
1706 if (!c->write->timer_set) { |
9bf58a3da25b
Upstream: SSL handshake timeouts.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5770
diff
changeset
|
1707 ngx_add_timer(c->write, u->conf->connect_timeout); |
9bf58a3da25b
Upstream: SSL handshake timeouts.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5770
diff
changeset
|
1708 } |
9bf58a3da25b
Upstream: SSL handshake timeouts.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5770
diff
changeset
|
1709 |
7042
bd2f97a3aecc
Upstream: introduced ngx_http_upstream_ssl_handshake_handler().
Maxim Dounin <mdounin@mdounin.ru>
parents:
7041
diff
changeset
|
1710 c->ssl->handler = ngx_http_upstream_ssl_handshake_handler; |
591 | 1711 return; |
1712 } | |
1713 | |
7042
bd2f97a3aecc
Upstream: introduced ngx_http_upstream_ssl_handshake_handler().
Maxim Dounin <mdounin@mdounin.ru>
parents:
7041
diff
changeset
|
1714 ngx_http_upstream_ssl_handshake(r, u, c); |
591 | 1715 } |
1716 | |
1717 | |
1718 static void | |
7042
bd2f97a3aecc
Upstream: introduced ngx_http_upstream_ssl_handshake_handler().
Maxim Dounin <mdounin@mdounin.ru>
parents:
7041
diff
changeset
|
1719 ngx_http_upstream_ssl_handshake_handler(ngx_connection_t *c) |
577 | 1720 { |
1721 ngx_http_request_t *r; | |
1722 ngx_http_upstream_t *u; | |
1723 | |
1724 r = c->data; | |
7042
bd2f97a3aecc
Upstream: introduced ngx_http_upstream_ssl_handshake_handler().
Maxim Dounin <mdounin@mdounin.ru>
parents:
7041
diff
changeset
|
1725 |
577 | 1726 u = r->upstream; |
7042
bd2f97a3aecc
Upstream: introduced ngx_http_upstream_ssl_handshake_handler().
Maxim Dounin <mdounin@mdounin.ru>
parents:
7041
diff
changeset
|
1727 c = r->connection; |
577 | 1728 |
5928
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5911
diff
changeset
|
1729 ngx_http_set_log_request(c->log, r); |
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5911
diff
changeset
|
1730 |
7042
bd2f97a3aecc
Upstream: introduced ngx_http_upstream_ssl_handshake_handler().
Maxim Dounin <mdounin@mdounin.ru>
parents:
7041
diff
changeset
|
1731 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
|
1732 "http upstream ssl handshake: \"%V?%V\"", |
bd2f97a3aecc
Upstream: introduced ngx_http_upstream_ssl_handshake_handler().
Maxim Dounin <mdounin@mdounin.ru>
parents:
7041
diff
changeset
|
1733 &r->uri, &r->args); |
bd2f97a3aecc
Upstream: introduced ngx_http_upstream_ssl_handshake_handler().
Maxim Dounin <mdounin@mdounin.ru>
parents:
7041
diff
changeset
|
1734 |
bd2f97a3aecc
Upstream: introduced ngx_http_upstream_ssl_handshake_handler().
Maxim Dounin <mdounin@mdounin.ru>
parents:
7041
diff
changeset
|
1735 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
|
1736 |
bd2f97a3aecc
Upstream: introduced ngx_http_upstream_ssl_handshake_handler().
Maxim Dounin <mdounin@mdounin.ru>
parents:
7041
diff
changeset
|
1737 ngx_http_run_posted_requests(c); |
bd2f97a3aecc
Upstream: introduced ngx_http_upstream_ssl_handshake_handler().
Maxim Dounin <mdounin@mdounin.ru>
parents:
7041
diff
changeset
|
1738 } |
bd2f97a3aecc
Upstream: introduced ngx_http_upstream_ssl_handshake_handler().
Maxim Dounin <mdounin@mdounin.ru>
parents:
7041
diff
changeset
|
1739 |
bd2f97a3aecc
Upstream: introduced ngx_http_upstream_ssl_handshake_handler().
Maxim Dounin <mdounin@mdounin.ru>
parents:
7041
diff
changeset
|
1740 |
bd2f97a3aecc
Upstream: introduced ngx_http_upstream_ssl_handshake_handler().
Maxim Dounin <mdounin@mdounin.ru>
parents:
7041
diff
changeset
|
1741 static void |
bd2f97a3aecc
Upstream: introduced ngx_http_upstream_ssl_handshake_handler().
Maxim Dounin <mdounin@mdounin.ru>
parents:
7041
diff
changeset
|
1742 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
|
1743 ngx_connection_t *c) |
bd2f97a3aecc
Upstream: introduced ngx_http_upstream_ssl_handshake_handler().
Maxim Dounin <mdounin@mdounin.ru>
parents:
7041
diff
changeset
|
1744 { |
bd2f97a3aecc
Upstream: introduced ngx_http_upstream_ssl_handshake_handler().
Maxim Dounin <mdounin@mdounin.ru>
parents:
7041
diff
changeset
|
1745 long rc; |
bd2f97a3aecc
Upstream: introduced ngx_http_upstream_ssl_handshake_handler().
Maxim Dounin <mdounin@mdounin.ru>
parents:
7041
diff
changeset
|
1746 |
577 | 1747 if (c->ssl->handshaked) { |
1748 | |
5661
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1749 if (u->conf->ssl_verify) { |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1750 rc = SSL_get_verify_result(c->ssl->connection); |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1751 |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1752 if (rc != X509_V_OK) { |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1753 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
|
1754 "upstream SSL certificate verify error: (%l:%s)", |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1755 rc, X509_verify_cert_error_string(rc)); |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1756 goto failed; |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1757 } |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1758 |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1759 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
|
1760 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
|
1761 "upstream SSL certificate does not match \"%V\"", |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1762 &u->ssl_name); |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1763 goto failed; |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1764 } |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1765 } |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1766 |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1767 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
|
1768 c->read->handler = ngx_http_upstream_handler; |
577 | 1769 |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1770 ngx_http_upstream_send_request(r, u, 1); |
577 | 1771 |
1772 return; | |
1773 } | |
1774 | |
6799
d8d037f20484
Upstream: handling of upstream SSL handshake timeouts.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6795
diff
changeset
|
1775 if (c->write->timedout) { |
d8d037f20484
Upstream: handling of upstream SSL handshake timeouts.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6795
diff
changeset
|
1776 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
|
1777 return; |
d8d037f20484
Upstream: handling of upstream SSL handshake timeouts.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6795
diff
changeset
|
1778 } |
d8d037f20484
Upstream: handling of upstream SSL handshake timeouts.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6795
diff
changeset
|
1779 |
5661
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1780 failed: |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1781 |
577 | 1782 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR); |
1783 } | |
1784 | |
5660
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1785 |
7320
696df3ac27ac
SSL: save sessions for upstream peers using a callback function.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7307
diff
changeset
|
1786 static void |
696df3ac27ac
SSL: save sessions for upstream peers using a callback function.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7307
diff
changeset
|
1787 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
|
1788 { |
696df3ac27ac
SSL: save sessions for upstream peers using a callback function.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7307
diff
changeset
|
1789 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
|
1790 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
|
1791 |
696df3ac27ac
SSL: save sessions for upstream peers using a callback function.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7307
diff
changeset
|
1792 if (c->idle) { |
696df3ac27ac
SSL: save sessions for upstream peers using a callback function.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7307
diff
changeset
|
1793 return; |
696df3ac27ac
SSL: save sessions for upstream peers using a callback function.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7307
diff
changeset
|
1794 } |
696df3ac27ac
SSL: save sessions for upstream peers using a callback function.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7307
diff
changeset
|
1795 |
696df3ac27ac
SSL: save sessions for upstream peers using a callback function.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7307
diff
changeset
|
1796 r = c->data; |
696df3ac27ac
SSL: save sessions for upstream peers using a callback function.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7307
diff
changeset
|
1797 |
696df3ac27ac
SSL: save sessions for upstream peers using a callback function.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7307
diff
changeset
|
1798 u = r->upstream; |
696df3ac27ac
SSL: save sessions for upstream peers using a callback function.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7307
diff
changeset
|
1799 c = r->connection; |
696df3ac27ac
SSL: save sessions for upstream peers using a callback function.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7307
diff
changeset
|
1800 |
696df3ac27ac
SSL: save sessions for upstream peers using a callback function.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7307
diff
changeset
|
1801 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
|
1802 |
696df3ac27ac
SSL: save sessions for upstream peers using a callback function.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7307
diff
changeset
|
1803 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
|
1804 } |
696df3ac27ac
SSL: save sessions for upstream peers using a callback function.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7307
diff
changeset
|
1805 |
696df3ac27ac
SSL: save sessions for upstream peers using a callback function.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7307
diff
changeset
|
1806 |
5660
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1807 static ngx_int_t |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1808 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
|
1809 ngx_connection_t *c) |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1810 { |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1811 u_char *p, *last; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1812 ngx_str_t name; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1813 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1814 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
|
1815 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
|
1816 return NGX_ERROR; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1817 } |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1818 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1819 } else { |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1820 name = u->ssl_name; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1821 } |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1822 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1823 if (name.len == 0) { |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1824 goto done; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1825 } |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1826 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1827 /* |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1828 * 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
|
1829 * 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
|
1830 */ |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1831 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1832 p = name.data; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1833 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
|
1834 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1835 if (*p == '[') { |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1836 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
|
1837 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1838 if (p == NULL) { |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1839 p = name.data; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1840 } |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1841 } |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1842 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1843 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
|
1844 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1845 if (p != NULL) { |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1846 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
|
1847 } |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1848 |
5661
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1849 if (!u->conf->ssl_server_name) { |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1850 goto done; |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1851 } |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1852 |
5660
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1853 #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
|
1854 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1855 /* 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
|
1856 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1857 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
|
1858 goto done; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1859 } |
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 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
|
1862 goto done; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1863 } |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1864 |
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 * 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
|
1867 * 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
|
1868 */ |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1869 |
5667
16405e02e612
Upstream: for ssl name, non-aligned memory allocation is enough.
Ruslan Ermilov <ru@nginx.com>
parents:
5661
diff
changeset
|
1870 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
|
1871 if (p == NULL) { |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1872 return NGX_ERROR; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1873 } |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1874 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1875 (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
|
1876 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1877 name.data = p; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1878 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1879 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
|
1880 "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
|
1881 |
6777
563a1ee345a4
SSL: compatibility with BoringSSL.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6745
diff
changeset
|
1882 if (SSL_set_tlsext_host_name(c->ssl->connection, |
563a1ee345a4
SSL: compatibility with BoringSSL.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6745
diff
changeset
|
1883 (char *) name.data) |
563a1ee345a4
SSL: compatibility with BoringSSL.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6745
diff
changeset
|
1884 == 0) |
563a1ee345a4
SSL: compatibility with BoringSSL.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6745
diff
changeset
|
1885 { |
5660
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1886 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
|
1887 "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
|
1888 return NGX_ERROR; |
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 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1891 #endif |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1892 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1893 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 u->ssl_name = name; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1896 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1897 return NGX_OK; |
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 |
577 | 1900 #endif |
1901 | |
1902 | |
509 | 1903 static ngx_int_t |
487 | 1904 ngx_http_upstream_reinit(ngx_http_request_t *r, ngx_http_upstream_t *u) |
479 | 1905 { |
5848
106a8bfa4f42
Upstream: fixed file buffers reinit in ngx_http_upstream_reinit().
Roman Arutyunyan <arut@nginx.com>
parents:
5832
diff
changeset
|
1906 off_t file_pos; |
479 | 1907 ngx_chain_t *cl; |
1908 | |
509 | 1909 if (u->reinit_request(r) != NGX_OK) { |
1910 return NGX_ERROR; | |
1911 } | |
1912 | |
4120
42135dd1f0ea
Upstream: keepalive flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4119
diff
changeset
|
1913 u->keepalive = 0; |
5072
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
1914 u->upgrade = 0; |
4120
42135dd1f0ea
Upstream: keepalive flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4119
diff
changeset
|
1915 |
1705 | 1916 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
|
1917 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
|
1918 u->headers_in.last_modified_time = -1; |
1705 | 1919 |
1920 if (ngx_list_init(&u->headers_in.headers, r->pool, 8, | |
591 | 1921 sizeof(ngx_table_elt_t)) |
1922 != NGX_OK) | |
509 | 1923 { |
1924 return NGX_ERROR; | |
479 | 1925 } |
1926 | |
7230
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
1927 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
|
1928 sizeof(ngx_table_elt_t)) |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
1929 != NGX_OK) |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
1930 { |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
1931 return NGX_ERROR; |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
1932 } |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
1933 |
479 | 1934 /* reinit the request chain */ |
577 | 1935 |
5848
106a8bfa4f42
Upstream: fixed file buffers reinit in ngx_http_upstream_reinit().
Roman Arutyunyan <arut@nginx.com>
parents:
5832
diff
changeset
|
1936 file_pos = 0; |
106a8bfa4f42
Upstream: fixed file buffers reinit in ngx_http_upstream_reinit().
Roman Arutyunyan <arut@nginx.com>
parents:
5832
diff
changeset
|
1937 |
509 | 1938 for (cl = u->request_bufs; cl; cl = cl->next) { |
479 | 1939 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
|
1940 |
106a8bfa4f42
Upstream: fixed file buffers reinit in ngx_http_upstream_reinit().
Roman Arutyunyan <arut@nginx.com>
parents:
5832
diff
changeset
|
1941 /* 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
|
1942 |
106a8bfa4f42
Upstream: fixed file buffers reinit in ngx_http_upstream_reinit().
Roman Arutyunyan <arut@nginx.com>
parents:
5832
diff
changeset
|
1943 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
|
1944 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
|
1945 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
|
1946 } |
479 | 1947 } |
1948 | |
509 | 1949 /* reinit the subrequest's ngx_output_chain() context */ |
1950 | |
573 | 1951 if (r->request_body && r->request_body->temp_file |
597 | 1952 && r != r->main && u->output.buf) |
573 | 1953 { |
1954 u->output.free = ngx_alloc_chain_link(r->pool); | |
1955 if (u->output.free == NULL) { | |
1956 return NGX_ERROR; | |
509 | 1957 } |
573 | 1958 |
1959 u->output.free->buf = u->output.buf; | |
1960 u->output.free->next = NULL; | |
1961 | |
1962 u->output.buf->pos = u->output.buf->start; | |
1963 u->output.buf->last = u->output.buf->start; | |
509 | 1964 } |
479 | 1965 |
1966 u->output.buf = NULL; | |
1967 u->output.in = NULL; | |
1968 u->output.busy = NULL; | |
577 | 1969 |
581 | 1970 /* reinit u->buffer */ |
577 | 1971 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1972 u->buffer.pos = u->buffer.start; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1973 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1974 #if (NGX_HTTP_CACHE) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1975 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1976 if (r->cache) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1977 u->buffer.pos += r->cache->header_start; |
479 | 1978 } |
509 | 1979 |
479 | 1980 #endif |
1981 | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1982 u->buffer.last = u->buffer.pos; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1983 |
509 | 1984 return NGX_OK; |
479 | 1985 } |
1986 | |
1987 | |
487 | 1988 static void |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1989 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
|
1990 ngx_uint_t do_write) |
479 | 1991 { |
1153
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
1992 ngx_int_t rc; |
483 | 1993 ngx_connection_t *c; |
577 | 1994 |
479 | 1995 c = u->peer.connection; |
1996 | |
1997 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
1998 "http upstream send request"); | |
1999 | |
6147
74b6ef56ea56
Upstream: $upstream_connect_time.
Ruslan Ermilov <ru@nginx.com>
parents:
6146
diff
changeset
|
2000 if (u->state->connect_time == (ngx_msec_t) -1) { |
74b6ef56ea56
Upstream: $upstream_connect_time.
Ruslan Ermilov <ru@nginx.com>
parents:
6146
diff
changeset
|
2001 u->state->connect_time = ngx_current_msec - u->state->response_time; |
74b6ef56ea56
Upstream: $upstream_connect_time.
Ruslan Ermilov <ru@nginx.com>
parents:
6146
diff
changeset
|
2002 } |
74b6ef56ea56
Upstream: $upstream_connect_time.
Ruslan Ermilov <ru@nginx.com>
parents:
6146
diff
changeset
|
2003 |
1153
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2004 if (!u->request_sent && ngx_http_upstream_test_connect(c) != NGX_OK) { |
1166 | 2005 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
|
2006 return; |
479 | 2007 } |
2008 | |
483 | 2009 c->log->action = "sending request to upstream"; |
479 | 2010 |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2011 rc = ngx_http_upstream_send_request_body(r, u, do_write); |
479 | 2012 |
2013 if (rc == NGX_ERROR) { | |
2014 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR); | |
2015 return; | |
2016 } | |
2017 | |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2018 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2019 ngx_http_upstream_finalize_request(r, u, rc); |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2020 return; |
479 | 2021 } |
2022 | |
2023 if (rc == NGX_AGAIN) { | |
7231
22f7bdbd96d3
Upstream: u->request_body_blocked flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7230
diff
changeset
|
2024 if (!c->write->ready || u->request_body_blocked) { |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2025 ngx_add_timer(c->write, u->conf->send_timeout); |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2026 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2027 } else if (c->write->timer_set) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2028 ngx_del_timer(c->write); |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2029 } |
479 | 2030 |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2031 if (ngx_handle_write_event(c->write, u->conf->send_lowat) != NGX_OK) { |
479 | 2032 ngx_http_upstream_finalize_request(r, u, |
2033 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
2034 return; | |
2035 } | |
2036 | |
7307
ece9b5454b8a
Upstream: fixed tcp_nopush with gRPC.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7306
diff
changeset
|
2037 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
|
2038 if (ngx_tcp_push(c->fd) == -1) { |
ece9b5454b8a
Upstream: fixed tcp_nopush with gRPC.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7306
diff
changeset
|
2039 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
|
2040 ngx_tcp_push_n " failed"); |
ece9b5454b8a
Upstream: fixed tcp_nopush with gRPC.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7306
diff
changeset
|
2041 ngx_http_upstream_finalize_request(r, u, |
ece9b5454b8a
Upstream: fixed tcp_nopush with gRPC.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7306
diff
changeset
|
2042 NGX_HTTP_INTERNAL_SERVER_ERROR); |
ece9b5454b8a
Upstream: fixed tcp_nopush with gRPC.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7306
diff
changeset
|
2043 return; |
ece9b5454b8a
Upstream: fixed tcp_nopush with gRPC.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7306
diff
changeset
|
2044 } |
ece9b5454b8a
Upstream: fixed tcp_nopush with gRPC.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7306
diff
changeset
|
2045 |
ece9b5454b8a
Upstream: fixed tcp_nopush with gRPC.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7306
diff
changeset
|
2046 c->tcp_nopush = NGX_TCP_NOPUSH_UNSET; |
ece9b5454b8a
Upstream: fixed tcp_nopush with gRPC.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7306
diff
changeset
|
2047 } |
ece9b5454b8a
Upstream: fixed tcp_nopush with gRPC.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7306
diff
changeset
|
2048 |
479 | 2049 return; |
2050 } | |
2051 | |
2052 /* rc == NGX_OK */ | |
2053 | |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2054 if (c->write->timer_set) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2055 ngx_del_timer(c->write); |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2056 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2057 |
479 | 2058 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
|
2059 if (ngx_tcp_push(c->fd) == -1) { |
479 | 2060 ngx_log_error(NGX_LOG_CRIT, c->log, ngx_socket_errno, |
2061 ngx_tcp_push_n " failed"); | |
2062 ngx_http_upstream_finalize_request(r, u, | |
2063 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
577 | 2064 return; |
479 | 2065 } |
2066 | |
2067 c->tcp_nopush = NGX_TCP_NOPUSH_UNSET; | |
2068 } | |
577 | 2069 |
7232
a7ed15573ae9
Upstream: u->conf->preserve_output flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7231
diff
changeset
|
2070 if (!u->conf->preserve_output) { |
a7ed15573ae9
Upstream: u->conf->preserve_output flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7231
diff
changeset
|
2071 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
|
2072 } |
479 | 2073 |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2074 if (ngx_handle_write_event(c->write, 0) != NGX_OK) { |
479 | 2075 ngx_http_upstream_finalize_request(r, u, |
2076 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
2077 return; | |
2078 } | |
5745
9d3a9c45fc43
Upstream: fixed handling of write event after sending request.
Valentin Bartenev <vbart@nginx.com>
parents:
5738
diff
changeset
|
2079 |
7260
08f114ed5449
Upstream: fixed u->conf->preserve_output (ticket #1519).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7255
diff
changeset
|
2080 if (!u->request_body_sent) { |
08f114ed5449
Upstream: fixed u->conf->preserve_output (ticket #1519).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7255
diff
changeset
|
2081 u->request_body_sent = 1; |
08f114ed5449
Upstream: fixed u->conf->preserve_output (ticket #1519).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7255
diff
changeset
|
2082 |
08f114ed5449
Upstream: fixed u->conf->preserve_output (ticket #1519).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7255
diff
changeset
|
2083 if (u->header_sent) { |
08f114ed5449
Upstream: fixed u->conf->preserve_output (ticket #1519).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7255
diff
changeset
|
2084 return; |
08f114ed5449
Upstream: fixed u->conf->preserve_output (ticket #1519).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7255
diff
changeset
|
2085 } |
08f114ed5449
Upstream: fixed u->conf->preserve_output (ticket #1519).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7255
diff
changeset
|
2086 |
08f114ed5449
Upstream: fixed u->conf->preserve_output (ticket #1519).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7255
diff
changeset
|
2087 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
|
2088 |
08f114ed5449
Upstream: fixed u->conf->preserve_output (ticket #1519).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7255
diff
changeset
|
2089 if (c->read->ready) { |
08f114ed5449
Upstream: fixed u->conf->preserve_output (ticket #1519).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7255
diff
changeset
|
2090 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
|
2091 return; |
08f114ed5449
Upstream: fixed u->conf->preserve_output (ticket #1519).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7255
diff
changeset
|
2092 } |
5745
9d3a9c45fc43
Upstream: fixed handling of write event after sending request.
Valentin Bartenev <vbart@nginx.com>
parents:
5738
diff
changeset
|
2093 } |
479 | 2094 } |
2095 | |
2096 | |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2097 static ngx_int_t |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2098 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
|
2099 ngx_http_upstream_t *u, ngx_uint_t do_write) |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2100 { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2101 ngx_int_t rc; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2102 ngx_chain_t *out, *cl, *ln; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2103 ngx_connection_t *c; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2104 ngx_http_core_loc_conf_t *clcf; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2105 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2106 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
|
2107 "http upstream send request body"); |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2108 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2109 if (!r->request_body_no_buffering) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2110 |
6474 | 2111 /* buffered request body */ |
2112 | |
2113 if (!u->request_sent) { | |
2114 u->request_sent = 1; | |
2115 out = u->request_bufs; | |
2116 | |
2117 } else { | |
2118 out = NULL; | |
2119 } | |
2120 | |
7231
22f7bdbd96d3
Upstream: u->request_body_blocked flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7230
diff
changeset
|
2121 rc = ngx_output_chain(&u->output, out); |
22f7bdbd96d3
Upstream: u->request_body_blocked flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7230
diff
changeset
|
2122 |
22f7bdbd96d3
Upstream: u->request_body_blocked flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7230
diff
changeset
|
2123 if (rc == NGX_AGAIN) { |
22f7bdbd96d3
Upstream: u->request_body_blocked flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7230
diff
changeset
|
2124 u->request_body_blocked = 1; |
22f7bdbd96d3
Upstream: u->request_body_blocked flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7230
diff
changeset
|
2125 |
22f7bdbd96d3
Upstream: u->request_body_blocked flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7230
diff
changeset
|
2126 } else { |
22f7bdbd96d3
Upstream: u->request_body_blocked flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7230
diff
changeset
|
2127 u->request_body_blocked = 0; |
22f7bdbd96d3
Upstream: u->request_body_blocked flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7230
diff
changeset
|
2128 } |
22f7bdbd96d3
Upstream: u->request_body_blocked flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7230
diff
changeset
|
2129 |
22f7bdbd96d3
Upstream: u->request_body_blocked flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7230
diff
changeset
|
2130 return rc; |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2131 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2132 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2133 if (!u->request_sent) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2134 u->request_sent = 1; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2135 out = u->request_bufs; |
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 if (r->request_body->bufs) { |
7341
15ea84e65d07
Upstream: fixed request chain traversal (ticket #1618).
Vladimir Homutov <vl@nginx.com>
parents:
7340
diff
changeset
|
2138 for (cl = out; cl->next; cl = cl->next) { /* void */ } |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2139 cl->next = r->request_body->bufs; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2140 r->request_body->bufs = NULL; |
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 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2143 c = u->peer.connection; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2144 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
|
2145 |
7007
ed1101bbf19f
Introduced ngx_tcp_nodelay().
Ruslan Ermilov <ru@nginx.com>
parents:
7006
diff
changeset
|
2146 if (clcf->tcp_nodelay && ngx_tcp_nodelay(c) != NGX_OK) { |
ed1101bbf19f
Introduced ngx_tcp_nodelay().
Ruslan Ermilov <ru@nginx.com>
parents:
7006
diff
changeset
|
2147 return NGX_ERROR; |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2148 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2149 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2150 r->read_event_handler = ngx_http_upstream_read_request_handler; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2151 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2152 } else { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2153 out = NULL; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2154 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2155 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2156 for ( ;; ) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2157 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2158 if (do_write) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2159 rc = ngx_output_chain(&u->output, out); |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2160 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2161 if (rc == NGX_ERROR) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2162 return NGX_ERROR; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2163 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2164 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2165 while (out) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2166 ln = out; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2167 out = out->next; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2168 ngx_free_chain(r->pool, ln); |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2169 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2170 |
7231
22f7bdbd96d3
Upstream: u->request_body_blocked flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7230
diff
changeset
|
2171 if (rc == NGX_AGAIN) { |
22f7bdbd96d3
Upstream: u->request_body_blocked flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7230
diff
changeset
|
2172 u->request_body_blocked = 1; |
22f7bdbd96d3
Upstream: u->request_body_blocked flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7230
diff
changeset
|
2173 |
22f7bdbd96d3
Upstream: u->request_body_blocked flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7230
diff
changeset
|
2174 } else { |
22f7bdbd96d3
Upstream: u->request_body_blocked flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7230
diff
changeset
|
2175 u->request_body_blocked = 0; |
22f7bdbd96d3
Upstream: u->request_body_blocked flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7230
diff
changeset
|
2176 } |
22f7bdbd96d3
Upstream: u->request_body_blocked flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7230
diff
changeset
|
2177 |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2178 if (rc == NGX_OK && !r->reading_body) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2179 break; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2180 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2181 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2182 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2183 if (r->reading_body) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2184 /* read client request body */ |
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 rc = ngx_http_read_unbuffered_request_body(r); |
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 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2189 return rc; |
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 out = r->request_body->bufs; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2193 r->request_body->bufs = NULL; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2194 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2195 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2196 /* stop if there is nothing to send */ |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2197 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2198 if (out == NULL) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2199 rc = NGX_AGAIN; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2200 break; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2201 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2202 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2203 do_write = 1; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2204 } |
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 if (!r->reading_body) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2207 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
|
2208 r->read_event_handler = |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2209 ngx_http_upstream_rd_check_broken_connection; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2210 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2211 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2212 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2213 return rc; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2214 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2215 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2216 |
487 | 2217 static void |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2218 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
|
2219 ngx_http_upstream_t *u) |
479 | 2220 { |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2221 ngx_connection_t *c; |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2222 |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2223 c = u->peer.connection; |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2224 |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2225 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
479 | 2226 "http upstream send request handler"); |
2227 | |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2228 if (c->write->timedout) { |
479 | 2229 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_TIMEOUT); |
2230 return; | |
2231 } | |
2232 | |
591 | 2233 #if (NGX_HTTP_SSL) |
2234 | |
1658 | 2235 if (u->ssl && c->ssl == NULL) { |
591 | 2236 ngx_http_upstream_ssl_init_connection(r, u, c); |
2237 return; | |
2238 } | |
2239 | |
2240 #endif | |
2241 | |
7232
a7ed15573ae9
Upstream: u->conf->preserve_output flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7231
diff
changeset
|
2242 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
|
2243 u->write_event_handler = ngx_http_upstream_dummy_handler; |
651 | 2244 |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2245 (void) ngx_handle_write_event(c->write, 0); |
651 | 2246 |
2247 return; | |
2248 } | |
2249 | |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2250 ngx_http_upstream_send_request(r, u, 1); |
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 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2253 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2254 static void |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2255 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
|
2256 { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2257 ngx_connection_t *c; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2258 ngx_http_upstream_t *u; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2259 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2260 c = r->connection; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2261 u = r->upstream; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2262 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2263 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
|
2264 "http upstream read request handler"); |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2265 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2266 if (c->read->timedout) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2267 c->timedout = 1; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2268 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
|
2269 return; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2270 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2271 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2272 ngx_http_upstream_send_request(r, u, 0); |
479 | 2273 } |
2274 | |
2275 | |
487 | 2276 static void |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2277 ngx_http_upstream_process_header(ngx_http_request_t *r, ngx_http_upstream_t *u) |
479 | 2278 { |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2279 ssize_t n; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2280 ngx_int_t rc; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2281 ngx_connection_t *c; |
479 | 2282 |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2283 c = u->peer.connection; |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2284 |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2285 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, |
483 | 2286 "http upstream process header"); |
479 | 2287 |
483 | 2288 c->log->action = "reading response header from upstream"; |
479 | 2289 |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2290 if (c->read->timedout) { |
479 | 2291 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_TIMEOUT); |
2292 return; | |
2293 } | |
577 | 2294 |
1153
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2295 if (!u->request_sent && ngx_http_upstream_test_connect(c) != NGX_OK) { |
1166 | 2296 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
|
2297 return; |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2298 } |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2299 |
581 | 2300 if (u->buffer.start == NULL) { |
2301 u->buffer.start = ngx_palloc(r->pool, u->conf->buffer_size); | |
2302 if (u->buffer.start == NULL) { | |
479 | 2303 ngx_http_upstream_finalize_request(r, u, |
2304 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
2305 return; | |
2306 } | |
2307 | |
581 | 2308 u->buffer.pos = u->buffer.start; |
2309 u->buffer.last = u->buffer.start; | |
2310 u->buffer.end = u->buffer.start + u->conf->buffer_size; | |
2311 u->buffer.temporary = 1; | |
2312 | |
2313 u->buffer.tag = u->output.tag; | |
479 | 2314 |
1705 | 2315 if (ngx_list_init(&u->headers_in.headers, r->pool, 8, |
581 | 2316 sizeof(ngx_table_elt_t)) |
2317 != NGX_OK) | |
509 | 2318 { |
2319 ngx_http_upstream_finalize_request(r, u, | |
2320 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
2321 return; | |
2322 } | |
2323 | |
7230
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2324 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
|
2325 sizeof(ngx_table_elt_t)) |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2326 != NGX_OK) |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2327 { |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2328 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
|
2329 NGX_HTTP_INTERNAL_SERVER_ERROR); |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2330 return; |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2331 } |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2332 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2333 #if (NGX_HTTP_CACHE) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2334 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2335 if (r->cache) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2336 u->buffer.pos += r->cache->header_start; |
581 | 2337 u->buffer.last = u->buffer.pos; |
479 | 2338 } |
2339 #endif | |
2340 } | |
2341 | |
2360
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2342 for ( ;; ) { |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2343 |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2344 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
|
2345 |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2346 if (n == NGX_AGAIN) { |
479 | 2347 #if 0 |
2360
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2348 ngx_add_timer(rev, u->read_timeout); |
479 | 2349 #endif |
2350 | |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2351 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
|
2352 ngx_http_upstream_finalize_request(r, u, |
479 | 2353 NGX_HTTP_INTERNAL_SERVER_ERROR); |
2360
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2354 return; |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2355 } |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2356 |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2357 return; |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2358 } |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2359 |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2360 if (n == 0) { |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2361 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
|
2362 "upstream prematurely closed connection"); |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2363 } |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2364 |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2365 if (n == NGX_ERROR || n == 0) { |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2366 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR); |
479 | 2367 return; |
2368 } | |
2369 | |
6654
c131f20c9562
Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6594
diff
changeset
|
2370 u->state->bytes_received += n; |
c131f20c9562
Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6594
diff
changeset
|
2371 |
2360
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2372 u->buffer.last += n; |
479 | 2373 |
2374 #if 0 | |
2360
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2375 u->valid_header_in = 0; |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2376 |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2377 u->peer.cached = 0; |
479 | 2378 #endif |
2379 | |
2360
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2380 rc = u->process_header(r); |
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 (rc == NGX_AGAIN) { |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2383 |
4460
6299d1c4dbb4
Upstream: fixed "too big header" check.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
2384 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
|
2385 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
|
2386 "upstream sent too big header"); |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2387 |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2388 ngx_http_upstream_next(r, u, |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2389 NGX_HTTP_UPSTREAM_FT_INVALID_HEADER); |
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 continue; |
479 | 2394 } |
2395 | |
2360
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2396 break; |
479 | 2397 } |
2398 | |
2399 if (rc == NGX_HTTP_UPSTREAM_INVALID_HEADER) { | |
2400 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_INVALID_HEADER); | |
2401 return; | |
2402 } | |
2403 | |
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
|
2404 if (rc == NGX_ERROR) { |
479 | 2405 ngx_http_upstream_finalize_request(r, u, |
2406 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
2407 return; | |
2408 } | |
2409 | |
2410 /* rc == NGX_OK */ | |
2411 | |
6146
59fc60585f1e
Upstream: times to obtain header/response are stored as ngx_msec_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6125
diff
changeset
|
2412 u->state->header_time = ngx_current_msec - u->state->response_time; |
5964
0a198a517eaf
Upstream: $upstream_header_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
5960
diff
changeset
|
2413 |
5209
07e515e65984
Upstream: allow to intercept responses with status 300.
Ruslan Ermilov <ru@nginx.com>
parents:
5169
diff
changeset
|
2414 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
|
2415 |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2416 if (ngx_http_upstream_test_next(r, u) == NGX_OK) { |
509 | 2417 return; |
2418 } | |
2419 | |
2267
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2420 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
|
2421 return; |
487 | 2422 } |
2423 } | |
2424 | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2425 if (ngx_http_upstream_process_headers(r, u) != NGX_OK) { |
515 | 2426 return; |
2427 } | |
2428 | |
7220
20f139e9ffa8
Generic subrequests in memory.
Roman Arutyunyan <arut@nginx.com>
parents:
7199
diff
changeset
|
2429 ngx_http_upstream_send_response(r, u); |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2430 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2431 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2432 |
1153
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2433 static ngx_int_t |
2268
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2434 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
|
2435 { |
7255
4db4fe3bdeda
Upstream: fixed ngx_http_upstream_test_next() conditions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7239
diff
changeset
|
2436 ngx_msec_t timeout; |
4db4fe3bdeda
Upstream: fixed ngx_http_upstream_test_next() conditions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7239
diff
changeset
|
2437 ngx_uint_t status, mask; |
2268
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2438 ngx_http_upstream_next_t *un; |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2439 |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2440 status = u->headers_in.status_n; |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2441 |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2442 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
|
2443 |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2444 if (status != un->status) { |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2445 continue; |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2446 } |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2447 |
7255
4db4fe3bdeda
Upstream: fixed ngx_http_upstream_test_next() conditions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7239
diff
changeset
|
2448 timeout = u->conf->next_upstream_timeout; |
4db4fe3bdeda
Upstream: fixed ngx_http_upstream_test_next() conditions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7239
diff
changeset
|
2449 |
4db4fe3bdeda
Upstream: fixed ngx_http_upstream_test_next() conditions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7239
diff
changeset
|
2450 if (u->request_sent |
4db4fe3bdeda
Upstream: fixed ngx_http_upstream_test_next() conditions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7239
diff
changeset
|
2451 && (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
|
2452 { |
4db4fe3bdeda
Upstream: fixed ngx_http_upstream_test_next() conditions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7239
diff
changeset
|
2453 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
|
2454 |
4db4fe3bdeda
Upstream: fixed ngx_http_upstream_test_next() conditions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7239
diff
changeset
|
2455 } else { |
4db4fe3bdeda
Upstream: fixed ngx_http_upstream_test_next() conditions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7239
diff
changeset
|
2456 mask = un->mask; |
4db4fe3bdeda
Upstream: fixed ngx_http_upstream_test_next() conditions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7239
diff
changeset
|
2457 } |
4db4fe3bdeda
Upstream: fixed ngx_http_upstream_test_next() conditions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7239
diff
changeset
|
2458 |
4db4fe3bdeda
Upstream: fixed ngx_http_upstream_test_next() conditions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7239
diff
changeset
|
2459 if (u->peer.tries > 1 |
4db4fe3bdeda
Upstream: fixed ngx_http_upstream_test_next() conditions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7239
diff
changeset
|
2460 && ((u->conf->next_upstream & mask) == mask) |
4db4fe3bdeda
Upstream: fixed ngx_http_upstream_test_next() conditions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7239
diff
changeset
|
2461 && !(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
|
2462 && !(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
|
2463 { |
2268
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2464 ngx_http_upstream_next(r, u, un->mask); |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2465 return NGX_OK; |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2466 } |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2467 |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2468 #if (NGX_HTTP_CACHE) |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2469 |
2952 | 2470 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
|
2471 && ((u->conf->cache_use_stale & un->mask) || r->cache->stale_error)) |
2952 | 2472 { |
2824
d106509491b5
fix building --without-http-cache
Igor Sysoev <igor@sysoev.ru>
parents:
2807
diff
changeset
|
2473 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
|
2474 |
60551422e150
reinit proxy/fastcgi header parser before ngx_http_upstream_cache_send()
Igor Sysoev <igor@sysoev.ru>
parents:
2804
diff
changeset
|
2475 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
|
2476 |
7126
77fe752b4586
Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7125
diff
changeset
|
2477 if (rc != NGX_OK) { |
77fe752b4586
Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7125
diff
changeset
|
2478 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
|
2479 return NGX_OK; |
77fe752b4586
Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7125
diff
changeset
|
2480 } |
77fe752b4586
Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7125
diff
changeset
|
2481 |
77fe752b4586
Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7125
diff
changeset
|
2482 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
|
2483 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
|
2484 |
77fe752b4586
Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7125
diff
changeset
|
2485 if (rc == NGX_DONE) { |
77fe752b4586
Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7125
diff
changeset
|
2486 return NGX_OK; |
77fe752b4586
Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7125
diff
changeset
|
2487 } |
77fe752b4586
Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7125
diff
changeset
|
2488 |
77fe752b4586
Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7125
diff
changeset
|
2489 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
|
2490 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
|
2491 } |
60551422e150
reinit proxy/fastcgi header parser before ngx_http_upstream_cache_send()
Igor Sysoev <igor@sysoev.ru>
parents:
2804
diff
changeset
|
2492 |
60551422e150
reinit proxy/fastcgi header parser before ngx_http_upstream_cache_send()
Igor Sysoev <igor@sysoev.ru>
parents:
2804
diff
changeset
|
2493 ngx_http_upstream_finalize_request(r, u, rc); |
2268
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2494 return NGX_OK; |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2495 } |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2496 |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2497 #endif |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2498 } |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2499 |
5441
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2500 #if (NGX_HTTP_CACHE) |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2501 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2502 if (status == NGX_HTTP_NOT_MODIFIED |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2503 && u->cache_status == NGX_HTTP_CACHE_EXPIRED |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2504 && u->conf->cache_revalidate) |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2505 { |
6905
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
2506 time_t now, valid, updating, error; |
5441
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2507 ngx_int_t rc; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2508 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2509 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
|
2510 "http upstream not modified"); |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2511 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2512 now = ngx_time(); |
6905
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
2513 |
5441
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2514 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
|
2515 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
|
2516 error = r->cache->error_sec; |
5441
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2517 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2518 rc = u->reinit_request(r); |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2519 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2520 if (rc != NGX_OK) { |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2521 ngx_http_upstream_finalize_request(r, u, rc); |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2522 return NGX_OK; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2523 } |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2524 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2525 u->cache_status = NGX_HTTP_CACHE_REVALIDATED; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2526 rc = ngx_http_upstream_cache_send(r, u); |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2527 |
7126
77fe752b4586
Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7125
diff
changeset
|
2528 if (rc == NGX_DONE) { |
77fe752b4586
Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7125
diff
changeset
|
2529 return NGX_OK; |
77fe752b4586
Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7125
diff
changeset
|
2530 } |
77fe752b4586
Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7125
diff
changeset
|
2531 |
77fe752b4586
Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7125
diff
changeset
|
2532 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
|
2533 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
|
2534 } |
77fe752b4586
Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7125
diff
changeset
|
2535 |
5441
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2536 if (valid == 0) { |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2537 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
|
2538 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
|
2539 error = r->cache->error_sec; |
5441
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2540 } |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2541 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2542 if (valid == 0) { |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2543 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
|
2544 u->headers_in.status_n); |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2545 if (valid) { |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2546 valid = now + valid; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2547 } |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2548 } |
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 if (valid) { |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2551 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
|
2552 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
|
2553 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
|
2554 |
5441
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2555 r->cache->date = now; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2556 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2557 ngx_http_file_cache_update_header(r); |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2558 } |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2559 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2560 ngx_http_upstream_finalize_request(r, u, rc); |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2561 return NGX_OK; |
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 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2564 #endif |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2565 |
2268
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2566 return NGX_DECLINED; |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2567 } |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2568 |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2569 |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2570 static ngx_int_t |
2267
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2571 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
|
2572 ngx_http_upstream_t *u) |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2573 { |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2574 ngx_int_t status; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2575 ngx_uint_t i; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2576 ngx_table_elt_t *h; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2577 ngx_http_err_page_t *err_page; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2578 ngx_http_core_loc_conf_t *clcf; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2579 |
2441
0c117a89f399
in miss case memcached module returned END instead of default 404 page body
Igor Sysoev <igor@sysoev.ru>
parents:
2422
diff
changeset
|
2580 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
|
2581 |
0c117a89f399
in miss case memcached module returned END instead of default 404 page body
Igor Sysoev <igor@sysoev.ru>
parents:
2422
diff
changeset
|
2582 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
|
2583 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
|
2584 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
|
2585 } |
0c117a89f399
in miss case memcached module returned END instead of default 404 page body
Igor Sysoev <igor@sysoev.ru>
parents:
2422
diff
changeset
|
2586 |
2267
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2587 if (!u->conf->intercept_errors) { |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2588 return NGX_DECLINED; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2589 } |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2590 |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2591 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
|
2592 |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2593 if (clcf->error_pages == NULL) { |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2594 return NGX_DECLINED; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2595 } |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2596 |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2597 err_page = clcf->error_pages->elts; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2598 for (i = 0; i < clcf->error_pages->nelts; i++) { |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2599 |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2600 if (err_page[i].status == status) { |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2601 |
2953
aa12525236da
fix segfault if there is error_page 401, proxy_intercept_errors is on
Igor Sysoev <igor@sysoev.ru>
parents:
2952
diff
changeset
|
2602 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
|
2603 && 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
|
2604 { |
2267
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2605 h = ngx_list_push(&r->headers_out.headers); |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2606 |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2607 if (h == NULL) { |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2608 ngx_http_upstream_finalize_request(r, u, |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2609 NGX_HTTP_INTERNAL_SERVER_ERROR); |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2610 return NGX_OK; |
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 |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2613 *h = *u->headers_in.www_authenticate; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2614 |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2615 r->headers_out.www_authenticate = h; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2616 } |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2617 |
3706
ea908f6ae499
an intercepted error code was not cached
Igor Sysoev <igor@sysoev.ru>
parents:
3705
diff
changeset
|
2618 #if (NGX_HTTP_CACHE) |
ea908f6ae499
an intercepted error code was not cached
Igor Sysoev <igor@sysoev.ru>
parents:
3705
diff
changeset
|
2619 |
3709
64777690c697
fix r3707: cache node should be freed be a response is not cached
Igor Sysoev <igor@sysoev.ru>
parents:
3708
diff
changeset
|
2620 if (r->cache) { |
7117
dbd77a638eb7
Cache: fixed caching of intercepted errors (ticket #1382).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7116
diff
changeset
|
2621 |
dbd77a638eb7
Cache: fixed caching of intercepted errors (ticket #1382).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7116
diff
changeset
|
2622 if (u->cacheable) { |
dbd77a638eb7
Cache: fixed caching of intercepted errors (ticket #1382).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7116
diff
changeset
|
2623 time_t valid; |
dbd77a638eb7
Cache: fixed caching of intercepted errors (ticket #1382).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7116
diff
changeset
|
2624 |
dbd77a638eb7
Cache: fixed caching of intercepted errors (ticket #1382).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7116
diff
changeset
|
2625 valid = r->cache->valid_sec; |
dbd77a638eb7
Cache: fixed caching of intercepted errors (ticket #1382).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7116
diff
changeset
|
2626 |
dbd77a638eb7
Cache: fixed caching of intercepted errors (ticket #1382).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7116
diff
changeset
|
2627 if (valid == 0) { |
dbd77a638eb7
Cache: fixed caching of intercepted errors (ticket #1382).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7116
diff
changeset
|
2628 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
|
2629 status); |
dbd77a638eb7
Cache: fixed caching of intercepted errors (ticket #1382).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7116
diff
changeset
|
2630 if (valid) { |
dbd77a638eb7
Cache: fixed caching of intercepted errors (ticket #1382).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7116
diff
changeset
|
2631 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
|
2632 } |
dbd77a638eb7
Cache: fixed caching of intercepted errors (ticket #1382).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7116
diff
changeset
|
2633 } |
dbd77a638eb7
Cache: fixed caching of intercepted errors (ticket #1382).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7116
diff
changeset
|
2634 |
dbd77a638eb7
Cache: fixed caching of intercepted errors (ticket #1382).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7116
diff
changeset
|
2635 if (valid) { |
dbd77a638eb7
Cache: fixed caching of intercepted errors (ticket #1382).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7116
diff
changeset
|
2636 r->cache->error = status; |
dbd77a638eb7
Cache: fixed caching of intercepted errors (ticket #1382).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7116
diff
changeset
|
2637 } |
3706
ea908f6ae499
an intercepted error code was not cached
Igor Sysoev <igor@sysoev.ru>
parents:
3705
diff
changeset
|
2638 } |
ea908f6ae499
an intercepted error code was not cached
Igor Sysoev <igor@sysoev.ru>
parents:
3705
diff
changeset
|
2639 |
3711
ce6ba077c270
several changes in cache cleanup handling:
Igor Sysoev <igor@sysoev.ru>
parents:
3709
diff
changeset
|
2640 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
|
2641 } |
ea908f6ae499
an intercepted error code was not cached
Igor Sysoev <igor@sysoev.ru>
parents:
3705
diff
changeset
|
2642 #endif |
2267
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2643 ngx_http_upstream_finalize_request(r, u, status); |
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 return NGX_OK; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2646 } |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2647 } |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2648 |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2649 return NGX_DECLINED; |
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 |
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 static ngx_int_t |
1153
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2654 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
|
2655 { |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2656 int err; |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2657 socklen_t len; |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2658 |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2659 #if (NGX_HAVE_KQUEUE) |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2660 |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2661 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
|
2662 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
|
2663 if (c->write->pending_eof) { |
e62219793beb
Upstream: better detection of connect() failures with kqueue.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4895
diff
changeset
|
2664 err = c->write->kq_errno; |
e62219793beb
Upstream: better detection of connect() failures with kqueue.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4895
diff
changeset
|
2665 |
e62219793beb
Upstream: better detection of connect() failures with kqueue.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4895
diff
changeset
|
2666 } else { |
e62219793beb
Upstream: better detection of connect() failures with kqueue.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4895
diff
changeset
|
2667 err = c->read->kq_errno; |
e62219793beb
Upstream: better detection of connect() failures with kqueue.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4895
diff
changeset
|
2668 } |
e62219793beb
Upstream: better detection of connect() failures with kqueue.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4895
diff
changeset
|
2669 |
1469
0a269c464eaf
connection error should be logged with "connecting to upstream" action,
Igor Sysoev <igor@sysoev.ru>
parents:
1468
diff
changeset
|
2670 c->log->action = "connecting to upstream"; |
4916
79c8e87b1fcb
Trailing whitespace fix.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4915
diff
changeset
|
2671 (void) ngx_connection_error(c, err, |
1166 | 2672 "kevent() reported that connect() failed"); |
2673 return NGX_ERROR; | |
2674 } | |
1153
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2675 |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2676 } else |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2677 #endif |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2678 { |
1166 | 2679 err = 0; |
2680 len = sizeof(int); | |
2681 | |
2682 /* | |
2683 * BSDs and Linux return 0 and set a pending error in err | |
2684 * Solaris returns -1 and sets errno | |
2685 */ | |
2686 | |
2687 if (getsockopt(c->fd, SOL_SOCKET, SO_ERROR, (void *) &err, &len) | |
2688 == -1) | |
2689 { | |
5557
188481078faf
Use ngx_socket_errno where appropriate.
Piotr Sikora <piotr@cloudflare.com>
parents:
5546
diff
changeset
|
2690 err = ngx_socket_errno; |
1166 | 2691 } |
2692 | |
2693 if (err) { | |
1469
0a269c464eaf
connection error should be logged with "connecting to upstream" action,
Igor Sysoev <igor@sysoev.ru>
parents:
1468
diff
changeset
|
2694 c->log->action = "connecting to upstream"; |
1166 | 2695 (void) ngx_connection_error(c, err, "connect() failed"); |
2696 return NGX_ERROR; | |
2697 } | |
1153
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 |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2700 return NGX_OK; |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2701 } |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2702 |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2703 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2704 static ngx_int_t |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2705 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
|
2706 { |
5489
6d357b2a9d6e
Upstream: keep $upstream_http_x_accel_redirect intact.
Ruslan Ermilov <ru@nginx.com>
parents:
5477
diff
changeset
|
2707 ngx_str_t uri, args; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2708 ngx_uint_t i, flags; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2709 ngx_list_part_t *part; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2710 ngx_table_elt_t *h; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2711 ngx_http_upstream_header_t *hh; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2712 ngx_http_upstream_main_conf_t *umcf; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2713 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2714 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
|
2715 |
2786
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
2716 if (u->headers_in.x_accel_redirect |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
2717 && !(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
|
2718 { |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2719 ngx_http_upstream_finalize_request(r, u, NGX_DECLINED); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2720 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2721 part = &u->headers_in.headers.part; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2722 h = part->elts; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2723 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2724 for (i = 0; /* void */; i++) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2725 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2726 if (i >= part->nelts) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2727 if (part->next == NULL) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2728 break; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2729 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2730 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2731 part = part->next; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2732 h = part->elts; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2733 i = 0; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2734 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2735 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2736 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
|
2737 h[i].lowcase_key, h[i].key.len); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2738 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2739 if (hh && hh->redirect) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2740 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
|
2741 ngx_http_finalize_request(r, |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2742 NGX_HTTP_INTERNAL_SERVER_ERROR); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2743 return NGX_DONE; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2744 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2745 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2746 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2747 |
5489
6d357b2a9d6e
Upstream: keep $upstream_http_x_accel_redirect intact.
Ruslan Ermilov <ru@nginx.com>
parents:
5477
diff
changeset
|
2748 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
|
2749 |
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2750 if (uri.data[0] == '@') { |
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2751 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
|
2752 |
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2753 } else { |
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2754 ngx_str_null(&args); |
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2755 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
|
2756 |
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2757 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
|
2758 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
|
2759 return NGX_DONE; |
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2760 } |
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2761 |
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2762 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
|
2763 r->method = NGX_HTTP_GET; |
6334
b31928ca3870
Upstream: fixed changing method on X-Accel-Redirect.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6332
diff
changeset
|
2764 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
|
2765 } |
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2766 |
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2767 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
|
2768 } |
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2769 |
3120
40b8b398dbbc
fix request counter for X-Accel-Redirect, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3112
diff
changeset
|
2770 ngx_http_finalize_request(r, NGX_DONE); |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2771 return NGX_DONE; |
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 part = &u->headers_in.headers.part; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2775 h = part->elts; |
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 for (i = 0; /* void */; i++) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2778 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2779 if (i >= part->nelts) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2780 if (part->next == NULL) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2781 break; |
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 part = part->next; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2785 h = part->elts; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2786 i = 0; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2787 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2788 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2789 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
|
2790 h[i].lowcase_key, h[i].key.len)) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2791 { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2792 continue; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2793 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2794 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2795 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
|
2796 h[i].lowcase_key, h[i].key.len); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2797 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2798 if (hh) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2799 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
|
2800 ngx_http_upstream_finalize_request(r, u, |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2801 NGX_HTTP_INTERNAL_SERVER_ERROR); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2802 return NGX_DONE; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2803 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2804 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2805 continue; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2806 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2807 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2808 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
|
2809 ngx_http_upstream_finalize_request(r, u, |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2810 NGX_HTTP_INTERNAL_SERVER_ERROR); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2811 return NGX_DONE; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2812 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2813 } |
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 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
|
2816 r->headers_out.server->hash = 0; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2817 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2818 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2819 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
|
2820 r->headers_out.date->hash = 0; |
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 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2823 r->headers_out.status = u->headers_in.status_n; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2824 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
|
2825 |
4117
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
2826 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
|
2827 |
5735
5fb1e57c758a
Entity tags: explicit flag to skip not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5732
diff
changeset
|
2828 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
|
2829 |
5874
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
2830 if (u->conf->force_ranges) { |
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
2831 r->allow_ranges = 1; |
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
2832 r->single_range = 1; |
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
2833 |
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
2834 #if (NGX_HTTP_CACHE) |
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
2835 if (r->cached) { |
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
2836 r->single_range = 0; |
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
2837 } |
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
2838 #endif |
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
2839 } |
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
2840 |
5300
f538a67c9f77
Upstream: u->length now defaults to -1 (API change).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5299
diff
changeset
|
2841 u->length = -1; |
2592
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 return NGX_OK; |
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 |
7230
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2847 static ngx_int_t |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2848 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
|
2849 ngx_http_upstream_t *u) |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2850 { |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2851 ngx_uint_t i; |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2852 ngx_list_part_t *part; |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2853 ngx_table_elt_t *h, *ho; |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2854 |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2855 if (!u->conf->pass_trailers) { |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2856 return NGX_OK; |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2857 } |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2858 |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2859 part = &u->headers_in.trailers.part; |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2860 h = part->elts; |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2861 |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2862 for (i = 0; /* void */; i++) { |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2863 |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2864 if (i >= part->nelts) { |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2865 if (part->next == NULL) { |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2866 break; |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2867 } |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2868 |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2869 part = part->next; |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2870 h = part->elts; |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2871 i = 0; |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2872 } |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2873 |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2874 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
|
2875 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
|
2876 { |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2877 continue; |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2878 } |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2879 |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2880 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
|
2881 if (ho == NULL) { |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2882 return NGX_ERROR; |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2883 } |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2884 |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2885 *ho = h[i]; |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2886 } |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2887 |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2888 return NGX_OK; |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2889 } |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2890 |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
2891 |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2892 static void |
681 | 2893 ngx_http_upstream_send_response(ngx_http_request_t *r, ngx_http_upstream_t *u) |
2894 { | |
2402 | 2895 ssize_t n; |
681 | 2896 ngx_int_t rc; |
2897 ngx_event_pipe_t *p; | |
2898 ngx_connection_t *c; | |
2899 ngx_http_core_loc_conf_t *clcf; | |
2900 | |
509 | 2901 rc = ngx_http_send_header(r); |
479 | 2902 |
2701 | 2903 if (rc == NGX_ERROR || rc > NGX_OK || r->post_action) { |
485 | 2904 ngx_http_upstream_finalize_request(r, u, rc); |
479 | 2905 return; |
2906 } | |
2907 | |
5353
1608b1135a1d
Upstream: setting u->header_sent before ngx_http_upstream_upgrade().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5340
diff
changeset
|
2908 u->header_sent = 1; |
1608b1135a1d
Upstream: setting u->header_sent before ngx_http_upstream_upgrade().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5340
diff
changeset
|
2909 |
5072
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2910 if (u->upgrade) { |
6794
93b294c5d581
Upstream: avoid holding a cache node with upgraded connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6793
diff
changeset
|
2911 |
93b294c5d581
Upstream: avoid holding a cache node with upgraded connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6793
diff
changeset
|
2912 #if (NGX_HTTP_CACHE) |
93b294c5d581
Upstream: avoid holding a cache node with upgraded connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6793
diff
changeset
|
2913 |
93b294c5d581
Upstream: avoid holding a cache node with upgraded connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6793
diff
changeset
|
2914 if (r->cache) { |
93b294c5d581
Upstream: avoid holding a cache node with upgraded connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6793
diff
changeset
|
2915 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
|
2916 } |
93b294c5d581
Upstream: avoid holding a cache node with upgraded connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6793
diff
changeset
|
2917 |
93b294c5d581
Upstream: avoid holding a cache node with upgraded connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6793
diff
changeset
|
2918 #endif |
93b294c5d581
Upstream: avoid holding a cache node with upgraded connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6793
diff
changeset
|
2919 |
5072
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2920 ngx_http_upstream_upgrade(r, u); |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2921 return; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2922 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2923 |
2704
ac1e2e199c9f
shutdown client connection for cacheable header only responses
Igor Sysoev <igor@sysoev.ru>
parents:
2703
diff
changeset
|
2924 c = r->connection; |
ac1e2e199c9f
shutdown client connection for cacheable header only responses
Igor Sysoev <igor@sysoev.ru>
parents:
2703
diff
changeset
|
2925 |
2701 | 2926 if (r->header_only) { |
2704
ac1e2e199c9f
shutdown client connection for cacheable header only responses
Igor Sysoev <igor@sysoev.ru>
parents:
2703
diff
changeset
|
2927 |
5746
35990c69b3ac
Upstream: p->downstream_error instead of closing connection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5745
diff
changeset
|
2928 if (!u->buffering) { |
2701 | 2929 ngx_http_upstream_finalize_request(r, u, rc); |
2930 return; | |
2931 } | |
5746
35990c69b3ac
Upstream: p->downstream_error instead of closing connection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5745
diff
changeset
|
2932 |
35990c69b3ac
Upstream: p->downstream_error instead of closing connection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5745
diff
changeset
|
2933 if (!u->cacheable && !u->store) { |
35990c69b3ac
Upstream: p->downstream_error instead of closing connection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5745
diff
changeset
|
2934 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
|
2935 return; |
35990c69b3ac
Upstream: p->downstream_error instead of closing connection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5745
diff
changeset
|
2936 } |
35990c69b3ac
Upstream: p->downstream_error instead of closing connection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5745
diff
changeset
|
2937 |
35990c69b3ac
Upstream: p->downstream_error instead of closing connection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5745
diff
changeset
|
2938 u->pipe->downstream_error = 1; |
2701 | 2939 } |
2940 | |
7070
f583559aadc7
Upstream: keep request body file from removal if requested.
Roman Arutyunyan <arut@nginx.com>
parents:
7067
diff
changeset
|
2941 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
|
2942 && 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
|
2943 && !u->conf->preserve_output) |
7070
f583559aadc7
Upstream: keep request body file from removal if requested.
Roman Arutyunyan <arut@nginx.com>
parents:
7067
diff
changeset
|
2944 { |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2945 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
|
2946 r->request_body->temp_file->file.fd = NGX_INVALID_FILE; |
563 | 2947 } |
2948 | |
581 | 2949 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
2950 | |
649 | 2951 if (!u->buffering) { |
581 | 2952 |
6794
93b294c5d581
Upstream: avoid holding a cache node with upgraded connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6793
diff
changeset
|
2953 #if (NGX_HTTP_CACHE) |
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 if (r->cache) { |
93b294c5d581
Upstream: avoid holding a cache node with upgraded connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6793
diff
changeset
|
2956 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
|
2957 } |
93b294c5d581
Upstream: avoid holding a cache node with upgraded connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6793
diff
changeset
|
2958 |
93b294c5d581
Upstream: avoid holding a cache node with upgraded connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6793
diff
changeset
|
2959 #endif |
93b294c5d581
Upstream: avoid holding a cache node with upgraded connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6793
diff
changeset
|
2960 |
581 | 2961 if (u->input_filter == NULL) { |
2962 u->input_filter_init = ngx_http_upstream_non_buffered_filter_init; | |
2963 u->input_filter = ngx_http_upstream_non_buffered_filter; | |
2964 u->input_filter_ctx = r; | |
2965 } | |
2966 | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2967 u->read_event_handler = ngx_http_upstream_process_non_buffered_upstream; |
581 | 2968 r->write_event_handler = |
2969 ngx_http_upstream_process_non_buffered_downstream; | |
2970 | |
2971 r->limit_rate = 0; | |
2972 | |
2973 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
|
2974 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
581 | 2975 return; |
2976 } | |
2977 | |
7007
ed1101bbf19f
Introduced ngx_tcp_nodelay().
Ruslan Ermilov <ru@nginx.com>
parents:
7006
diff
changeset
|
2978 if (clcf->tcp_nodelay && ngx_tcp_nodelay(c) != NGX_OK) { |
ed1101bbf19f
Introduced ngx_tcp_nodelay().
Ruslan Ermilov <ru@nginx.com>
parents:
7006
diff
changeset
|
2979 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
ed1101bbf19f
Introduced ngx_tcp_nodelay().
Ruslan Ermilov <ru@nginx.com>
parents:
7006
diff
changeset
|
2980 return; |
583 | 2981 } |
2982 | |
2402 | 2983 n = u->buffer.last - u->buffer.pos; |
2984 | |
2985 if (n) { | |
581 | 2986 u->buffer.last = u->buffer.pos; |
2987 | |
2402 | 2988 u->state->response_length += n; |
2989 | |
2990 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
|
2991 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
581 | 2992 return; |
2993 } | |
2994 | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2995 ngx_http_upstream_process_non_buffered_downstream(r); |
581 | 2996 |
2997 } else { | |
2998 u->buffer.pos = u->buffer.start; | |
2999 u->buffer.last = u->buffer.start; | |
3000 | |
3001 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
|
3002 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
581 | 3003 return; |
3004 } | |
1468
491e5059ea19
read EOF of header only responses in non-buffered proxying
Igor Sysoev <igor@sysoev.ru>
parents:
1397
diff
changeset
|
3005 |
4120
42135dd1f0ea
Upstream: keepalive flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4119
diff
changeset
|
3006 if (u->peer.connection->read->ready || u->length == 0) { |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
3007 ngx_http_upstream_process_non_buffered_upstream(r, u); |
1468
491e5059ea19
read EOF of header only responses in non-buffered proxying
Igor Sysoev <igor@sysoev.ru>
parents:
1397
diff
changeset
|
3008 } |
581 | 3009 } |
3010 | |
3011 return; | |
3012 } | |
3013 | |
479 | 3014 /* TODO: preallocate event_pipe bufs, look "Content-Length" */ |
3015 | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3016 #if (NGX_HTTP_CACHE) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3017 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3018 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
|
3019 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
|
3020 r->cache->file.fd = NGX_INVALID_FILE; |
479 | 3021 } |
3022 | |
3699
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
3023 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
|
3024 |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
3025 case NGX_ERROR: |
5295
a489c31c9783
Upstream: ngx_http_upstream_finalize_request(NGX_ERROR) on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5294
diff
changeset
|
3026 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
|
3027 return; |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
3028 |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
3029 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
|
3030 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
|
3031 break; |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
3032 |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
3033 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
|
3034 |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
3035 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
|
3036 |
5950
eaeecf00d5d7
Upstream: preset some cache configuration when bypassing.
Valentin Bartenev <vbart@nginx.com>
parents:
5949
diff
changeset
|
3037 /* 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
|
3038 |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
3039 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
|
3040 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
|
3041 return; |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
3042 } |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
3043 } |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
3044 |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
3045 break; |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
3046 } |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
3047 |
1565 | 3048 if (u->cacheable) { |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3049 time_t now, valid; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3050 |
2663
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
3051 now = ngx_time(); |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
3052 |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
3053 valid = r->cache->valid_sec; |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
3054 |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
3055 if (valid == 0) { |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
3056 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
|
3057 u->headers_in.status_n); |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
3058 if (valid) { |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
3059 r->cache->valid_sec = now + valid; |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
3060 } |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
3061 } |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
3062 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3063 if (valid) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3064 r->cache->date = now; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3065 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
|
3066 |
5935
1573fc7875fa
Cache: send conditional requests only for cached 200/206 responses.
Piotr Sikora <piotr@cloudflare.com>
parents:
5928
diff
changeset
|
3067 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
|
3068 || 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
|
3069 { |
1573fc7875fa
Cache: send conditional requests only for cached 200/206 responses.
Piotr Sikora <piotr@cloudflare.com>
parents:
5928
diff
changeset
|
3070 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
|
3071 |
1573fc7875fa
Cache: send conditional requests only for cached 200/206 responses.
Piotr Sikora <piotr@cloudflare.com>
parents:
5928
diff
changeset
|
3072 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
|
3073 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
|
3074 |
174512857ccf
Cache: do not inherit last_modified and etag from stale response.
Roman Arutyunyan <arut@nginx.com>
parents:
5977
diff
changeset
|
3075 } else { |
174512857ccf
Cache: do not inherit last_modified and etag from stale response.
Roman Arutyunyan <arut@nginx.com>
parents:
5977
diff
changeset
|
3076 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
|
3077 } |
5992
174512857ccf
Cache: do not inherit last_modified and etag from stale response.
Roman Arutyunyan <arut@nginx.com>
parents:
5977
diff
changeset
|
3078 |
174512857ccf
Cache: do not inherit last_modified and etag from stale response.
Roman Arutyunyan <arut@nginx.com>
parents:
5977
diff
changeset
|
3079 } else { |
174512857ccf
Cache: do not inherit last_modified and etag from stale response.
Roman Arutyunyan <arut@nginx.com>
parents:
5977
diff
changeset
|
3080 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
|
3081 ngx_str_null(&r->cache->etag); |
5737
44b9ab7752e3
Cache: ETag now saved into cache header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5735
diff
changeset
|
3082 } |
44b9ab7752e3
Cache: ETag now saved into cache header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5735
diff
changeset
|
3083 |
5959
f7584d7c0ccb
Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents:
5951
diff
changeset
|
3084 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
|
3085 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
|
3086 return; |
f7584d7c0ccb
Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents:
5951
diff
changeset
|
3087 } |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3088 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3089 } else { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3090 u->cacheable = 0; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3091 } |
479 | 3092 } |
3093 | |
2690 | 3094 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, |
3095 "http cacheable: %d", u->cacheable); | |
3096 | |
3083
ffe8bfb38184
clean cache updating state if a response has uncacheable code or
Igor Sysoev <igor@sysoev.ru>
parents:
3056
diff
changeset
|
3097 if (u->cacheable == 0 && r->cache) { |
3711
ce6ba077c270
several changes in cache cleanup handling:
Igor Sysoev <igor@sysoev.ru>
parents:
3709
diff
changeset
|
3098 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
|
3099 } |
ffe8bfb38184
clean cache updating state if a response has uncacheable code or
Igor Sysoev <igor@sysoev.ru>
parents:
3056
diff
changeset
|
3100 |
6428
545b5e4d83b2
Upstream: avoid closing client connection in edge case.
Justin Li <jli.justinli@gmail.com>
parents:
6427
diff
changeset
|
3101 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
|
3102 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
|
3103 return; |
545b5e4d83b2
Upstream: avoid closing client connection in edge case.
Justin Li <jli.justinli@gmail.com>
parents:
6427
diff
changeset
|
3104 } |
545b5e4d83b2
Upstream: avoid closing client connection in edge case.
Justin Li <jli.justinli@gmail.com>
parents:
6427
diff
changeset
|
3105 |
479 | 3106 #endif |
3107 | |
581 | 3108 p = u->pipe; |
479 | 3109 |
6443
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3110 p->output_filter = ngx_http_upstream_output_filter; |
479 | 3111 p->output_ctx = r; |
3112 p->tag = u->output.tag; | |
577 | 3113 p->bufs = u->conf->bufs; |
479 | 3114 p->busy_size = u->conf->busy_buffers_size; |
3115 p->upstream = u->peer.connection; | |
583 | 3116 p->downstream = c; |
479 | 3117 p->pool = r->pool; |
583 | 3118 p->log = c->log; |
5883
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3119 p->limit_rate = u->conf->limit_rate; |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3120 p->start_sec = ngx_time(); |
577 | 3121 |
1565 | 3122 p->cacheable = u->cacheable || u->store; |
479 | 3123 |
501 | 3124 p->temp_file = ngx_pcalloc(r->pool, sizeof(ngx_temp_file_t)); |
3125 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
|
3126 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
479 | 3127 return; |
3128 } | |
3129 | |
3130 p->temp_file->file.fd = NGX_INVALID_FILE; | |
583 | 3131 p->temp_file->file.log = c->log; |
479 | 3132 p->temp_file->path = u->conf->temp_path; |
3133 p->temp_file->pool = r->pool; | |
577 | 3134 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3135 if (p->cacheable) { |
479 | 3136 p->temp_file->persistent = 1; |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3137 |
5960
e9effef98874
Upstream: use_temp_path parameter of proxy_cache_path and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5959
diff
changeset
|
3138 #if (NGX_HTTP_CACHE) |
6795
1a917932db96
Cache: prefix-based temporary files.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6794
diff
changeset
|
3139 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
|
3140 p->temp_file->path = r->cache->file_cache->path; |
1a917932db96
Cache: prefix-based temporary files.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6794
diff
changeset
|
3141 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
|
3142 } |
e9effef98874
Upstream: use_temp_path parameter of proxy_cache_path and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5959
diff
changeset
|
3143 #endif |
e9effef98874
Upstream: use_temp_path parameter of proxy_cache_path and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5959
diff
changeset
|
3144 |
479 | 3145 } else { |
667 | 3146 p->temp_file->log_level = NGX_LOG_WARN; |
479 | 3147 p->temp_file->warn = "an upstream response is buffered " |
3148 "to a temporary file"; | |
3149 } | |
3150 | |
3151 p->max_temp_file_size = u->conf->max_temp_file_size; | |
3152 p->temp_file_write_size = u->conf->temp_file_write_size; | |
3153 | |
6443
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3154 #if (NGX_THREADS) |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3155 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
|
3156 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
|
3157 p->thread_ctx = r; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3158 } |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3159 #endif |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3160 |
501 | 3161 p->preread_bufs = ngx_alloc_chain_link(r->pool); |
3162 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
|
3163 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
479 | 3164 return; |
3165 } | |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3166 |
581 | 3167 p->preread_bufs->buf = &u->buffer; |
479 | 3168 p->preread_bufs->next = NULL; |
581 | 3169 u->buffer.recycled = 1; |
3170 | |
3171 p->preread_size = u->buffer.last - u->buffer.pos; | |
479 | 3172 |
1565 | 3173 if (u->cacheable) { |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3174 |
479 | 3175 p->buf_to_file = ngx_calloc_buf(r->pool); |
3176 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
|
3177 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
479 | 3178 return; |
3179 } | |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3180 |
4895
508e61393b6c
Event pipe: fixed handling of buf_to_file data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4769
diff
changeset
|
3181 p->buf_to_file->start = u->buffer.start; |
581 | 3182 p->buf_to_file->pos = u->buffer.start; |
3183 p->buf_to_file->last = u->buffer.pos; | |
479 | 3184 p->buf_to_file->temporary = 1; |
3185 } | |
3186 | |
6125
4dc8e7b62216
Removed the obsolete aio module.
Ruslan Ermilov <ru@nginx.com>
parents:
6068
diff
changeset
|
3187 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
|
3188 /* the posted aio operation may corrupt a shadow buffer */ |
479 | 3189 p->single_buf = 1; |
3190 } | |
3191 | |
3192 /* TODO: p->free_bufs = 0 if use ngx_create_chain_of_bufs() */ | |
3193 p->free_bufs = 1; | |
3194 | |
3195 /* | |
581 | 3196 * event_pipe would do u->buffer.last += p->preread_size |
479 | 3197 * as though these bytes were read |
3198 */ | |
581 | 3199 u->buffer.last = u->buffer.pos; |
479 | 3200 |
3201 if (u->conf->cyclic_temp_file) { | |
3202 | |
3203 /* | |
3204 * we need to disable the use of sendfile() if we use cyclic temp file | |
3205 * because the writing a new data may interfere with sendfile() | |
3206 * that uses the same kernel file pages (at least on FreeBSD) | |
3207 */ | |
3208 | |
3209 p->cyclic_temp_file = 1; | |
583 | 3210 c->sendfile = 0; |
479 | 3211 |
3212 } else { | |
3213 p->cyclic_temp_file = 0; | |
3214 } | |
3215 | |
3216 p->read_timeout = u->conf->read_timeout; | |
3217 p->send_timeout = clcf->send_timeout; | |
3218 p->send_lowat = clcf->send_lowat; | |
3219 | |
4119
b66712cde67d
Upstream: pipe length and input_filter_init in buffered mode.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4118
diff
changeset
|
3220 p->length = -1; |
b66712cde67d
Upstream: pipe length and input_filter_init in buffered mode.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4118
diff
changeset
|
3221 |
b66712cde67d
Upstream: pipe length and input_filter_init in buffered mode.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4118
diff
changeset
|
3222 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
|
3223 && 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
|
3224 { |
5295
a489c31c9783
Upstream: ngx_http_upstream_finalize_request(NGX_ERROR) on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5294
diff
changeset
|
3225 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
|
3226 return; |
b66712cde67d
Upstream: pipe length and input_filter_init in buffered mode.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4118
diff
changeset
|
3227 } |
b66712cde67d
Upstream: pipe length and input_filter_init in buffered mode.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4118
diff
changeset
|
3228 |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3229 u->read_event_handler = ngx_http_upstream_process_upstream; |
509 | 3230 r->write_event_handler = ngx_http_upstream_process_downstream; |
479 | 3231 |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
3232 ngx_http_upstream_process_upstream(r, u); |
479 | 3233 } |
3234 | |
3235 | |
487 | 3236 static void |
5072
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3237 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
|
3238 { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3239 ngx_connection_t *c; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3240 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
|
3241 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3242 c = r->connection; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3243 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
|
3244 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3245 /* 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
|
3246 |
7131
6a5a91de5b74
Upstream: disabled upgrading in subrequests.
Roman Arutyunyan <arut@nginx.com>
parents:
7130
diff
changeset
|
3247 if (r != r->main) { |
6a5a91de5b74
Upstream: disabled upgrading in subrequests.
Roman Arutyunyan <arut@nginx.com>
parents:
7130
diff
changeset
|
3248 ngx_log_error(NGX_LOG_ERR, c->log, 0, |
6a5a91de5b74
Upstream: disabled upgrading in subrequests.
Roman Arutyunyan <arut@nginx.com>
parents:
7130
diff
changeset
|
3249 "connection upgrade in subrequest"); |
6a5a91de5b74
Upstream: disabled upgrading in subrequests.
Roman Arutyunyan <arut@nginx.com>
parents:
7130
diff
changeset
|
3250 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
6a5a91de5b74
Upstream: disabled upgrading in subrequests.
Roman Arutyunyan <arut@nginx.com>
parents:
7130
diff
changeset
|
3251 return; |
6a5a91de5b74
Upstream: disabled upgrading in subrequests.
Roman Arutyunyan <arut@nginx.com>
parents:
7130
diff
changeset
|
3252 } |
6a5a91de5b74
Upstream: disabled upgrading in subrequests.
Roman Arutyunyan <arut@nginx.com>
parents:
7130
diff
changeset
|
3253 |
5072
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3254 r->keepalive = 0; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3255 c->log->action = "proxying upgraded connection"; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3256 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3257 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
|
3258 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
|
3259 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
|
3260 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
|
3261 |
5142
afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5132
diff
changeset
|
3262 if (clcf->tcp_nodelay) { |
7007
ed1101bbf19f
Introduced ngx_tcp_nodelay().
Ruslan Ermilov <ru@nginx.com>
parents:
7006
diff
changeset
|
3263 |
ed1101bbf19f
Introduced ngx_tcp_nodelay().
Ruslan Ermilov <ru@nginx.com>
parents:
7006
diff
changeset
|
3264 if (ngx_tcp_nodelay(c) != NGX_OK) { |
ed1101bbf19f
Introduced ngx_tcp_nodelay().
Ruslan Ermilov <ru@nginx.com>
parents:
7006
diff
changeset
|
3265 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
ed1101bbf19f
Introduced ngx_tcp_nodelay().
Ruslan Ermilov <ru@nginx.com>
parents:
7006
diff
changeset
|
3266 return; |
ed1101bbf19f
Introduced ngx_tcp_nodelay().
Ruslan Ermilov <ru@nginx.com>
parents:
7006
diff
changeset
|
3267 } |
ed1101bbf19f
Introduced ngx_tcp_nodelay().
Ruslan Ermilov <ru@nginx.com>
parents:
7006
diff
changeset
|
3268 |
ed1101bbf19f
Introduced ngx_tcp_nodelay().
Ruslan Ermilov <ru@nginx.com>
parents:
7006
diff
changeset
|
3269 if (ngx_tcp_nodelay(u->peer.connection) != NGX_OK) { |
ed1101bbf19f
Introduced ngx_tcp_nodelay().
Ruslan Ermilov <ru@nginx.com>
parents:
7006
diff
changeset
|
3270 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
ed1101bbf19f
Introduced ngx_tcp_nodelay().
Ruslan Ermilov <ru@nginx.com>
parents:
7006
diff
changeset
|
3271 return; |
5072
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3272 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3273 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3274 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3275 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
|
3276 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
|
3277 return; |
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 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3280 if (u->peer.connection->read->ready |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3281 || u->buffer.pos != u->buffer.last) |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3282 { |
5579
7586e7b2dbe9
Upstream: ngx_post_event() instead of upgraded call (ticket #503).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5557
diff
changeset
|
3283 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
|
3284 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
|
3285 return; |
5072
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3286 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3287 |
5532
17134d29782e
Upstream: reading from a client after connection upgrade.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5500
diff
changeset
|
3288 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
|
3289 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3290 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3291 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3292 static void |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3293 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
|
3294 { |
5073
52eb762c68a9
Proxy: fixed do_write handling in previous commit.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5072
diff
changeset
|
3295 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
|
3296 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3297 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3298 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3299 static void |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3300 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
|
3301 { |
5073
52eb762c68a9
Proxy: fixed do_write handling in previous commit.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5072
diff
changeset
|
3302 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
|
3303 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3304 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3305 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3306 static void |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3307 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
|
3308 ngx_http_upstream_t *u) |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3309 { |
5073
52eb762c68a9
Proxy: fixed do_write handling in previous commit.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5072
diff
changeset
|
3310 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
|
3311 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3312 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3313 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3314 static void |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3315 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
|
3316 ngx_http_upstream_t *u) |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3317 { |
5073
52eb762c68a9
Proxy: fixed do_write handling in previous commit.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5072
diff
changeset
|
3318 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
|
3319 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3320 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3321 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3322 static void |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3323 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
|
3324 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
|
3325 { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3326 size_t size; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3327 ssize_t n; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3328 ngx_buf_t *b; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3329 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
|
3330 ngx_http_upstream_t *u; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3331 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
|
3332 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3333 c = r->connection; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3334 u = r->upstream; |
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 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
|
3337 "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
|
3338 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3339 downstream = c; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3340 upstream = u->peer.connection; |
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 if (downstream->write->timedout) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3343 c->timedout = 1; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3344 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
|
3345 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
|
3346 return; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3347 } |
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 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
|
3350 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
|
3351 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
|
3352 return; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3353 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3354 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3355 if (from_upstream) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3356 src = upstream; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3357 dst = downstream; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3358 b = &u->buffer; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3359 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3360 } else { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3361 src = downstream; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3362 dst = upstream; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3363 b = &u->from_client; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3364 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3365 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
|
3366 b = r->header_in; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3367 b->end = b->last; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3368 do_write = 1; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3369 } |
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 if (b->start == NULL) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3372 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
|
3373 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
|
3374 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
|
3375 return; |
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 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3378 b->pos = b->start; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3379 b->last = b->start; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3380 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
|
3381 b->temporary = 1; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3382 b->tag = u->output.tag; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3383 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3384 } |
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 for ( ;; ) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3387 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3388 if (do_write) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3389 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3390 size = b->last - b->pos; |
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 if (size && dst->write->ready) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3393 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3394 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
|
3395 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3396 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
|
3397 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
|
3398 return; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3399 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3400 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3401 if (n > 0) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3402 b->pos += n; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3403 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3404 if (b->pos == b->last) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3405 b->pos = b->start; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3406 b->last = b->start; |
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 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3410 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3411 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3412 size = b->end - b->last; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3413 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3414 if (size && src->read->ready) { |
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 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
|
3417 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3418 if (n == NGX_AGAIN || n == 0) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3419 break; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3420 } |
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 if (n > 0) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3423 do_write = 1; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3424 b->last += n; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3425 |
6654
c131f20c9562
Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6594
diff
changeset
|
3426 if (from_upstream) { |
c131f20c9562
Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6594
diff
changeset
|
3427 u->state->bytes_received += n; |
c131f20c9562
Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6594
diff
changeset
|
3428 } |
c131f20c9562
Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6594
diff
changeset
|
3429 |
5072
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3430 continue; |
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 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3433 if (n == NGX_ERROR) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3434 src->read->eof = 1; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3435 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3436 } |
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 break; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3439 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3440 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3441 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
|
3442 || (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
|
3443 || (downstream->read->eof && upstream->read->eof)) |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3444 { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3445 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
|
3446 "http upstream upgraded done"); |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3447 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
|
3448 return; |
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 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3451 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
|
3452 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3453 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
|
3454 != NGX_OK) |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3455 { |
5295
a489c31c9783
Upstream: ngx_http_upstream_finalize_request(NGX_ERROR) on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5294
diff
changeset
|
3456 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
|
3457 return; |
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 (upstream->write->active && !upstream->write->ready) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3461 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
|
3462 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3463 } else if (upstream->write->timer_set) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3464 ngx_del_timer(upstream->write); |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3465 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3466 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3467 if (ngx_handle_read_event(upstream->read, 0) != NGX_OK) { |
5295
a489c31c9783
Upstream: ngx_http_upstream_finalize_request(NGX_ERROR) on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5294
diff
changeset
|
3468 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
|
3469 return; |
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 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3472 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
|
3473 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
|
3474 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3475 } else if (upstream->read->timer_set) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3476 ngx_del_timer(upstream->read); |
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 (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
|
3480 != NGX_OK) |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3481 { |
5295
a489c31c9783
Upstream: ngx_http_upstream_finalize_request(NGX_ERROR) on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5294
diff
changeset
|
3482 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
|
3483 return; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3484 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3485 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3486 if (ngx_handle_read_event(downstream->read, 0) != NGX_OK) { |
5295
a489c31c9783
Upstream: ngx_http_upstream_finalize_request(NGX_ERROR) on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5294
diff
changeset
|
3487 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
|
3488 return; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3489 } |
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 (downstream->write->active && !downstream->write->ready) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3492 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
|
3493 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3494 } else if (downstream->write->timer_set) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3495 ngx_del_timer(downstream->write); |
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 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3499 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3500 static void |
581 | 3501 ngx_http_upstream_process_non_buffered_downstream(ngx_http_request_t *r) |
3502 { | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3503 ngx_event_t *wev; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3504 ngx_connection_t *c; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3505 ngx_http_upstream_t *u; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3506 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3507 c = r->connection; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3508 u = r->upstream; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3509 wev = c->write; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3510 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3511 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
|
3512 "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
|
3513 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3514 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
|
3515 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3516 if (wev->timedout) { |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3517 c->timedout = 1; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3518 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
|
3519 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
|
3520 return; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3521 } |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3522 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3523 ngx_http_upstream_process_non_buffered_request(r, 1); |
581 | 3524 } |
3525 | |
3526 | |
3527 static void | |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
3528 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
|
3529 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
|
3530 { |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
3531 ngx_connection_t *c; |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
3532 |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
3533 c = u->peer.connection; |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3534 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3535 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
|
3536 "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
|
3537 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3538 c->log->action = "reading upstream"; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3539 |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
3540 if (c->read->timedout) { |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3541 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
|
3542 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
|
3543 return; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3544 } |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3545 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3546 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
|
3547 } |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3548 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3549 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3550 static void |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3551 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
|
3552 ngx_uint_t do_write) |
581 | 3553 { |
3554 size_t size; | |
3555 ssize_t n; | |
3556 ngx_buf_t *b; | |
583 | 3557 ngx_int_t rc; |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3558 ngx_connection_t *downstream, *upstream; |
581 | 3559 ngx_http_upstream_t *u; |
3560 ngx_http_core_loc_conf_t *clcf; | |
3561 | |
756
d904b5cb3bba
fix building introduced by previous commit
Igor Sysoev <igor@sysoev.ru>
parents:
755
diff
changeset
|
3562 u = r->upstream; |
884 | 3563 downstream = r->connection; |
3564 upstream = u->peer.connection; | |
581 | 3565 |
3566 b = &u->buffer; | |
3567 | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3568 do_write = do_write || u->length == 0; |
581 | 3569 |
3570 for ( ;; ) { | |
3571 | |
3572 if (do_write) { | |
3573 | |
7166
a762ddf22dbb
Upstream: flush low-level buffers on write retry.
Patryk Lesiewicz <patryk@google.com>
parents:
7131
diff
changeset
|
3574 if (u->out_bufs || u->busy_bufs || downstream->buffered) { |
583 | 3575 rc = ngx_http_output_filter(r, u->out_bufs); |
3576 | |
3577 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
|
3578 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
581 | 3579 return; |
3580 } | |
3581 | |
4114
5db098f97e0e
API change: ngx_chain_update_chains() now requires pool.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3976
diff
changeset
|
3582 ngx_chain_update_chains(r->pool, &u->free_bufs, &u->busy_bufs, |
581 | 3583 &u->out_bufs, u->output.tag); |
3584 } | |
3585 | |
3586 if (u->busy_bufs == NULL) { | |
3587 | |
3588 if (u->length == 0 | |
5301
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3589 || (upstream->read->eof && u->length == -1)) |
581 | 3590 { |
3591 ngx_http_upstream_finalize_request(r, u, 0); | |
3592 return; | |
3593 } | |
3594 | |
5301
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3595 if (upstream->read->eof) { |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3596 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
|
3597 "upstream prematurely closed connection"); |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3598 |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3599 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
|
3600 NGX_HTTP_BAD_GATEWAY); |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3601 return; |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3602 } |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3603 |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3604 if (upstream->read->error) { |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3605 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
|
3606 NGX_HTTP_BAD_GATEWAY); |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3607 return; |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3608 } |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3609 |
581 | 3610 b->pos = b->start; |
3611 b->last = b->start; | |
3612 } | |
3613 } | |
3614 | |
3615 size = b->end - b->last; | |
3616 | |
884 | 3617 if (size && upstream->read->ready) { |
3618 | |
3619 n = upstream->recv(upstream, b->last, size); | |
581 | 3620 |
3621 if (n == NGX_AGAIN) { | |
3622 break; | |
3623 } | |
3624 | |
3625 if (n > 0) { | |
6654
c131f20c9562
Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6594
diff
changeset
|
3626 u->state->bytes_received += n; |
2402 | 3627 u->state->response_length += n; |
3628 | |
581 | 3629 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
|
3630 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
581 | 3631 return; |
3632 } | |
3633 } | |
3634 | |
3635 do_write = 1; | |
3636 | |
3637 continue; | |
3638 } | |
3639 | |
3640 break; | |
3641 } | |
3642 | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3643 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
|
3644 |
884 | 3645 if (downstream->data == r) { |
3646 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
|
3647 != NGX_OK) |
583 | 3648 { |
5295
a489c31c9783
Upstream: ngx_http_upstream_finalize_request(NGX_ERROR) on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5294
diff
changeset
|
3649 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
583 | 3650 return; |
3651 } | |
581 | 3652 } |
3653 | |
1063
e2a6ecc5a3ae
a non-active client connection must not closed after send timeout
Igor Sysoev <igor@sysoev.ru>
parents:
1031
diff
changeset
|
3654 if (downstream->write->active && !downstream->write->ready) { |
884 | 3655 ngx_add_timer(downstream->write, clcf->send_timeout); |
3656 | |
3657 } else if (downstream->write->timer_set) { | |
3658 ngx_del_timer(downstream->write); | |
581 | 3659 } |
3660 | |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
3661 if (ngx_handle_read_event(upstream->read, 0) != NGX_OK) { |
5295
a489c31c9783
Upstream: ngx_http_upstream_finalize_request(NGX_ERROR) on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5294
diff
changeset
|
3662 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
581 | 3663 return; |
3664 } | |
3665 | |
1063
e2a6ecc5a3ae
a non-active client connection must not closed after send timeout
Igor Sysoev <igor@sysoev.ru>
parents:
1031
diff
changeset
|
3666 if (upstream->read->active && !upstream->read->ready) { |
884 | 3667 ngx_add_timer(upstream->read, u->conf->read_timeout); |
3668 | |
3669 } else if (upstream->read->timer_set) { | |
3670 ngx_del_timer(upstream->read); | |
581 | 3671 } |
3672 } | |
3673 | |
3674 | |
3675 static ngx_int_t | |
3676 ngx_http_upstream_non_buffered_filter_init(void *data) | |
3677 { | |
3678 return NGX_OK; | |
3679 } | |
3680 | |
3681 | |
3682 static ngx_int_t | |
3683 ngx_http_upstream_non_buffered_filter(void *data, ssize_t bytes) | |
3684 { | |
3685 ngx_http_request_t *r = data; | |
3686 | |
3687 ngx_buf_t *b; | |
3688 ngx_chain_t *cl, **ll; | |
3689 ngx_http_upstream_t *u; | |
3690 | |
3691 u = r->upstream; | |
3692 | |
3693 for (cl = u->out_bufs, ll = &u->out_bufs; cl; cl = cl->next) { | |
3694 ll = &cl->next; | |
3695 } | |
3696 | |
3697 cl = ngx_chain_get_free_buf(r->pool, &u->free_bufs); | |
3698 if (cl == NULL) { | |
3699 return NGX_ERROR; | |
3700 } | |
3701 | |
3702 *ll = cl; | |
3703 | |
3704 cl->buf->flush = 1; | |
3705 cl->buf->memory = 1; | |
3706 | |
3707 b = &u->buffer; | |
3708 | |
3709 cl->buf->pos = b->last; | |
3710 b->last += bytes; | |
3711 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
|
3712 cl->buf->tag = u->output.tag; |
581 | 3713 |
4118
dbddec65fdab
Upstream: r->upstream->length type change to off_t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4117
diff
changeset
|
3714 if (u->length == -1) { |
581 | 3715 return NGX_OK; |
3716 } | |
3717 | |
3718 u->length -= bytes; | |
3719 | |
3720 return NGX_OK; | |
3721 } | |
3722 | |
3723 | |
6443
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3724 #if (NGX_THREADS) |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3725 |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3726 static ngx_int_t |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3727 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
|
3728 { |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3729 ngx_str_t name; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3730 ngx_event_pipe_t *p; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3731 ngx_thread_pool_t *tp; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3732 ngx_http_request_t *r; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3733 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
|
3734 |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3735 r = file->thread_ctx; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3736 p = r->upstream->pipe; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3737 |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3738 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
|
3739 tp = clcf->thread_pool; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3740 |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3741 if (tp == NULL) { |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3742 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
|
3743 != NGX_OK) |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3744 { |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3745 return NGX_ERROR; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3746 } |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3747 |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3748 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
|
3749 |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3750 if (tp == NULL) { |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3751 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
|
3752 "thread pool \"%V\" not found", &name); |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3753 return NGX_ERROR; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3754 } |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3755 } |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3756 |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3757 task->event.data = r; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3758 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
|
3759 |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3760 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
|
3761 return NGX_ERROR; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3762 } |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3763 |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3764 r->main->blocked++; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3765 r->aio = 1; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3766 p->aio = 1; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3767 |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3768 return NGX_OK; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3769 } |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3770 |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3771 |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3772 static void |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3773 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
|
3774 { |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3775 ngx_connection_t *c; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3776 ngx_http_request_t *r; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3777 |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3778 r = ev->data; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3779 c = r->connection; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3780 |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3781 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
|
3782 |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3783 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
|
3784 "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
|
3785 |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3786 r->main->blocked--; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3787 r->aio = 0; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3788 |
6950
4cb4ffe06785
Threads: fixed request hang with aio_write and subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6923
diff
changeset
|
3789 if (r->done) { |
4cb4ffe06785
Threads: fixed request hang with aio_write and subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6923
diff
changeset
|
3790 /* |
4cb4ffe06785
Threads: fixed request hang with aio_write and subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6923
diff
changeset
|
3791 * 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
|
3792 * 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
|
3793 * for sendfile() in threads |
4cb4ffe06785
Threads: fixed request hang with aio_write and subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6923
diff
changeset
|
3794 */ |
4cb4ffe06785
Threads: fixed request hang with aio_write and subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6923
diff
changeset
|
3795 |
4cb4ffe06785
Threads: fixed request hang with aio_write and subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6923
diff
changeset
|
3796 c->write->handler(c->write); |
4cb4ffe06785
Threads: fixed request hang with aio_write and subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6923
diff
changeset
|
3797 |
4cb4ffe06785
Threads: fixed request hang with aio_write and subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6923
diff
changeset
|
3798 } else { |
4cb4ffe06785
Threads: fixed request hang with aio_write and subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6923
diff
changeset
|
3799 r->write_event_handler(r); |
4cb4ffe06785
Threads: fixed request hang with aio_write and subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6923
diff
changeset
|
3800 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
|
3801 } |
6443
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3802 } |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3803 |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3804 #endif |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3805 |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3806 |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3807 static ngx_int_t |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3808 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
|
3809 { |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3810 ngx_int_t rc; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3811 ngx_event_pipe_t *p; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3812 ngx_http_request_t *r; |
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 = data; |
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 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
|
3818 |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3819 p->aio = r->aio; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3820 |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3821 return rc; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3822 } |
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 |
581 | 3825 static void |
509 | 3826 ngx_http_upstream_process_downstream(ngx_http_request_t *r) |
3827 { | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3828 ngx_event_t *wev; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3829 ngx_connection_t *c; |
509 | 3830 ngx_event_pipe_t *p; |
479 | 3831 ngx_http_upstream_t *u; |
3832 | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3833 c = r->connection; |
479 | 3834 u = r->upstream; |
581 | 3835 p = u->pipe; |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3836 wev = c->write; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3837 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3838 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
|
3839 "http upstream process downstream"); |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3840 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3841 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
|
3842 |
6443
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3843 #if (NGX_THREADS) |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3844 p->aio = r->aio; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3845 #endif |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3846 |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3847 if (wev->timedout) { |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3848 |
6961
903fb1ddc07f
Moved handling of wev->delayed to the connection event handler.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6950
diff
changeset
|
3849 p->downstream_error = 1; |
903fb1ddc07f
Moved handling of wev->delayed to the connection event handler.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6950
diff
changeset
|
3850 c->timedout = 1; |
903fb1ddc07f
Moved handling of wev->delayed to the connection event handler.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6950
diff
changeset
|
3851 ngx_connection_error(c, NGX_ETIMEDOUT, "client timed out"); |
479 | 3852 |
3853 } else { | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3854 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3855 if (wev->delayed) { |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3856 |
527 | 3857 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, |
3858 "http downstream delayed"); | |
3859 | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3860 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
|
3861 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
527 | 3862 } |
3863 | |
3864 return; | |
3865 } | |
3866 | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3867 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
|
3868 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
479 | 3869 return; |
3870 } | |
3871 } | |
577 | 3872 |
5995
5f179f344096
Upstream: upstream argument in ngx_http_upstream_process_request().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5994
diff
changeset
|
3873 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
|
3874 } |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3875 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3876 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3877 static void |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
3878 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
|
3879 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
|
3880 { |
5883
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3881 ngx_event_t *rev; |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3882 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
|
3883 ngx_connection_t *c; |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
3884 |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
3885 c = u->peer.connection; |
5883
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3886 p = u->pipe; |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3887 rev = c->read; |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3888 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3889 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
|
3890 "http upstream process upstream"); |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3891 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3892 c->log->action = "reading upstream"; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3893 |
5883
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3894 if (rev->timedout) { |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3895 |
6961
903fb1ddc07f
Moved handling of wev->delayed to the connection event handler.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6950
diff
changeset
|
3896 p->upstream_error = 1; |
903fb1ddc07f
Moved handling of wev->delayed to the connection event handler.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6950
diff
changeset
|
3897 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
|
3898 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3899 } else { |
5883
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3900 |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3901 if (rev->delayed) { |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3902 |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3903 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
|
3904 "http upstream delayed"); |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3905 |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3906 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
|
3907 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
|
3908 } |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3909 |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3910 return; |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3911 } |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3912 |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3913 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
|
3914 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
|
3915 return; |
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 } |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3918 |
5995
5f179f344096
Upstream: upstream argument in ngx_http_upstream_process_request().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5994
diff
changeset
|
3919 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
|
3920 } |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3921 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3922 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3923 static void |
5995
5f179f344096
Upstream: upstream argument in ngx_http_upstream_process_request().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5994
diff
changeset
|
3924 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
|
3925 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
|
3926 { |
5996 | 3927 ngx_temp_file_t *tf; |
3928 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
|
3929 |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3930 p = u->pipe; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3931 |
6443
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3932 #if (NGX_THREADS) |
6876
a5d1b1383dea
Upstream: fixed cache corruption and socket leaks with aio_write.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6853
diff
changeset
|
3933 |
a5d1b1383dea
Upstream: fixed cache corruption and socket leaks with aio_write.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6853
diff
changeset
|
3934 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
|
3935 |
a5d1b1383dea
Upstream: fixed cache corruption and socket leaks with aio_write.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6853
diff
changeset
|
3936 /* |
a5d1b1383dea
Upstream: fixed cache corruption and socket leaks with aio_write.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6853
diff
changeset
|
3937 * 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
|
3938 * 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
|
3939 */ |
a5d1b1383dea
Upstream: fixed cache corruption and socket leaks with aio_write.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6853
diff
changeset
|
3940 |
a5d1b1383dea
Upstream: fixed cache corruption and socket leaks with aio_write.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6853
diff
changeset
|
3941 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
|
3942 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
|
3943 return; |
a5d1b1383dea
Upstream: fixed cache corruption and socket leaks with aio_write.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6853
diff
changeset
|
3944 } |
a5d1b1383dea
Upstream: fixed cache corruption and socket leaks with aio_write.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6853
diff
changeset
|
3945 } |
a5d1b1383dea
Upstream: fixed cache corruption and socket leaks with aio_write.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6853
diff
changeset
|
3946 |
6443
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3947 if (p->writing) { |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3948 return; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3949 } |
6876
a5d1b1383dea
Upstream: fixed cache corruption and socket leaks with aio_write.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6853
diff
changeset
|
3950 |
6443
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3951 #endif |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3952 |
479 | 3953 if (u->peer.connection) { |
3954 | |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3955 if (u->store) { |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3956 |
2463 | 3957 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
|
3958 |
5298
a7b2db9119e0
Upstream: replaced u->pipe->temp_file with p->temp_file.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5297
diff
changeset
|
3959 tf = p->temp_file; |
4469
24c0dca04eb9
Fix for proxy_store leaving temporary files for subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4464
diff
changeset
|
3960 |
2445
3c6af1fb7586
proxy/fastcgi_store did not delete incomplete files
Igor Sysoev <igor@sysoev.ru>
parents:
2441
diff
changeset
|
3961 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
|
3962 && (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
|
3963 && (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
|
3964 || 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
|
3965 { |
3c6af1fb7586
proxy/fastcgi_store did not delete incomplete files
Igor Sysoev <igor@sysoev.ru>
parents:
2441
diff
changeset
|
3966 ngx_http_upstream_store(r, u); |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3967 } |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3968 } |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3969 } |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3970 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3971 #if (NGX_HTTP_CACHE) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3972 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3973 if (u->cacheable) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3974 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3975 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
|
3976 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
|
3977 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3978 } else if (p->upstream_eof) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3979 |
5298
a7b2db9119e0
Upstream: replaced u->pipe->temp_file with p->temp_file.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5297
diff
changeset
|
3980 tf = p->temp_file; |
4298
186f02886bed
Upstream: don't cache unfinished responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4197
diff
changeset
|
3981 |
5299
b779728b180c
Upstream: fixed store/cache of unfinished responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5298
diff
changeset
|
3982 if (p->length == -1 |
b779728b180c
Upstream: fixed store/cache of unfinished responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5298
diff
changeset
|
3983 && (u->headers_in.content_length_n == -1 |
b779728b180c
Upstream: fixed store/cache of unfinished responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5298
diff
changeset
|
3984 || u->headers_in.content_length_n |
b779728b180c
Upstream: fixed store/cache of unfinished responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5298
diff
changeset
|
3985 == 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
|
3986 { |
186f02886bed
Upstream: don't cache unfinished responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4197
diff
changeset
|
3987 ngx_http_file_cache_update(r, tf); |
186f02886bed
Upstream: don't cache unfinished responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4197
diff
changeset
|
3988 |
186f02886bed
Upstream: don't cache unfinished responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4197
diff
changeset
|
3989 } else { |
186f02886bed
Upstream: don't cache unfinished responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4197
diff
changeset
|
3990 ngx_http_file_cache_free(r->cache, tf); |
186f02886bed
Upstream: don't cache unfinished responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4197
diff
changeset
|
3991 } |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3992 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3993 } 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
|
3994 ngx_http_file_cache_free(r->cache, p->temp_file); |
479 | 3995 } |
3996 } | |
3997 | |
3998 #endif | |
3999 | |
4000 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
|
4001 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
483 | 4002 "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
|
4003 |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
4004 if (p->upstream_done |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
4005 || (p->upstream_eof && p->length == -1)) |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
4006 { |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
4007 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
|
4008 return; |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
4009 } |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
4010 |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
4011 if (p->upstream_eof) { |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
4012 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
|
4013 "upstream prematurely closed connection"); |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
4014 } |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
4015 |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
4016 ngx_http_upstream_finalize_request(r, u, NGX_HTTP_BAD_GATEWAY); |
479 | 4017 return; |
4018 } | |
4019 } | |
4020 | |
4021 if (p->downstream_error) { | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
4022 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
483 | 4023 "http upstream downstream error"); |
479 | 4024 |
2757
9cc973b46af1
get a full response if the response is cacheable or storable even
Igor Sysoev <igor@sysoev.ru>
parents:
2708
diff
changeset
|
4025 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
|
4026 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
479 | 4027 } |
4028 } | |
4029 } | |
4030 | |
4031 | |
487 | 4032 static void |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4033 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
|
4034 { |
1947
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
4035 size_t root; |
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
4036 time_t lm; |
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
4037 ngx_str_t path; |
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
4038 ngx_temp_file_t *tf; |
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
4039 ngx_ext_rename_file_t ext; |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4040 |
1777 | 4041 tf = u->pipe->temp_file; |
4042 | |
4043 if (tf->file.fd == NGX_INVALID_FILE) { | |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4044 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4045 /* create file for empty 200 response */ |
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 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
|
4048 if (tf == NULL) { |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4049 return; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4050 } |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4051 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4052 tf->file.fd = NGX_INVALID_FILE; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4053 tf->file.log = r->connection->log; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4054 tf->path = u->conf->temp_path; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4055 tf->pool = r->pool; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4056 tf->persistent = 1; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4057 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4058 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
|
4059 tf->persistent, tf->clean, tf->access) |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4060 != NGX_OK) |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4061 { |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4062 return; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4063 } |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4064 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4065 u->pipe->temp_file = tf; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4066 } |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4067 |
1947
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
4068 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
|
4069 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
|
4070 ext.time = -1; |
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
4071 ext.create_path = 1; |
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
4072 ext.delete_file = 1; |
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
4073 ext.log = r->connection->log; |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4074 |
1705 | 4075 if (u->headers_in.last_modified) { |
4076 | |
6180
8b6fa4842133
Moved ngx_http_parse_time() to core, renamed accordingly.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6147
diff
changeset
|
4077 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
|
4078 u->headers_in.last_modified->value.len); |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4079 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4080 if (lm != NGX_ERROR) { |
1947
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
4081 ext.time = lm; |
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
4082 ext.fd = tf->file.fd; |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4083 } |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4084 } |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4085 |
1295
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
4086 if (u->conf->store_lengths == NULL) { |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
4087 |
5770
9de5820bb3e0
Upstream: ngx_http_upstream_store() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5757
diff
changeset
|
4088 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
|
4089 return; |
9de5820bb3e0
Upstream: ngx_http_upstream_store() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5757
diff
changeset
|
4090 } |
1295
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
4091 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
4092 } else { |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
4093 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
|
4094 u->conf->store_values->elts) |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
4095 == NULL) |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
4096 { |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
4097 return; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
4098 } |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
4099 } |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4100 |
3032
524ba56ba9f7
fix copy destination name length, introduced in r3025
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
4101 path.len--; |
524ba56ba9f7
fix copy destination name length, introduced in r3025
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
4102 |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4103 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
|
4104 "upstream stores \"%s\" to \"%s\"", |
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
4105 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
|
4106 |
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
4107 (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
|
4108 |
9de5820bb3e0
Upstream: ngx_http_upstream_store() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5757
diff
changeset
|
4109 u->store = 0; |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4110 } |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4111 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4112 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4113 static void |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
4114 ngx_http_upstream_dummy_handler(ngx_http_request_t *r, ngx_http_upstream_t *u) |
479 | 4115 { |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
4116 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
479 | 4117 "http upstream dummy handler"); |
4118 } | |
4119 | |
4120 | |
487 | 4121 static void |
4122 ngx_http_upstream_next(ngx_http_request_t *r, ngx_http_upstream_t *u, | |
4123 ngx_uint_t ft_type) | |
479 | 4124 { |
5832
d09b689911ac
Upstream: limited next_upstream time and tries (ticket #544).
Roman Arutyunyan <arut@nginx.com>
parents:
5827
diff
changeset
|
4125 ngx_msec_t timeout; |
884 | 4126 ngx_uint_t status, state; |
479 | 4127 |
4128 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
884 | 4129 "http next upstream, %xi", ft_type); |
479 | 4130 |
5132
9bcf89ca78d2
Upstream: only call peer.free() if peer.get() selected a peer.
Ruslan Ermilov <ru@nginx.com>
parents:
5121
diff
changeset
|
4131 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
|
4132 |
5231
05c53652e7b4
Upstream: http_403 support in proxy_next_upstream (and friends).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5217
diff
changeset
|
4133 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
|
4134 || 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
|
4135 { |
5132
9bcf89ca78d2
Upstream: only call peer.free() if peer.get() selected a peer.
Ruslan Ermilov <ru@nginx.com>
parents:
5121
diff
changeset
|
4136 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
|
4137 |
5132
9bcf89ca78d2
Upstream: only call peer.free() if peer.get() selected a peer.
Ruslan Ermilov <ru@nginx.com>
parents:
5121
diff
changeset
|
4138 } else { |
9bcf89ca78d2
Upstream: only call peer.free() if peer.get() selected a peer.
Ruslan Ermilov <ru@nginx.com>
parents:
5121
diff
changeset
|
4139 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
|
4140 } |
9bcf89ca78d2
Upstream: only call peer.free() if peer.get() selected a peer.
Ruslan Ermilov <ru@nginx.com>
parents:
5121
diff
changeset
|
4141 |
1378 | 4142 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
|
4143 u->peer.sockaddr = NULL; |
1378 | 4144 } |
525 | 4145 |
479 | 4146 if (ft_type == NGX_HTTP_UPSTREAM_FT_TIMEOUT) { |
4147 ngx_log_error(NGX_LOG_ERR, r->connection->log, NGX_ETIMEDOUT, | |
4148 "upstream timed out"); | |
4149 } | |
577 | 4150 |
6466
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4151 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
|
4152 /* TODO: inform balancer instead */ |
70a45a504905
Workaround for cpu hog on errors with cached connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4114
diff
changeset
|
4153 u->peer.tries++; |
6466
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4154 } |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4155 |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4156 switch (ft_type) { |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4157 |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4158 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
|
4159 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
|
4160 status = NGX_HTTP_GATEWAY_TIME_OUT; |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4161 break; |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4162 |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4163 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
|
4164 status = NGX_HTTP_INTERNAL_SERVER_ERROR; |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4165 break; |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4166 |
7130
882ad033d43c
Upstream: fixed $upstream_status when upstream returns 503/504.
Ruslan Ermilov <ru@nginx.com>
parents:
7126
diff
changeset
|
4167 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
|
4168 status = NGX_HTTP_SERVICE_UNAVAILABLE; |
882ad033d43c
Upstream: fixed $upstream_status when upstream returns 503/504.
Ruslan Ermilov <ru@nginx.com>
parents:
7126
diff
changeset
|
4169 break; |
882ad033d43c
Upstream: fixed $upstream_status when upstream returns 503/504.
Ruslan Ermilov <ru@nginx.com>
parents:
7126
diff
changeset
|
4170 |
6466
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4171 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
|
4172 status = NGX_HTTP_FORBIDDEN; |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4173 break; |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4174 |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4175 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
|
4176 status = NGX_HTTP_NOT_FOUND; |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4177 break; |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4178 |
6966
fa56ab75cffc
Upstream: allow recovery from "429 Too Many Requests" response.
Piotr Sikora <piotrsikora@google.com>
parents:
6961
diff
changeset
|
4179 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
|
4180 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
|
4181 break; |
fa56ab75cffc
Upstream: allow recovery from "429 Too Many Requests" response.
Piotr Sikora <piotrsikora@google.com>
parents:
6961
diff
changeset
|
4182 |
6466
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4183 /* |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4184 * 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
|
4185 * never reach here |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4186 */ |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4187 |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4188 default: |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4189 status = NGX_HTTP_BAD_GATEWAY; |
479 | 4190 } |
4191 | |
583 | 4192 if (r->connection->error) { |
479 | 4193 ngx_http_upstream_finalize_request(r, u, |
4194 NGX_HTTP_CLIENT_CLOSED_REQUEST); | |
4195 return; | |
4196 } | |
4197 | |
6466
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4198 u->state->status = status; |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4199 |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4200 timeout = u->conf->next_upstream_timeout; |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4201 |
6467
91c8d990fb45
Upstream: proxy_next_upstream non_idempotent.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6466
diff
changeset
|
4202 if (u->request_sent |
91c8d990fb45
Upstream: proxy_next_upstream non_idempotent.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6466
diff
changeset
|
4203 && (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
|
4204 { |
91c8d990fb45
Upstream: proxy_next_upstream non_idempotent.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6466
diff
changeset
|
4205 ft_type |= NGX_HTTP_UPSTREAM_FT_NON_IDEMPOTENT; |
91c8d990fb45
Upstream: proxy_next_upstream non_idempotent.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6466
diff
changeset
|
4206 } |
91c8d990fb45
Upstream: proxy_next_upstream non_idempotent.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6466
diff
changeset
|
4207 |
6466
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4208 if (u->peer.tries == 0 |
6467
91c8d990fb45
Upstream: proxy_next_upstream non_idempotent.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6466
diff
changeset
|
4209 || ((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
|
4210 || (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
|
4211 || (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
|
4212 { |
479 | 4213 #if (NGX_HTTP_CACHE) |
4214 | |
6466
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4215 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
|
4216 && ((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
|
4217 { |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4218 ngx_int_t rc; |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4219 |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4220 rc = u->reinit_request(r); |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4221 |
7126
77fe752b4586
Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7125
diff
changeset
|
4222 if (rc != NGX_OK) { |
77fe752b4586
Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7125
diff
changeset
|
4223 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
|
4224 return; |
77fe752b4586
Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7125
diff
changeset
|
4225 } |
77fe752b4586
Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7125
diff
changeset
|
4226 |
77fe752b4586
Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7125
diff
changeset
|
4227 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
|
4228 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
|
4229 |
77fe752b4586
Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7125
diff
changeset
|
4230 if (rc == NGX_DONE) { |
77fe752b4586
Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7125
diff
changeset
|
4231 return; |
77fe752b4586
Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7125
diff
changeset
|
4232 } |
77fe752b4586
Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7125
diff
changeset
|
4233 |
77fe752b4586
Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7125
diff
changeset
|
4234 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
|
4235 rc = NGX_HTTP_INTERNAL_SERVER_ERROR; |
479 | 4236 } |
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 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
|
4239 return; |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4240 } |
479 | 4241 #endif |
4242 | |
6466
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4243 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
|
4244 return; |
479 | 4245 } |
4246 | |
4247 if (u->peer.connection) { | |
4248 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
4249 "close http upstream connection: %d", | |
4250 u->peer.connection->fd); | |
577 | 4251 #if (NGX_HTTP_SSL) |
884 | 4252 |
577 | 4253 if (u->peer.connection->ssl) { |
884 | 4254 u->peer.connection->ssl->no_wait_shutdown = 1; |
4255 u->peer.connection->ssl->no_send_shutdown = 1; | |
4256 | |
4257 (void) ngx_ssl_shutdown(u->peer.connection); | |
577 | 4258 } |
4259 #endif | |
884 | 4260 |
4138
70e1ee2307f9
Fix of separate pool for upstream connections (r4117).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4124
diff
changeset
|
4261 if (u->peer.connection->pool) { |
70e1ee2307f9
Fix of separate pool for upstream connections (r4117).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4124
diff
changeset
|
4262 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
|
4263 } |
70e1ee2307f9
Fix of separate pool for upstream connections (r4117).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4124
diff
changeset
|
4264 |
479 | 4265 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
|
4266 u->peer.connection = NULL; |
479 | 4267 } |
4268 | |
4269 ngx_http_upstream_connect(r, u); | |
4270 } | |
4271 | |
4272 | |
487 | 4273 static void |
569 | 4274 ngx_http_upstream_cleanup(void *data) |
4275 { | |
4276 ngx_http_request_t *r = data; | |
4277 | |
4278 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
4279 "cleanup http upstream request: \"%V\"", &r->uri); | |
4280 | |
5167
85ee9d858dcb
Upstream: removed surplus ngx_resolve_name_done() call.
Valentin Bartenev <vbart@nginx.com>
parents:
5142
diff
changeset
|
4281 ngx_http_upstream_finalize_request(r, r->upstream, NGX_DONE); |
569 | 4282 } |
4283 | |
4284 | |
4285 static void | |
487 | 4286 ngx_http_upstream_finalize_request(ngx_http_request_t *r, |
4287 ngx_http_upstream_t *u, ngx_int_t rc) | |
479 | 4288 { |
6146
59fc60585f1e
Upstream: times to obtain header/response are stored as ngx_msec_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6125
diff
changeset
|
4289 ngx_uint_t flush; |
563 | 4290 |
483 | 4291 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
4292 "finalize http upstream request: %i", rc); | |
479 | 4293 |
5994
5abf5af257a7
Upstream: avoid duplicate finalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5992
diff
changeset
|
4294 if (u->cleanup == NULL) { |
5abf5af257a7
Upstream: avoid duplicate finalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5992
diff
changeset
|
4295 /* the request was already finalized */ |
5abf5af257a7
Upstream: avoid duplicate finalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5992
diff
changeset
|
4296 ngx_http_finalize_request(r, NGX_DONE); |
5abf5af257a7
Upstream: avoid duplicate finalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5992
diff
changeset
|
4297 return; |
5abf5af257a7
Upstream: avoid duplicate finalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5992
diff
changeset
|
4298 } |
5abf5af257a7
Upstream: avoid duplicate finalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5992
diff
changeset
|
4299 |
5abf5af257a7
Upstream: avoid duplicate finalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5992
diff
changeset
|
4300 *u->cleanup = NULL; |
5abf5af257a7
Upstream: avoid duplicate finalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5992
diff
changeset
|
4301 u->cleanup = NULL; |
569 | 4302 |
3169
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
4303 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
|
4304 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
|
4305 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
|
4306 } |
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
4307 |
6146
59fc60585f1e
Upstream: times to obtain header/response are stored as ngx_msec_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6125
diff
changeset
|
4308 if (u->state && u->state->response_time) { |
59fc60585f1e
Upstream: times to obtain header/response are stored as ngx_msec_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6125
diff
changeset
|
4309 u->state->response_time = ngx_current_msec - u->state->response_time; |
2402 | 4310 |
5169
f6bbe77794aa
Upstream: fixed $upstream_response_length without buffering.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5167
diff
changeset
|
4311 if (u->pipe && u->pipe->read_length) { |
6654
c131f20c9562
Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6594
diff
changeset
|
4312 u->state->bytes_received += u->pipe->read_length |
c131f20c9562
Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6594
diff
changeset
|
4313 - u->pipe->preread_size; |
2402 | 4314 u->state->response_length = u->pipe->read_length; |
4315 } | |
563 | 4316 } |
4317 | |
479 | 4318 u->finalize_request(r, rc); |
4319 | |
5132
9bcf89ca78d2
Upstream: only call peer.free() if peer.get() selected a peer.
Ruslan Ermilov <ru@nginx.com>
parents:
5121
diff
changeset
|
4320 if (u->peer.free && u->peer.sockaddr) { |
1658 | 4321 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
|
4322 u->peer.sockaddr = NULL; |
1658 | 4323 } |
884 | 4324 |
479 | 4325 if (u->peer.connection) { |
884 | 4326 |
577 | 4327 #if (NGX_HTTP_SSL) |
4328 | |
4329 /* TODO: do not shutdown persistent connection */ | |
4330 | |
4331 if (u->peer.connection->ssl) { | |
884 | 4332 |
4333 /* | |
4334 * We send the "close notify" shutdown alert to the upstream only | |
4335 * and do not wait its "close notify" shutdown alert. | |
4336 * It is acceptable according to the TLS standard. | |
4337 */ | |
4338 | |
4339 u->peer.connection->ssl->no_wait_shutdown = 1; | |
4340 | |
4341 (void) ngx_ssl_shutdown(u->peer.connection); | |
577 | 4342 } |
4343 #endif | |
884 | 4344 |
4345 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
4346 "close http upstream connection: %d", | |
4347 u->peer.connection->fd); | |
4348 | |
4138
70e1ee2307f9
Fix of separate pool for upstream connections (r4117).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4124
diff
changeset
|
4349 if (u->peer.connection->pool) { |
70e1ee2307f9
Fix of separate pool for upstream connections (r4117).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4124
diff
changeset
|
4350 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
|
4351 } |
70e1ee2307f9
Fix of separate pool for upstream connections (r4117).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4124
diff
changeset
|
4352 |
479 | 4353 ngx_close_connection(u->peer.connection); |
4354 } | |
4355 | |
483 | 4356 u->peer.connection = NULL; |
4357 | |
581 | 4358 if (u->pipe && u->pipe->temp_file) { |
479 | 4359 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
4360 "http upstream temp fd: %d", | |
581 | 4361 u->pipe->temp_file->file.fd); |
479 | 4362 } |
4363 | |
4469
24c0dca04eb9
Fix for proxy_store leaving temporary files for subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4464
diff
changeset
|
4364 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
|
4365 && 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
|
4366 { |
24c0dca04eb9
Fix for proxy_store leaving temporary files for subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4464
diff
changeset
|
4367 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
|
4368 == NGX_FILE_ERROR) |
24c0dca04eb9
Fix for proxy_store leaving temporary files for subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4464
diff
changeset
|
4369 { |
24c0dca04eb9
Fix for proxy_store leaving temporary files for subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4464
diff
changeset
|
4370 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
|
4371 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
|
4372 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
|
4373 } |
24c0dca04eb9
Fix for proxy_store leaving temporary files for subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4464
diff
changeset
|
4374 } |
24c0dca04eb9
Fix for proxy_store leaving temporary files for subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4464
diff
changeset
|
4375 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4376 #if (NGX_HTTP_CACHE) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4377 |
3940
22f3e9197096
revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents:
3934
diff
changeset
|
4378 if (r->cache) { |
22f3e9197096
revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents:
3934
diff
changeset
|
4379 |
22f3e9197096
revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents:
3934
diff
changeset
|
4380 if (u->cacheable) { |
22f3e9197096
revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents:
3934
diff
changeset
|
4381 |
22f3e9197096
revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents:
3934
diff
changeset
|
4382 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
|
4383 time_t valid; |
22f3e9197096
revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents:
3934
diff
changeset
|
4384 |
22f3e9197096
revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents:
3934
diff
changeset
|
4385 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
|
4386 |
22f3e9197096
revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents:
3934
diff
changeset
|
4387 if (valid) { |
22f3e9197096
revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents:
3934
diff
changeset
|
4388 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
|
4389 r->cache->error = rc; |
22f3e9197096
revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents:
3934
diff
changeset
|
4390 } |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4391 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4392 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4393 |
3711
ce6ba077c270
several changes in cache cleanup handling:
Igor Sysoev <igor@sysoev.ru>
parents:
3709
diff
changeset
|
4394 ngx_http_file_cache_free(r->cache, u->pipe->temp_file); |
479 | 4395 } |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4396 |
479 | 4397 #endif |
4398 | |
6909
5850fed24639
Upstream: read handler cleared on upstream finalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6906
diff
changeset
|
4399 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
|
4400 |
515 | 4401 if (rc == NGX_DECLINED) { |
4402 return; | |
4403 } | |
4404 | |
483 | 4405 r->connection->log->action = "sending to client"; |
4406 | |
5303
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
4407 if (!u->header_sent |
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
4408 || 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
|
4409 || rc == NGX_HTTP_CLIENT_CLOSED_REQUEST) |
4151
3549db8ceaf2
Cache: fix for sending of stale responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4143
diff
changeset
|
4410 { |
5303
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
4411 ngx_http_finalize_request(r, rc); |
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
4412 return; |
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
4413 } |
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
4414 |
5304
d3eab5e2df5f
Upstream: no last buffer on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5303
diff
changeset
|
4415 flush = 0; |
d3eab5e2df5f
Upstream: no last buffer on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5303
diff
changeset
|
4416 |
d3eab5e2df5f
Upstream: no last buffer on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5303
diff
changeset
|
4417 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) { |
d3eab5e2df5f
Upstream: no last buffer on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5303
diff
changeset
|
4418 rc = NGX_ERROR; |
d3eab5e2df5f
Upstream: no last buffer on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5303
diff
changeset
|
4419 flush = 1; |
5303
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
4420 } |
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
4421 |
7188
93abb5a855d6
Upstream: fixed "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7174
diff
changeset
|
4422 if (r->header_only |
93abb5a855d6
Upstream: fixed "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7174
diff
changeset
|
4423 || (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
|
4424 { |
5303
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
4425 ngx_http_finalize_request(r, rc); |
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
4426 return; |
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
4427 } |
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
4428 |
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
4429 if (rc == 0) { |
7230
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
4430 |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
4431 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
|
4432 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
|
4433 return; |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
4434 } |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
4435 |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
4436 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
|
4437 |
d3eab5e2df5f
Upstream: no last buffer on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5303
diff
changeset
|
4438 } else if (flush) { |
d3eab5e2df5f
Upstream: no last buffer on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5303
diff
changeset
|
4439 r->keepalive = 0; |
d3eab5e2df5f
Upstream: no last buffer on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5303
diff
changeset
|
4440 rc = ngx_http_send_special(r, NGX_HTTP_FLUSH); |
479 | 4441 } |
4442 | |
4443 ngx_http_finalize_request(r, rc); | |
4444 } | |
4445 | |
4446 | |
509 | 4447 static ngx_int_t |
4448 ngx_http_upstream_process_header_line(ngx_http_request_t *r, ngx_table_elt_t *h, | |
4449 ngx_uint_t offset) | |
577 | 4450 { |
509 | 4451 ngx_table_elt_t **ph; |
577 | 4452 |
509 | 4453 ph = (ngx_table_elt_t **) ((char *) &r->upstream->headers_in + offset); |
4454 | |
4455 if (*ph == NULL) { | |
4456 *ph = h; | |
4457 } | |
4458 | |
4459 return NGX_OK; | |
4460 } | |
4461 | |
4462 | |
4463 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
|
4464 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
|
4465 ngx_uint_t offset) |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4466 { |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4467 return NGX_OK; |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4468 } |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4469 |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4470 |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4471 static ngx_int_t |
4117
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
4472 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
|
4473 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
|
4474 { |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
4475 ngx_http_upstream_t *u; |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
4476 |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
4477 u = r->upstream; |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
4478 |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
4479 u->headers_in.content_length = h; |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
4480 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
|
4481 |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
4482 return NGX_OK; |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
4483 } |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
4484 |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
4485 |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
4486 static ngx_int_t |
5732
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
4487 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
|
4488 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
|
4489 { |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
4490 ngx_http_upstream_t *u; |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
4491 |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
4492 u = r->upstream; |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
4493 |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
4494 u->headers_in.last_modified = h; |
7093
acc2cddc7b45
Upstream: unconditional parsing of last_modified_time.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7077
diff
changeset
|
4495 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
|
4496 h->value.len); |
5732
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
4497 |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
4498 return NGX_OK; |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
4499 } |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
4500 |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
4501 |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
4502 static ngx_int_t |
3669
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
4503 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
|
4504 ngx_uint_t offset) |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
4505 { |
5677
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4506 ngx_array_t *pa; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4507 ngx_table_elt_t **ph; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4508 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
|
4509 |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
4510 u = r->upstream; |
5677
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4511 pa = &u->headers_in.cookies; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4512 |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4513 if (pa->elts == NULL) { |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4514 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
|
4515 { |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4516 return NGX_ERROR; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4517 } |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4518 } |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4519 |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4520 ph = ngx_array_push(pa); |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4521 if (ph == NULL) { |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4522 return NGX_ERROR; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4523 } |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4524 |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4525 *ph = h; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4526 |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4527 #if (NGX_HTTP_CACHE) |
3669
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
4528 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
|
4529 u->cacheable = 0; |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
4530 } |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
4531 #endif |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
4532 |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
4533 return NGX_OK; |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
4534 } |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
4535 |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
4536 |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
4537 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
|
4538 ngx_http_upstream_process_cache_control(ngx_http_request_t *r, |
509 | 4539 ngx_table_elt_t *h, ngx_uint_t offset) |
4540 { | |
2786
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4541 ngx_array_t *pa; |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4542 ngx_table_elt_t **ph; |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4543 ngx_http_upstream_t *u; |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4544 |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4545 u = r->upstream; |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4546 pa = &u->headers_in.cache_control; |
509 | 4547 |
4548 if (pa->elts == NULL) { | |
6474 | 4549 if (ngx_array_init(pa, r->pool, 2, sizeof(ngx_table_elt_t *)) != NGX_OK) |
4550 { | |
4551 return NGX_ERROR; | |
4552 } | |
509 | 4553 } |
4554 | |
4555 ph = ngx_array_push(pa); | |
4556 if (ph == NULL) { | |
4557 return NGX_ERROR; | |
4558 } | |
4559 | |
4560 *ph = h; | |
4561 | |
2708
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
4562 #if (NGX_HTTP_CACHE) |
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
4563 { |
5911
88d55e5934f7
Cache: add support for Cache-Control's s-maxage response directive.
Piotr Sikora <piotr@cloudflare.com>
parents:
5905
diff
changeset
|
4564 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
|
4565 ngx_int_t n; |
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
4566 |
2786
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4567 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
|
4568 return NGX_OK; |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4569 } |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4570 |
2669
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4571 if (r->cache == NULL) { |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4572 return NGX_OK; |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4573 } |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4574 |
5500
6a3ab6fdd70f
Upstream: Cache-Control preferred over Expires.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5489
diff
changeset
|
4575 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
|
4576 return NGX_OK; |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4577 } |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4578 |
5911
88d55e5934f7
Cache: add support for Cache-Control's s-maxage response directive.
Piotr Sikora <piotr@cloudflare.com>
parents:
5905
diff
changeset
|
4579 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
|
4580 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
|
4581 |
88d55e5934f7
Cache: add support for Cache-Control's s-maxage response directive.
Piotr Sikora <piotr@cloudflare.com>
parents:
5905
diff
changeset
|
4582 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
|
4583 || 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
|
4584 || 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
|
4585 { |
2786
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4586 u->cacheable = 0; |
2669
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4587 return NGX_OK; |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4588 } |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4589 |
5911
88d55e5934f7
Cache: add support for Cache-Control's s-maxage response directive.
Piotr Sikora <piotr@cloudflare.com>
parents:
5905
diff
changeset
|
4590 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
|
4591 offset = 9; |
88d55e5934f7
Cache: add support for Cache-Control's s-maxage response directive.
Piotr Sikora <piotr@cloudflare.com>
parents:
5905
diff
changeset
|
4592 |
88d55e5934f7
Cache: add support for Cache-Control's s-maxage response directive.
Piotr Sikora <piotr@cloudflare.com>
parents:
5905
diff
changeset
|
4593 if (p == NULL) { |
88d55e5934f7
Cache: add support for Cache-Control's s-maxage response directive.
Piotr Sikora <piotr@cloudflare.com>
parents:
5905
diff
changeset
|
4594 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
|
4595 offset = 8; |
88d55e5934f7
Cache: add support for Cache-Control's s-maxage response directive.
Piotr Sikora <piotr@cloudflare.com>
parents:
5905
diff
changeset
|
4596 } |
2669
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4597 |
6905
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4598 if (p) { |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4599 n = 0; |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4600 |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4601 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
|
4602 if (*p == ',' || *p == ';' || *p == ' ') { |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4603 break; |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4604 } |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4605 |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4606 if (*p >= '0' && *p <= '9') { |
7067
e3723f2a11b7
Parenthesized ASCII-related calculations.
Valentin Bartenev <vbart@nginx.com>
parents:
7042
diff
changeset
|
4607 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
|
4608 continue; |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4609 } |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4610 |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4611 u->cacheable = 0; |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4612 return NGX_OK; |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4613 } |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4614 |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4615 if (n == 0) { |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4616 u->cacheable = 0; |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4617 return NGX_OK; |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4618 } |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4619 |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4620 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
|
4621 } |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4622 |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4623 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
|
4624 23 - 1); |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4625 |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4626 if (p) { |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4627 n = 0; |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4628 |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4629 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
|
4630 if (*p == ',' || *p == ';' || *p == ' ') { |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4631 break; |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4632 } |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4633 |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4634 if (*p >= '0' && *p <= '9') { |
7067
e3723f2a11b7
Parenthesized ASCII-related calculations.
Valentin Bartenev <vbart@nginx.com>
parents:
7042
diff
changeset
|
4635 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
|
4636 continue; |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4637 } |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4638 |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4639 u->cacheable = 0; |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4640 return NGX_OK; |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4641 } |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4642 |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4643 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
|
4644 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
|
4645 } |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4646 |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4647 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
|
4648 |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4649 if (p) { |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4650 n = 0; |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4651 |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4652 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
|
4653 if (*p == ',' || *p == ';' || *p == ' ') { |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4654 break; |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4655 } |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4656 |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4657 if (*p >= '0' && *p <= '9') { |
7067
e3723f2a11b7
Parenthesized ASCII-related calculations.
Valentin Bartenev <vbart@nginx.com>
parents:
7042
diff
changeset
|
4658 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
|
4659 continue; |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4660 } |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4661 |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4662 u->cacheable = 0; |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4663 return NGX_OK; |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4664 } |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4665 |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4666 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
|
4667 } |
2708
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
4668 } |
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
4669 #endif |
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
4670 |
509 | 4671 return NGX_OK; |
4672 } | |
4673 | |
4674 | |
4675 static ngx_int_t | |
2666 | 4676 ngx_http_upstream_process_expires(ngx_http_request_t *r, ngx_table_elt_t *h, |
4677 ngx_uint_t offset) | |
4678 { | |
2786
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4679 ngx_http_upstream_t *u; |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4680 |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4681 u = r->upstream; |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4682 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
|
4683 |
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
4684 #if (NGX_HTTP_CACHE) |
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
4685 { |
2666 | 4686 time_t expires; |
4687 | |
2786
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4688 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
|
4689 return NGX_OK; |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4690 } |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4691 |
2666 | 4692 if (r->cache == NULL) { |
4693 return NGX_OK; | |
4694 } | |
4695 | |
4696 if (r->cache->valid_sec != 0) { | |
4697 return NGX_OK; | |
4698 } | |
4699 | |
6180
8b6fa4842133
Moved ngx_http_parse_time() to core, renamed accordingly.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6147
diff
changeset
|
4700 expires = ngx_parse_http_time(h->value.data, h->value.len); |
2666 | 4701 |
4702 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
|
4703 u->cacheable = 0; |
2666 | 4704 return NGX_OK; |
4705 } | |
4706 | |
4707 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
|
4708 } |
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
4709 #endif |
2666 | 4710 |
4711 return NGX_OK; | |
4712 } | |
4713 | |
4714 | |
4715 static ngx_int_t | |
2663
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4716 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
|
4717 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
|
4718 { |
2786
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4719 ngx_http_upstream_t *u; |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4720 |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4721 u = r->upstream; |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4722 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
|
4723 |
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
4724 #if (NGX_HTTP_CACHE) |
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
4725 { |
2663
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4726 u_char *p; |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4727 size_t len; |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4728 ngx_int_t n; |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4729 |
2786
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4730 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
|
4731 return NGX_OK; |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4732 } |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4733 |
2663
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4734 if (r->cache == NULL) { |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4735 return NGX_OK; |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4736 } |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4737 |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4738 len = h->value.len; |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4739 p = h->value.data; |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4740 |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4741 if (p[0] != '@') { |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4742 n = ngx_atoi(p, len); |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4743 |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4744 switch (n) { |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4745 case 0: |
2786
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4746 u->cacheable = 0; |
4546
4988fa232629
For the sake of case/switch code readability, 'fall through'
Maxim Konovalov <maxim@nginx.com>
parents:
4499
diff
changeset
|
4747 /* fall through */ |
4988fa232629
For the sake of case/switch code readability, 'fall through'
Maxim Konovalov <maxim@nginx.com>
parents:
4499
diff
changeset
|
4748 |
2663
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4749 case NGX_ERROR: |
2667 | 4750 return NGX_OK; |
2663
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4751 |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4752 default: |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4753 r->cache->valid_sec = ngx_time() + n; |
2667 | 4754 return NGX_OK; |
2663
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4755 } |
2667 | 4756 } |
4757 | |
4758 p++; | |
4759 len--; | |
4760 | |
4761 n = ngx_atoi(p, len); | |
4762 | |
4763 if (n != NGX_ERROR) { | |
4764 r->cache->valid_sec = n; | |
2663
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4765 } |
2708
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
4766 } |
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
4767 #endif |
2663
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4768 |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4769 return NGX_OK; |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4770 } |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4771 |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4772 |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4773 static ngx_int_t |
527 | 4774 ngx_http_upstream_process_limit_rate(ngx_http_request_t *r, ngx_table_elt_t *h, |
4775 ngx_uint_t offset) | |
577 | 4776 { |
4197
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4777 ngx_int_t n; |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4778 ngx_http_upstream_t *u; |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4779 |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4780 u = r->upstream; |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4781 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
|
4782 |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4783 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
|
4784 return NGX_OK; |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4785 } |
527 | 4786 |
4787 n = ngx_atoi(h->value.data, h->value.len); | |
4788 | |
4789 if (n != NGX_ERROR) { | |
4790 r->limit_rate = (size_t) n; | |
4791 } | |
4792 | |
4793 return NGX_OK; | |
4794 } | |
4795 | |
4796 | |
4797 static ngx_int_t | |
649 | 4798 ngx_http_upstream_process_buffering(ngx_http_request_t *r, ngx_table_elt_t *h, |
4799 ngx_uint_t offset) | |
4800 { | |
4197
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4801 u_char c0, c1, c2; |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4802 ngx_http_upstream_t *u; |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4803 |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4804 u = r->upstream; |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4805 |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4806 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
|
4807 return NGX_OK; |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4808 } |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4809 |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4810 if (u->conf->change_buffering) { |
649 | 4811 |
4812 if (h->value.len == 2) { | |
4813 c0 = ngx_tolower(h->value.data[0]); | |
4814 c1 = ngx_tolower(h->value.data[1]); | |
4815 | |
4816 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
|
4817 u->buffering = 0; |
649 | 4818 } |
4819 | |
4820 } else if (h->value.len == 3) { | |
4821 c0 = ngx_tolower(h->value.data[0]); | |
4822 c1 = ngx_tolower(h->value.data[1]); | |
4823 c2 = ngx_tolower(h->value.data[2]); | |
4824 | |
4825 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
|
4826 u->buffering = 1; |
649 | 4827 } |
4828 } | |
4829 } | |
4830 | |
4831 return NGX_OK; | |
4832 } | |
4833 | |
4834 | |
4835 static ngx_int_t | |
657 | 4836 ngx_http_upstream_process_charset(ngx_http_request_t *r, ngx_table_elt_t *h, |
4837 ngx_uint_t offset) | |
4838 { | |
4197
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4839 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
|
4840 return NGX_OK; |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4841 } |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4842 |
657 | 4843 r->headers_out.override_charset = &h->value; |
4844 | |
4845 return NGX_OK; | |
4846 } | |
4847 | |
4848 | |
4849 static ngx_int_t | |
4124
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4850 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
|
4851 ngx_uint_t offset) |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4852 { |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4853 r->upstream->headers_in.connection = h; |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4854 |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4855 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
|
4856 (u_char *) "close", 5 - 1) |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4857 != NULL) |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4858 { |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4859 r->upstream->headers_in.connection_close = 1; |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4860 } |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4861 |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4862 return NGX_OK; |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4863 } |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4864 |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4865 |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4866 static ngx_int_t |
4123
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4867 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
|
4868 ngx_table_elt_t *h, ngx_uint_t offset) |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4869 { |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4870 r->upstream->headers_in.transfer_encoding = h; |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4871 |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4872 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
|
4873 (u_char *) "chunked", 7 - 1) |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4874 != NULL) |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4875 { |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4876 r->upstream->headers_in.chunked = 1; |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4877 } |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4878 |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4879 return NGX_OK; |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4880 } |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4881 |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4882 |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4883 static ngx_int_t |
5877
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4884 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
|
4885 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
|
4886 { |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4887 ngx_http_upstream_t *u; |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4888 |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4889 u = r->upstream; |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4890 u->headers_in.vary = h; |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4891 |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4892 #if (NGX_HTTP_CACHE) |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4893 |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4894 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
|
4895 return NGX_OK; |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4896 } |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4897 |
5878
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5877
diff
changeset
|
4898 if (r->cache == NULL) { |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5877
diff
changeset
|
4899 return NGX_OK; |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5877
diff
changeset
|
4900 } |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5877
diff
changeset
|
4901 |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5877
diff
changeset
|
4902 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
|
4903 || (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
|
4904 { |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5877
diff
changeset
|
4905 u->cacheable = 0; |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5877
diff
changeset
|
4906 } |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5877
diff
changeset
|
4907 |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5877
diff
changeset
|
4908 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
|
4909 |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4910 #endif |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4911 |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4912 return NGX_OK; |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4913 } |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4914 |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4915 |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4916 static ngx_int_t |
509 | 4917 ngx_http_upstream_copy_header_line(ngx_http_request_t *r, ngx_table_elt_t *h, |
4918 ngx_uint_t offset) | |
4919 { | |
573 | 4920 ngx_table_elt_t *ho, **ph; |
509 | 4921 |
4922 ho = ngx_list_push(&r->headers_out.headers); | |
4923 if (ho == NULL) { | |
4924 return NGX_ERROR; | |
4925 } | |
4926 | |
4927 *ho = *h; | |
4928 | |
573 | 4929 if (offset) { |
4930 ph = (ngx_table_elt_t **) ((char *) &r->headers_out + offset); | |
4931 *ph = ho; | |
4932 } | |
4933 | |
509 | 4934 return NGX_OK; |
4935 } | |
4936 | |
4937 | |
4938 static ngx_int_t | |
4939 ngx_http_upstream_copy_multi_header_lines(ngx_http_request_t *r, | |
4940 ngx_table_elt_t *h, ngx_uint_t offset) | |
4941 { | |
4942 ngx_array_t *pa; | |
4943 ngx_table_elt_t *ho, **ph; | |
4944 | |
4945 pa = (ngx_array_t *) ((char *) &r->headers_out + offset); | |
4946 | |
4947 if (pa->elts == NULL) { | |
4948 if (ngx_array_init(pa, r->pool, 2, sizeof(ngx_table_elt_t *)) != NGX_OK) | |
4949 { | |
4950 return NGX_ERROR; | |
4951 } | |
4952 } | |
4953 | |
4954 ho = ngx_list_push(&r->headers_out.headers); | |
4955 if (ho == NULL) { | |
4956 return NGX_ERROR; | |
4957 } | |
4958 | |
4959 *ho = *h; | |
6986
0cdee26605f3
Cleaned up r->headers_out.headers allocation error handling.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6966
diff
changeset
|
4960 |
0cdee26605f3
Cleaned up r->headers_out.headers allocation error handling.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6966
diff
changeset
|
4961 ph = ngx_array_push(pa); |
0cdee26605f3
Cleaned up r->headers_out.headers allocation error handling.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6966
diff
changeset
|
4962 if (ph == NULL) { |
0cdee26605f3
Cleaned up r->headers_out.headers allocation error handling.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6966
diff
changeset
|
4963 return NGX_ERROR; |
0cdee26605f3
Cleaned up r->headers_out.headers allocation error handling.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6966
diff
changeset
|
4964 } |
0cdee26605f3
Cleaned up r->headers_out.headers allocation error handling.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6966
diff
changeset
|
4965 |
509 | 4966 *ph = ho; |
4967 | |
4968 return NGX_OK; | |
4969 } | |
4970 | |
4971 | |
4972 static ngx_int_t | |
4973 ngx_http_upstream_copy_content_type(ngx_http_request_t *r, ngx_table_elt_t *h, | |
4974 ngx_uint_t offset) | |
4975 { | |
657 | 4976 u_char *p, *last; |
4977 | |
4978 r->headers_out.content_type_len = h->value.len; | |
509 | 4979 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
|
4980 r->headers_out.content_type_lowcase = NULL; |
509 | 4981 |
657 | 4982 for (p = h->value.data; *p; p++) { |
4983 | |
4984 if (*p != ';') { | |
4985 continue; | |
4986 } | |
4987 | |
4988 last = p; | |
4989 | |
4990 while (*++p == ' ') { /* void */ } | |
4991 | |
1968 | 4992 if (*p == '\0') { |
4993 return NGX_OK; | |
4994 } | |
4995 | |
1107
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1098
diff
changeset
|
4996 if (ngx_strncasecmp(p, (u_char *) "charset=", 8) != 0) { |
657 | 4997 continue; |
4998 } | |
4999 | |
5000 p += 8; | |
5001 | |
5002 r->headers_out.content_type_len = last - h->value.data; | |
5003 | |
2244 | 5004 if (*p == '"') { |
5005 p++; | |
5006 } | |
5007 | |
5008 last = h->value.data + h->value.len; | |
5009 | |
5010 if (*(last - 1) == '"') { | |
5011 last--; | |
5012 } | |
5013 | |
5014 r->headers_out.charset.len = last - p; | |
657 | 5015 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
|
5016 |
c6c42497106c
fix segfault if upstream sends trailing ";" in "charset="
Igor Sysoev <igor@sysoev.ru>
parents:
1109
diff
changeset
|
5017 return NGX_OK; |
657 | 5018 } |
5019 | |
509 | 5020 return NGX_OK; |
5021 } | |
5022 | |
5023 | |
5024 static ngx_int_t | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5025 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
|
5026 ngx_uint_t offset) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5027 { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5028 ngx_table_elt_t *ho; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5029 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5030 ho = ngx_list_push(&r->headers_out.headers); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5031 if (ho == NULL) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5032 return NGX_ERROR; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5033 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5034 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5035 *ho = *h; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5036 |
3004
4121acaf7a04
fix handling "Last-Modified" and "Accept-Ranges" for upstream responses
Igor Sysoev <igor@sysoev.ru>
parents:
3003
diff
changeset
|
5037 r->headers_out.last_modified = ho; |
7093
acc2cddc7b45
Upstream: unconditional parsing of last_modified_time.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7077
diff
changeset
|
5038 r->headers_out.last_modified_time = |
5732
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
5039 r->upstream->headers_in.last_modified_time; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5040 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5041 return NGX_OK; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5042 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5043 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5044 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5045 static ngx_int_t |
509 | 5046 ngx_http_upstream_rewrite_location(ngx_http_request_t *r, ngx_table_elt_t *h, |
5047 ngx_uint_t offset) | |
5048 { | |
5049 ngx_int_t rc; | |
5050 ngx_table_elt_t *ho; | |
5051 | |
5052 ho = ngx_list_push(&r->headers_out.headers); | |
5053 if (ho == NULL) { | |
5054 return NGX_ERROR; | |
5055 } | |
5056 | |
5057 *ho = *h; | |
5058 | |
5059 if (r->upstream->rewrite_redirect) { | |
5060 rc = r->upstream->rewrite_redirect(r, ho, 0); | |
5061 | |
529 | 5062 if (rc == NGX_DECLINED) { |
5063 return NGX_OK; | |
5064 } | |
5065 | |
509 | 5066 if (rc == NGX_OK) { |
5067 r->headers_out.location = ho; | |
5068 | |
5069 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
5070 "rewritten location: \"%V\"", &ho->value); | |
5071 } | |
5072 | |
5073 return rc; | |
5074 } | |
5075 | |
1653
ea681a6a0c61
set r->headers_out.location for non-local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
5076 if (ho->value.data[0] != '/') { |
ea681a6a0c61
set r->headers_out.location for non-local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
5077 r->headers_out.location = ho; |
ea681a6a0c61
set r->headers_out.location for non-local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
5078 } |
ea681a6a0c61
set r->headers_out.location for non-local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
5079 |
509 | 5080 /* |
6853
c85dfd99a2dd
Fixed missing "Location" field with some relative redirects.
Ruslan Ermilov <ru@nginx.com>
parents:
6799
diff
changeset
|
5081 * 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
|
5082 * relative redirects in ngx_http_header_filter() |
509 | 5083 */ |
5084 | |
5085 return NGX_OK; | |
5086 } | |
5087 | |
5088 | |
5089 static ngx_int_t | |
5090 ngx_http_upstream_rewrite_refresh(ngx_http_request_t *r, ngx_table_elt_t *h, | |
5091 ngx_uint_t offset) | |
5092 { | |
5093 u_char *p; | |
5094 ngx_int_t rc; | |
5095 ngx_table_elt_t *ho; | |
5096 | |
5097 ho = ngx_list_push(&r->headers_out.headers); | |
5098 if (ho == NULL) { | |
5099 return NGX_ERROR; | |
5100 } | |
5101 | |
5102 *ho = *h; | |
5103 | |
5104 if (r->upstream->rewrite_redirect) { | |
5105 | |
1549 | 5106 p = ngx_strcasestrn(ho->value.data, "url=", 4 - 1); |
509 | 5107 |
5108 if (p) { | |
5109 rc = r->upstream->rewrite_redirect(r, ho, p + 4 - ho->value.data); | |
5110 | |
5111 } else { | |
5112 return NGX_OK; | |
5113 } | |
5114 | |
529 | 5115 if (rc == NGX_DECLINED) { |
5116 return NGX_OK; | |
5117 } | |
5118 | |
509 | 5119 if (rc == NGX_OK) { |
1654 | 5120 r->headers_out.refresh = ho; |
5121 | |
509 | 5122 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
5123 "rewritten refresh: \"%V\"", &ho->value); | |
5124 } | |
5125 | |
5126 return rc; | |
5127 } | |
5128 | |
1654 | 5129 r->headers_out.refresh = ho; |
5130 | |
509 | 5131 return NGX_OK; |
5132 } | |
5133 | |
5134 | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5135 static ngx_int_t |
4464
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
5136 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
|
5137 ngx_uint_t offset) |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
5138 { |
4650
b38fea6f9a15
Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents:
4572
diff
changeset
|
5139 ngx_int_t rc; |
4464
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
5140 ngx_table_elt_t *ho; |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
5141 |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
5142 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
|
5143 if (ho == NULL) { |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
5144 return NGX_ERROR; |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
5145 } |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
5146 |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
5147 *ho = *h; |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
5148 |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
5149 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
|
5150 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
|
5151 |
b38fea6f9a15
Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents:
4572
diff
changeset
|
5152 if (rc == NGX_DECLINED) { |
b38fea6f9a15
Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents:
4572
diff
changeset
|
5153 return NGX_OK; |
b38fea6f9a15
Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents:
4572
diff
changeset
|
5154 } |
b38fea6f9a15
Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents:
4572
diff
changeset
|
5155 |
b38fea6f9a15
Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents:
4572
diff
changeset
|
5156 #if (NGX_DEBUG) |
b38fea6f9a15
Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents:
4572
diff
changeset
|
5157 if (rc == NGX_OK) { |
b38fea6f9a15
Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents:
4572
diff
changeset
|
5158 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
|
5159 "rewritten cookie: \"%V\"", &ho->value); |
b38fea6f9a15
Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents:
4572
diff
changeset
|
5160 } |
b38fea6f9a15
Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents:
4572
diff
changeset
|
5161 #endif |
b38fea6f9a15
Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents:
4572
diff
changeset
|
5162 |
b38fea6f9a15
Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents:
4572
diff
changeset
|
5163 return rc; |
4464
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
5164 } |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
5165 |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
5166 return NGX_OK; |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
5167 } |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
5168 |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
5169 |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
5170 static ngx_int_t |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5171 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
|
5172 ngx_table_elt_t *h, ngx_uint_t offset) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5173 { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5174 ngx_table_elt_t *ho; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5175 |
5874
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
5176 if (r->upstream->conf->force_ranges) { |
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
5177 return NGX_OK; |
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
5178 } |
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
5179 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5180 #if (NGX_HTTP_CACHE) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5181 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5182 if (r->cached) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5183 r->allow_ranges = 1; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5184 return NGX_OK; |
5621
345e4fd4bb64
Range filter: single_range flag in request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5581
diff
changeset
|
5185 } |
345e4fd4bb64
Range filter: single_range flag in request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5581
diff
changeset
|
5186 |
345e4fd4bb64
Range filter: single_range flag in request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5581
diff
changeset
|
5187 if (r->upstream->cacheable) { |
345e4fd4bb64
Range filter: single_range flag in request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5581
diff
changeset
|
5188 r->allow_ranges = 1; |
345e4fd4bb64
Range filter: single_range flag in request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5581
diff
changeset
|
5189 r->single_range = 1; |
345e4fd4bb64
Range filter: single_range flag in request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5581
diff
changeset
|
5190 return NGX_OK; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5191 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5192 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5193 #endif |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5194 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5195 ho = ngx_list_push(&r->headers_out.headers); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5196 if (ho == NULL) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5197 return NGX_ERROR; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5198 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5199 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5200 *ho = *h; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5201 |
3004
4121acaf7a04
fix handling "Last-Modified" and "Accept-Ranges" for upstream responses
Igor Sysoev <igor@sysoev.ru>
parents:
3003
diff
changeset
|
5202 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
|
5203 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5204 return NGX_OK; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5205 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5206 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5207 |
509 | 5208 #if (NGX_HTTP_GZIP) |
5209 | |
5210 static ngx_int_t | |
5211 ngx_http_upstream_copy_content_encoding(ngx_http_request_t *r, | |
5212 ngx_table_elt_t *h, ngx_uint_t offset) | |
5213 { | |
5214 ngx_table_elt_t *ho; | |
5215 | |
5216 ho = ngx_list_push(&r->headers_out.headers); | |
5217 if (ho == NULL) { | |
5218 return NGX_ERROR; | |
5219 } | |
5220 | |
5221 *ho = *h; | |
5222 | |
5223 r->headers_out.content_encoding = ho; | |
5224 | |
5225 return NGX_OK; | |
5226 } | |
5227 | |
5228 #endif | |
5229 | |
5230 | |
487 | 5231 static ngx_int_t |
573 | 5232 ngx_http_upstream_add_variables(ngx_conf_t *cf) |
479 | 5233 { |
880 | 5234 ngx_http_variable_t *var, *v; |
479 | 5235 |
573 | 5236 for (v = ngx_http_upstream_vars; v->name.len; v++) { |
5237 var = ngx_http_add_variable(cf, &v->name, v->flags); | |
5238 if (var == NULL) { | |
5239 return NGX_ERROR; | |
5240 } | |
5241 | |
637 | 5242 var->get_handler = v->get_handler; |
573 | 5243 var->data = v->data; |
5244 } | |
5245 | |
479 | 5246 return NGX_OK; |
5247 } | |
509 | 5248 |
5249 | |
573 | 5250 static ngx_int_t |
1181 | 5251 ngx_http_upstream_addr_variable(ngx_http_request_t *r, |
5252 ngx_http_variable_value_t *v, uintptr_t data) | |
5253 { | |
5254 u_char *p; | |
5255 size_t len; | |
5256 ngx_uint_t i; | |
5257 ngx_http_upstream_state_t *state; | |
5258 | |
5259 v->valid = 1; | |
1565 | 5260 v->no_cacheable = 0; |
1181 | 5261 v->not_found = 0; |
5262 | |
5263 if (r->upstream_states == NULL || r->upstream_states->nelts == 0) { | |
5264 v->not_found = 1; | |
5265 return NGX_OK; | |
5266 } | |
5267 | |
5268 len = 0; | |
5269 state = r->upstream_states->elts; | |
5270 | |
5271 for (i = 0; i < r->upstream_states->nelts; i++) { | |
5272 if (state[i].peer) { | |
5273 len += state[i].peer->len + 2; | |
5274 | |
5275 } else { | |
5276 len += 3; | |
5277 } | |
5278 } | |
5279 | |
2049 | 5280 p = ngx_pnalloc(r->pool, len); |
1181 | 5281 if (p == NULL) { |
5282 return NGX_ERROR; | |
5283 } | |
5284 | |
5285 v->data = p; | |
5286 | |
5287 i = 0; | |
5288 | |
5289 for ( ;; ) { | |
5290 if (state[i].peer) { | |
5291 p = ngx_cpymem(p, state[i].peer->data, state[i].peer->len); | |
5292 } | |
5293 | |
5294 if (++i == r->upstream_states->nelts) { | |
5295 break; | |
5296 } | |
5297 | |
5298 if (state[i].peer) { | |
5299 *p++ = ','; | |
5300 *p++ = ' '; | |
5301 | |
5302 } else { | |
5303 *p++ = ' '; | |
5304 *p++ = ':'; | |
5305 *p++ = ' '; | |
5306 | |
5307 if (++i == r->upstream_states->nelts) { | |
5308 break; | |
5309 } | |
5310 | |
5311 continue; | |
5312 } | |
5313 } | |
5314 | |
5315 v->len = p - v->data; | |
5316 | |
5317 return NGX_OK; | |
5318 } | |
5319 | |
5320 | |
5321 static ngx_int_t | |
573 | 5322 ngx_http_upstream_status_variable(ngx_http_request_t *r, |
5323 ngx_http_variable_value_t *v, uintptr_t data) | |
5324 { | |
5325 u_char *p; | |
5326 size_t len; | |
5327 ngx_uint_t i; | |
5328 ngx_http_upstream_state_t *state; | |
5329 | |
5330 v->valid = 1; | |
1565 | 5331 v->no_cacheable = 0; |
573 | 5332 v->not_found = 0; |
5333 | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5334 if (r->upstream_states == NULL || r->upstream_states->nelts == 0) { |
573 | 5335 v->not_found = 1; |
5336 return NGX_OK; | |
5337 } | |
5338 | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5339 len = r->upstream_states->nelts * (3 + 2); |
573 | 5340 |
2049 | 5341 p = ngx_pnalloc(r->pool, len); |
573 | 5342 if (p == NULL) { |
5343 return NGX_ERROR; | |
5344 } | |
5345 | |
5346 v->data = p; | |
5347 | |
5348 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
|
5349 state = r->upstream_states->elts; |
573 | 5350 |
5351 for ( ;; ) { | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5352 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
|
5353 p = ngx_sprintf(p, "%ui", state[i].status); |
573 | 5354 |
5355 } else { | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5356 *p++ = '-'; |
573 | 5357 } |
5358 | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5359 if (++i == r->upstream_states->nelts) { |
573 | 5360 break; |
5361 } | |
5362 | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5363 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
|
5364 *p++ = ','; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5365 *p++ = ' '; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5366 |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5367 } else { |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5368 *p++ = ' '; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5369 *p++ = ':'; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5370 *p++ = ' '; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5371 |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5372 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
|
5373 break; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5374 } |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5375 |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5376 continue; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5377 } |
573 | 5378 } |
5379 | |
5380 v->len = p - v->data; | |
5381 | |
5382 return NGX_OK; | |
5383 } | |
5384 | |
5385 | |
5386 static ngx_int_t | |
5387 ngx_http_upstream_response_time_variable(ngx_http_request_t *r, | |
5388 ngx_http_variable_value_t *v, uintptr_t data) | |
5389 { | |
5390 u_char *p; | |
5391 size_t len; | |
5392 ngx_uint_t i; | |
889
a9a7e4b1a72b
the previous fix does not actually fix overflow
Igor Sysoev <igor@sysoev.ru>
parents:
888
diff
changeset
|
5393 ngx_msec_int_t ms; |
573 | 5394 ngx_http_upstream_state_t *state; |
5395 | |
5396 v->valid = 1; | |
1565 | 5397 v->no_cacheable = 0; |
573 | 5398 v->not_found = 0; |
5399 | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5400 if (r->upstream_states == NULL || r->upstream_states->nelts == 0) { |
573 | 5401 v->not_found = 1; |
5402 return NGX_OK; | |
5403 } | |
5404 | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5405 len = r->upstream_states->nelts * (NGX_TIME_T_LEN + 4 + 2); |
573 | 5406 |
2049 | 5407 p = ngx_pnalloc(r->pool, len); |
573 | 5408 if (p == NULL) { |
5409 return NGX_ERROR; | |
5410 } | |
5411 | |
5412 v->data = p; | |
5413 | |
5414 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
|
5415 state = r->upstream_states->elts; |
573 | 5416 |
5417 for ( ;; ) { | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5418 if (state[i].status) { |
5964
0a198a517eaf
Upstream: $upstream_header_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
5960
diff
changeset
|
5419 |
6147
74b6ef56ea56
Upstream: $upstream_connect_time.
Ruslan Ermilov <ru@nginx.com>
parents:
6146
diff
changeset
|
5420 if (data == 1 && state[i].header_time != (ngx_msec_t) -1) { |
6146
59fc60585f1e
Upstream: times to obtain header/response are stored as ngx_msec_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6125
diff
changeset
|
5421 ms = state[i].header_time; |
5964
0a198a517eaf
Upstream: $upstream_header_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
5960
diff
changeset
|
5422 |
6147
74b6ef56ea56
Upstream: $upstream_connect_time.
Ruslan Ermilov <ru@nginx.com>
parents:
6146
diff
changeset
|
5423 } else if (data == 2 && state[i].connect_time != (ngx_msec_t) -1) { |
74b6ef56ea56
Upstream: $upstream_connect_time.
Ruslan Ermilov <ru@nginx.com>
parents:
6146
diff
changeset
|
5424 ms = state[i].connect_time; |
74b6ef56ea56
Upstream: $upstream_connect_time.
Ruslan Ermilov <ru@nginx.com>
parents:
6146
diff
changeset
|
5425 |
5964
0a198a517eaf
Upstream: $upstream_header_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
5960
diff
changeset
|
5426 } else { |
6146
59fc60585f1e
Upstream: times to obtain header/response are stored as ngx_msec_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6125
diff
changeset
|
5427 ms = state[i].response_time; |
5964
0a198a517eaf
Upstream: $upstream_header_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
5960
diff
changeset
|
5428 } |
0a198a517eaf
Upstream: $upstream_header_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
5960
diff
changeset
|
5429 |
3515 | 5430 ms = ngx_max(ms, 0); |
5368
cd46297325bd
Upstream: fixed $upstream_response_time format specifiers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5353
diff
changeset
|
5431 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
|
5432 |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5433 } else { |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5434 *p++ = '-'; |
573 | 5435 } |
5436 | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5437 if (++i == r->upstream_states->nelts) { |
573 | 5438 break; |
5439 } | |
5440 | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5441 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
|
5442 *p++ = ','; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5443 *p++ = ' '; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5444 |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5445 } else { |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5446 *p++ = ' '; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5447 *p++ = ':'; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5448 *p++ = ' '; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5449 |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5450 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
|
5451 break; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5452 } |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5453 |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5454 continue; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5455 } |
573 | 5456 } |
5457 | |
5458 v->len = p - v->data; | |
5459 | |
5460 return NGX_OK; | |
5461 } | |
5462 | |
5463 | |
2402 | 5464 static ngx_int_t |
5465 ngx_http_upstream_response_length_variable(ngx_http_request_t *r, | |
5466 ngx_http_variable_value_t *v, uintptr_t data) | |
5467 { | |
5468 u_char *p; | |
5469 size_t len; | |
5470 ngx_uint_t i; | |
5471 ngx_http_upstream_state_t *state; | |
5472 | |
5473 v->valid = 1; | |
5474 v->no_cacheable = 0; | |
5475 v->not_found = 0; | |
5476 | |
5477 if (r->upstream_states == NULL || r->upstream_states->nelts == 0) { | |
5478 v->not_found = 1; | |
5479 return NGX_OK; | |
5480 } | |
5481 | |
5482 len = r->upstream_states->nelts * (NGX_OFF_T_LEN + 2); | |
5483 | |
5484 p = ngx_pnalloc(r->pool, len); | |
5485 if (p == NULL) { | |
5486 return NGX_ERROR; | |
5487 } | |
5488 | |
5489 v->data = p; | |
5490 | |
5491 i = 0; | |
5492 state = r->upstream_states->elts; | |
5493 | |
5494 for ( ;; ) { | |
6654
c131f20c9562
Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6594
diff
changeset
|
5495 |
c131f20c9562
Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6594
diff
changeset
|
5496 if (data == 1) { |
c131f20c9562
Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6594
diff
changeset
|
5497 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
|
5498 |
c131f20c9562
Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6594
diff
changeset
|
5499 } else { |
c131f20c9562
Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6594
diff
changeset
|
5500 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
|
5501 } |
2402 | 5502 |
5503 if (++i == r->upstream_states->nelts) { | |
5504 break; | |
5505 } | |
5506 | |
5507 if (state[i].peer) { | |
5508 *p++ = ','; | |
5509 *p++ = ' '; | |
5510 | |
5511 } else { | |
5512 *p++ = ' '; | |
5513 *p++ = ':'; | |
5514 *p++ = ' '; | |
5515 | |
5516 if (++i == r->upstream_states->nelts) { | |
5517 break; | |
5518 } | |
5519 | |
5520 continue; | |
5521 } | |
5522 } | |
5523 | |
5524 v->len = p - v->data; | |
5525 | |
5526 return NGX_OK; | |
5527 } | |
5528 | |
5529 | |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6876
diff
changeset
|
5530 static ngx_int_t |
1162 | 5531 ngx_http_upstream_header_variable(ngx_http_request_t *r, |
5532 ngx_http_variable_value_t *v, uintptr_t data) | |
5533 { | |
5534 if (r->upstream == NULL) { | |
5535 v->not_found = 1; | |
5536 return NGX_OK; | |
5537 } | |
5538 | |
5539 return ngx_http_variable_unknown_header(v, (ngx_str_t *) data, | |
5540 &r->upstream->headers_in.headers.part, | |
5541 sizeof("upstream_http_") - 1); | |
5542 } | |
5543 | |
5544 | |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6876
diff
changeset
|
5545 static ngx_int_t |
7230
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
5546 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
|
5547 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
|
5548 { |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
5549 if (r->upstream == NULL) { |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
5550 v->not_found = 1; |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
5551 return NGX_OK; |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
5552 } |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
5553 |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
5554 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
|
5555 &r->upstream->headers_in.trailers.part, |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
5556 sizeof("upstream_trailer_") - 1); |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
5557 } |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
5558 |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
5559 |
098bbd076a2d
Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7220
diff
changeset
|
5560 static ngx_int_t |
5677
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5561 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
|
5562 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
|
5563 { |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5564 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
|
5565 |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5566 ngx_str_t cookie, s; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5567 |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5568 if (r->upstream == NULL) { |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5569 v->not_found = 1; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5570 return NGX_OK; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5571 } |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5572 |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5573 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
|
5574 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
|
5575 |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5576 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
|
5577 &s, &cookie) |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5578 == NGX_DECLINED) |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5579 { |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5580 v->not_found = 1; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5581 return NGX_OK; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5582 } |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5583 |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5584 v->len = cookie.len; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5585 v->valid = 1; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5586 v->no_cacheable = 0; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5587 v->not_found = 0; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5588 v->data = cookie.data; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5589 |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5590 return NGX_OK; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5591 } |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5592 |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5593 |
2952 | 5594 #if (NGX_HTTP_CACHE) |
5595 | |
6923
fbdaad9b0e7b
Added missing "static" specifiers found by gcc -Wtraditional.
Ruslan Ermilov <ru@nginx.com>
parents:
6922
diff
changeset
|
5596 static ngx_int_t |
2952 | 5597 ngx_http_upstream_cache_status(ngx_http_request_t *r, |
5598 ngx_http_variable_value_t *v, uintptr_t data) | |
5599 { | |
5600 ngx_uint_t n; | |
5601 | |
5602 if (r->upstream == NULL || r->upstream->cache_status == 0) { | |
5603 v->not_found = 1; | |
5604 return NGX_OK; | |
5605 } | |
5606 | |
5607 n = r->upstream->cache_status - 1; | |
5608 | |
5609 v->valid = 1; | |
5610 v->no_cacheable = 0; | |
5611 v->not_found = 0; | |
5612 v->len = ngx_http_cache_status[n].len; | |
5613 v->data = ngx_http_cache_status[n].data; | |
5614 | |
5615 return NGX_OK; | |
5616 } | |
5617 | |
5441
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5618 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5619 static ngx_int_t |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5620 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
|
5621 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
|
5622 { |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5623 u_char *p; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5624 |
5453
b7b8e2fa7ebd
Fixed null pointer dereference with $upstream_cache_last_modified.
Ruslan Ermilov <ru@nginx.com>
parents:
5441
diff
changeset
|
5625 if (r->upstream == NULL |
b7b8e2fa7ebd
Fixed null pointer dereference with $upstream_cache_last_modified.
Ruslan Ermilov <ru@nginx.com>
parents:
5441
diff
changeset
|
5626 || !r->upstream->conf->cache_revalidate |
5441
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5627 || r->upstream->cache_status != NGX_HTTP_CACHE_EXPIRED |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5628 || r->cache->last_modified == -1) |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5629 { |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5630 v->not_found = 1; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5631 return NGX_OK; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5632 } |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5633 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5634 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
|
5635 if (p == NULL) { |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5636 return NGX_ERROR; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5637 } |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5638 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5639 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
|
5640 v->valid = 1; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5641 v->no_cacheable = 0; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5642 v->not_found = 0; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5643 v->data = p; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5644 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5645 return NGX_OK; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5646 } |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5647 |
5738
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5648 |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5649 static ngx_int_t |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5650 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
|
5651 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
|
5652 { |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5653 if (r->upstream == NULL |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5654 || !r->upstream->conf->cache_revalidate |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5655 || 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
|
5656 || r->cache->etag.len == 0) |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5657 { |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5658 v->not_found = 1; |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5659 return NGX_OK; |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5660 } |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5661 |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5662 v->valid = 1; |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5663 v->no_cacheable = 0; |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5664 v->not_found = 0; |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5665 v->len = r->cache->etag.len; |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5666 v->data = r->cache->etag.data; |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5667 |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5668 return NGX_OK; |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5669 } |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5670 |
2952 | 5671 #endif |
5672 | |
5673 | |
651 | 5674 static char * |
5675 ngx_http_upstream(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy) | |
5676 { | |
884 | 5677 char *rv; |
5678 void *mconf; | |
5679 ngx_str_t *value; | |
5680 ngx_url_t u; | |
5681 ngx_uint_t m; | |
5682 ngx_conf_t pcf; | |
5683 ngx_http_module_t *module; | |
5684 ngx_http_conf_ctx_t *ctx, *http_ctx; | |
5685 ngx_http_upstream_srv_conf_t *uscf; | |
5686 | |
5687 ngx_memzero(&u, sizeof(ngx_url_t)); | |
5688 | |
5689 value = cf->args->elts; | |
5690 u.host = value[1]; | |
5691 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
|
5692 u.no_port = 1; |
884 | 5693 |
5694 uscf = ngx_http_upstream_add(cf, &u, NGX_HTTP_UPSTREAM_CREATE | |
5695 |NGX_HTTP_UPSTREAM_WEIGHT | |
6705 | 5696 |NGX_HTTP_UPSTREAM_MAX_CONNS |
884 | 5697 |NGX_HTTP_UPSTREAM_MAX_FAILS |
5698 |NGX_HTTP_UPSTREAM_FAIL_TIMEOUT | |
5699 |NGX_HTTP_UPSTREAM_DOWN | |
5700 |NGX_HTTP_UPSTREAM_BACKUP); | |
5701 if (uscf == NULL) { | |
5702 return NGX_CONF_ERROR; | |
5703 } | |
5704 | |
651 | 5705 |
5706 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)); | |
5707 if (ctx == NULL) { | |
5708 return NGX_CONF_ERROR; | |
5709 } | |
5710 | |
884 | 5711 http_ctx = cf->ctx; |
5712 ctx->main_conf = http_ctx->main_conf; | |
651 | 5713 |
5714 /* the upstream{}'s srv_conf */ | |
5715 | |
5716 ctx->srv_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module); | |
5717 if (ctx->srv_conf == NULL) { | |
5718 return NGX_CONF_ERROR; | |
5719 } | |
5720 | |
5721 ctx->srv_conf[ngx_http_upstream_module.ctx_index] = uscf; | |
5722 | |
884 | 5723 uscf->srv_conf = ctx->srv_conf; |
5724 | |
651 | 5725 |
5726 /* the upstream{}'s loc_conf */ | |
5727 | |
5728 ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module); | |
5729 if (ctx->loc_conf == NULL) { | |
5730 return NGX_CONF_ERROR; | |
5731 } | |
5732 | |
6379
cf5e822cf470
Dynamic modules: changed ngx_modules to cycle->modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6334
diff
changeset
|
5733 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
|
5734 if (cf->cycle->modules[m]->type != NGX_HTTP_MODULE) { |
651 | 5735 continue; |
5736 } | |
5737 | |
6379
cf5e822cf470
Dynamic modules: changed ngx_modules to cycle->modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6334
diff
changeset
|
5738 module = cf->cycle->modules[m]->ctx; |
651 | 5739 |
884 | 5740 if (module->create_srv_conf) { |
5741 mconf = module->create_srv_conf(cf); | |
5742 if (mconf == NULL) { | |
5743 return NGX_CONF_ERROR; | |
5744 } | |
5745 | |
6379
cf5e822cf470
Dynamic modules: changed ngx_modules to cycle->modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6334
diff
changeset
|
5746 ctx->srv_conf[cf->cycle->modules[m]->ctx_index] = mconf; |
884 | 5747 } |
5748 | |
651 | 5749 if (module->create_loc_conf) { |
5750 mconf = module->create_loc_conf(cf); | |
5751 if (mconf == NULL) { | |
5752 return NGX_CONF_ERROR; | |
5753 } | |
5754 | |
6379
cf5e822cf470
Dynamic modules: changed ngx_modules to cycle->modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6334
diff
changeset
|
5755 ctx->loc_conf[cf->cycle->modules[m]->ctx_index] = mconf; |
651 | 5756 } |
5757 } | |
5758 | |
5728
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5759 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
|
5760 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
|
5761 if (uscf->servers == NULL) { |
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5762 return NGX_CONF_ERROR; |
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5763 } |
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5764 |
651 | 5765 |
5766 /* parse inside upstream{} */ | |
5767 | |
5768 pcf = *cf; | |
5769 cf->ctx = ctx; | |
5770 cf->cmd_type = NGX_HTTP_UPS_CONF; | |
5771 | |
5772 rv = ngx_conf_parse(cf, NULL); | |
5773 | |
5774 *cf = pcf; | |
5775 | |
5776 if (rv != NGX_CONF_OK) { | |
5777 return rv; | |
5778 } | |
5779 | |
5728
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5780 if (uscf->servers->nelts == 0) { |
651 | 5781 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
5782 "no servers are inside upstream"); | |
5783 return NGX_CONF_ERROR; | |
5784 } | |
5785 | |
5786 return rv; | |
5787 } | |
5788 | |
5789 | |
5790 static char * | |
5791 ngx_http_upstream_server(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
5792 { | |
5793 ngx_http_upstream_srv_conf_t *uscf = conf; | |
5794 | |
884 | 5795 time_t fail_timeout; |
5796 ngx_str_t *value, s; | |
5797 ngx_url_t u; | |
6705 | 5798 ngx_int_t weight, max_conns, max_fails; |
884 | 5799 ngx_uint_t i; |
5800 ngx_http_upstream_server_t *us; | |
651 | 5801 |
884 | 5802 us = ngx_array_push(uscf->servers); |
5803 if (us == NULL) { | |
651 | 5804 return NGX_CONF_ERROR; |
5805 } | |
5806 | |
884 | 5807 ngx_memzero(us, sizeof(ngx_http_upstream_server_t)); |
5808 | |
651 | 5809 value = cf->args->elts; |
5810 | |
663 | 5811 weight = 1; |
6705 | 5812 max_conns = 0; |
884 | 5813 max_fails = 1; |
5814 fail_timeout = 10; | |
5815 | |
5816 for (i = 2; i < cf->args->nelts; i++) { | |
5817 | |
5818 if (ngx_strncmp(value[i].data, "weight=", 7) == 0) { | |
5819 | |
5820 if (!(uscf->flags & NGX_HTTP_UPSTREAM_WEIGHT)) { | |
5818
fe8bafab5b49
Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents:
5774
diff
changeset
|
5821 goto not_supported; |
884 | 5822 } |
5823 | |
5824 weight = ngx_atoi(&value[i].data[7], value[i].len - 7); | |
663 | 5825 |
5826 if (weight == NGX_ERROR || weight == 0) { | |
5827 goto invalid; | |
5828 } | |
5829 | |
884 | 5830 continue; |
5831 } | |
5832 | |
6705 | 5833 if (ngx_strncmp(value[i].data, "max_conns=", 10) == 0) { |
5834 | |
5835 if (!(uscf->flags & NGX_HTTP_UPSTREAM_MAX_CONNS)) { | |
5836 goto not_supported; | |
5837 } | |
5838 | |
5839 max_conns = ngx_atoi(&value[i].data[10], value[i].len - 10); | |
5840 | |
5841 if (max_conns == NGX_ERROR) { | |
5842 goto invalid; | |
5843 } | |
5844 | |
5845 continue; | |
5846 } | |
5847 | |
884 | 5848 if (ngx_strncmp(value[i].data, "max_fails=", 10) == 0) { |
5849 | |
5850 if (!(uscf->flags & NGX_HTTP_UPSTREAM_MAX_FAILS)) { | |
5818
fe8bafab5b49
Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents:
5774
diff
changeset
|
5851 goto not_supported; |
884 | 5852 } |
5853 | |
5854 max_fails = ngx_atoi(&value[i].data[10], value[i].len - 10); | |
5855 | |
5856 if (max_fails == NGX_ERROR) { | |
5857 goto invalid; | |
5858 } | |
5859 | |
5860 continue; | |
663 | 5861 } |
884 | 5862 |
5863 if (ngx_strncmp(value[i].data, "fail_timeout=", 13) == 0) { | |
5864 | |
5865 if (!(uscf->flags & NGX_HTTP_UPSTREAM_FAIL_TIMEOUT)) { | |
5818
fe8bafab5b49
Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents:
5774
diff
changeset
|
5866 goto not_supported; |
884 | 5867 } |
5868 | |
5869 s.len = value[i].len - 13; | |
5870 s.data = &value[i].data[13]; | |
5871 | |
5872 fail_timeout = ngx_parse_time(&s, 1); | |
5873 | |
4474 | 5874 if (fail_timeout == (time_t) NGX_ERROR) { |
884 | 5875 goto invalid; |
5876 } | |
5877 | |
5878 continue; | |
5879 } | |
5880 | |
5410
16b68c724438
Upstream: fixed "down" and "backup" parsing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5392
diff
changeset
|
5881 if (ngx_strcmp(value[i].data, "backup") == 0) { |
1378 | 5882 |
5883 if (!(uscf->flags & NGX_HTTP_UPSTREAM_BACKUP)) { | |
5818
fe8bafab5b49
Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents:
5774
diff
changeset
|
5884 goto not_supported; |
1378 | 5885 } |
5886 | |
5887 us->backup = 1; | |
5888 | |
5889 continue; | |
5890 } | |
5891 | |
5410
16b68c724438
Upstream: fixed "down" and "backup" parsing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5392
diff
changeset
|
5892 if (ngx_strcmp(value[i].data, "down") == 0) { |
884 | 5893 |
5894 if (!(uscf->flags & NGX_HTTP_UPSTREAM_DOWN)) { | |
5818
fe8bafab5b49
Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents:
5774
diff
changeset
|
5895 goto not_supported; |
884 | 5896 } |
5897 | |
5898 us->down = 1; | |
5899 | |
5900 continue; | |
5901 } | |
5902 | |
5903 goto invalid; | |
663 | 5904 } |
5905 | |
5728
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5906 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
|
5907 |
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5908 u.url = value[1]; |
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5909 u.default_port = 80; |
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5910 |
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5911 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
|
5912 if (u.err) { |
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5913 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
|
5914 "%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
|
5915 } |
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5916 |
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5917 return NGX_CONF_ERROR; |
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5918 } |
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5919 |
5717
efc84a5723b3
Upstream: generic hash module.
Roman Arutyunyan <arut@nginx.com>
parents:
5682
diff
changeset
|
5920 us->name = u.url; |
884 | 5921 us->addrs = u.addrs; |
5922 us->naddrs = u.naddrs; | |
5923 us->weight = weight; | |
6705 | 5924 us->max_conns = max_conns; |
884 | 5925 us->max_fails = max_fails; |
5926 us->fail_timeout = fail_timeout; | |
651 | 5927 |
5928 return NGX_CONF_OK; | |
663 | 5929 |
5930 invalid: | |
5931 | |
884 | 5932 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
5933 "invalid parameter \"%V\"", &value[i]); | |
663 | 5934 |
5935 return NGX_CONF_ERROR; | |
5818
fe8bafab5b49
Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents:
5774
diff
changeset
|
5936 |
fe8bafab5b49
Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents:
5774
diff
changeset
|
5937 not_supported: |
fe8bafab5b49
Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents:
5774
diff
changeset
|
5938 |
fe8bafab5b49
Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents:
5774
diff
changeset
|
5939 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
fe8bafab5b49
Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents:
5774
diff
changeset
|
5940 "balancing method does not support parameter \"%V\"", |
fe8bafab5b49
Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents:
5774
diff
changeset
|
5941 &value[i]); |
fe8bafab5b49
Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents:
5774
diff
changeset
|
5942 |
fe8bafab5b49
Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents:
5774
diff
changeset
|
5943 return NGX_CONF_ERROR; |
651 | 5944 } |
5945 | |
5946 | |
5947 ngx_http_upstream_srv_conf_t * | |
884 | 5948 ngx_http_upstream_add(ngx_conf_t *cf, ngx_url_t *u, ngx_uint_t flags) |
651 | 5949 { |
5950 ngx_uint_t i; | |
884 | 5951 ngx_http_upstream_server_t *us; |
651 | 5952 ngx_http_upstream_srv_conf_t *uscf, **uscfp; |
5953 ngx_http_upstream_main_conf_t *umcf; | |
5954 | |
884 | 5955 if (!(flags & NGX_HTTP_UPSTREAM_CREATE)) { |
5956 | |
1559
fe11e2a3946d
use pool instead of ngx_conf_t
Igor Sysoev <igor@sysoev.ru>
parents:
1558
diff
changeset
|
5957 if (ngx_parse_url(cf->pool, u) != NGX_OK) { |
651 | 5958 if (u->err) { |
5959 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
5960 "%s in upstream \"%V\"", u->err, &u->url); | |
5961 } | |
5962 | |
5963 return NULL; | |
5964 } | |
5965 } | |
5966 | |
5967 umcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_upstream_module); | |
5968 | |
5969 uscfp = umcf->upstreams.elts; | |
5970 | |
5971 for (i = 0; i < umcf->upstreams.nelts; i++) { | |
906 | 5972 |
5973 if (uscfp[i]->host.len != u->host.len | |
884 | 5974 || ngx_strncasecmp(uscfp[i]->host.data, u->host.data, u->host.len) |
5975 != 0) | |
5976 { | |
651 | 5977 continue; |
5978 } | |
5979 | |
884 | 5980 if ((flags & NGX_HTTP_UPSTREAM_CREATE) |
5981 && (uscfp[i]->flags & NGX_HTTP_UPSTREAM_CREATE)) | |
651 | 5982 { |
884 | 5983 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
5984 "duplicate upstream \"%V\"", &u->host); | |
5985 return NULL; | |
651 | 5986 } |
884 | 5987 |
5005
c9059bd5445b
Fixed "proxy_pass" with IP address and no port (ticket #276).
Ruslan Ermilov <ru@nginx.com>
parents:
4990
diff
changeset
|
5988 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
|
5989 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
906 | 5990 "upstream \"%V\" may not have port %d", |
5991 &u->host, u->port); | |
5992 return NULL; | |
5993 } | |
5994 | |
5005
c9059bd5445b
Fixed "proxy_pass" with IP address and no port (ticket #276).
Ruslan Ermilov <ru@nginx.com>
parents:
4990
diff
changeset
|
5995 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
|
5996 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, |
906 | 5997 "upstream \"%V\" may not have port %d in %s:%ui", |
5998 &u->host, uscfp[i]->port, | |
1489
56f1ea5baabb
u_char* is enough to keep file name
Igor Sysoev <igor@sysoev.ru>
parents:
1469
diff
changeset
|
5999 uscfp[i]->file_name, uscfp[i]->line); |
906 | 6000 return NULL; |
6001 } | |
6002 | |
5005
c9059bd5445b
Fixed "proxy_pass" with IP address and no port (ticket #276).
Ruslan Ermilov <ru@nginx.com>
parents:
4990
diff
changeset
|
6003 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
|
6004 && 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
|
6005 { |
906 | 6006 continue; |
884 | 6007 } |
6008 | |
4152
65c1c241d70e
Better handling of late upstream creation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4151
diff
changeset
|
6009 if (flags & NGX_HTTP_UPSTREAM_CREATE) { |
65c1c241d70e
Better handling of late upstream creation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4151
diff
changeset
|
6010 uscfp[i]->flags = flags; |
6787
640e1e778de6
Upstream: consistently initialize explicit upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6786
diff
changeset
|
6011 uscfp[i]->port = 0; |
4152
65c1c241d70e
Better handling of late upstream creation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4151
diff
changeset
|
6012 } |
65c1c241d70e
Better handling of late upstream creation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4151
diff
changeset
|
6013 |
884 | 6014 return uscfp[i]; |
651 | 6015 } |
6016 | |
6017 uscf = ngx_pcalloc(cf->pool, sizeof(ngx_http_upstream_srv_conf_t)); | |
6018 if (uscf == NULL) { | |
6019 return NULL; | |
6020 } | |
6021 | |
884 | 6022 uscf->flags = flags; |
651 | 6023 uscf->host = u->host; |
1489
56f1ea5baabb
u_char* is enough to keep file name
Igor Sysoev <igor@sysoev.ru>
parents:
1469
diff
changeset
|
6024 uscf->file_name = cf->conf_file->file.name.data; |
651 | 6025 uscf->line = cf->conf_file->line; |
906 | 6026 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
|
6027 uscf->no_port = u->no_port; |
884 | 6028 |
5977
26c127bab5ef
Upstream: detect port absence in fastcgi_pass with IP literal.
Ruslan Ermilov <ru@nginx.com>
parents:
5968
diff
changeset
|
6029 if (u->naddrs == 1 && (u->port || u->family == AF_UNIX)) { |
884 | 6030 uscf->servers = ngx_array_create(cf->pool, 1, |
6031 sizeof(ngx_http_upstream_server_t)); | |
6032 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
|
6033 return NULL; |
884 | 6034 } |
6035 | |
6036 us = ngx_array_push(uscf->servers); | |
6037 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
|
6038 return NULL; |
884 | 6039 } |
6040 | |
6041 ngx_memzero(us, sizeof(ngx_http_upstream_server_t)); | |
6042 | |
6043 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
|
6044 us->naddrs = 1; |
884 | 6045 } |
651 | 6046 |
6047 uscfp = ngx_array_push(&umcf->upstreams); | |
6048 if (uscfp == NULL) { | |
6049 return NULL; | |
6050 } | |
6051 | |
6052 *uscfp = uscf; | |
6053 | |
6054 return uscf; | |
6055 } | |
6056 | |
6057 | |
3271
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3198
diff
changeset
|
6058 char * |
3399 | 6059 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
|
6060 void *conf) |
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3198
diff
changeset
|
6061 { |
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3198
diff
changeset
|
6062 char *p = conf; |
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3198
diff
changeset
|
6063 |
5008
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6064 ngx_int_t rc; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6065 ngx_str_t *value; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6066 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
|
6067 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
|
6068 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
|
6069 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6070 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
|
6071 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6072 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
|
6073 return "is duplicate"; |
3271
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3198
diff
changeset
|
6074 } |
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3198
diff
changeset
|
6075 |
3272
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3271
diff
changeset
|
6076 value = cf->args->elts; |
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3271
diff
changeset
|
6077 |
6530
1d0e03db9f8e
Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6528
diff
changeset
|
6078 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
|
6079 *plocal = NULL; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6080 return NGX_CONF_OK; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6081 } |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6082 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6083 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
|
6084 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6085 ccv.cf = cf; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6086 ccv.value = &value[1]; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6087 ccv.complex_value = &cv; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6088 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6089 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
|
6090 return NGX_CONF_ERROR; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6091 } |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6092 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6093 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
|
6094 if (local == NULL) { |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6095 return NGX_CONF_ERROR; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6096 } |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6097 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6098 *plocal = local; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6099 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6100 if (cv.lengths) { |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6101 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
|
6102 if (local->value == NULL) { |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6103 return NGX_CONF_ERROR; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6104 } |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6105 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6106 *local->value = cv; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6107 |
6528
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6108 } else { |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6109 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
|
6110 if (local->addr == NULL) { |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6111 return NGX_CONF_ERROR; |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6112 } |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6113 |
6594
3c87b82b17d4
Upstream: support for port in proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6536
diff
changeset
|
6114 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
|
6115 value[1].len); |
6528
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6116 |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6117 switch (rc) { |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6118 case NGX_OK: |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6119 local->addr->name = value[1]; |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6120 break; |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6121 |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6122 case NGX_DECLINED: |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6123 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
|
6124 "invalid address \"%V\"", &value[1]); |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6125 /* fall through */ |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6126 |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6127 default: |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6128 return NGX_CONF_ERROR; |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6129 } |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6130 } |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6131 |
6530
1d0e03db9f8e
Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6528
diff
changeset
|
6132 if (cf->args->nelts > 2) { |
1d0e03db9f8e
Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6528
diff
changeset
|
6133 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
|
6134 #if (NGX_HAVE_TRANSPARENT_PROXY) |
7174
84e53e4735a4
Retain CAP_NET_RAW capability for transparent proxying.
Roman Arutyunyan <arut@nginx.com>
parents:
7166
diff
changeset
|
6135 ngx_core_conf_t *ccf; |
84e53e4735a4
Retain CAP_NET_RAW capability for transparent proxying.
Roman Arutyunyan <arut@nginx.com>
parents:
7166
diff
changeset
|
6136 |
84e53e4735a4
Retain CAP_NET_RAW capability for transparent proxying.
Roman Arutyunyan <arut@nginx.com>
parents:
7166
diff
changeset
|
6137 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
|
6138 ngx_core_module); |
84e53e4735a4
Retain CAP_NET_RAW capability for transparent proxying.
Roman Arutyunyan <arut@nginx.com>
parents:
7166
diff
changeset
|
6139 |
84e53e4735a4
Retain CAP_NET_RAW capability for transparent proxying.
Roman Arutyunyan <arut@nginx.com>
parents:
7166
diff
changeset
|
6140 ccf->transparent = 1; |
6530
1d0e03db9f8e
Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6528
diff
changeset
|
6141 local->transparent = 1; |
1d0e03db9f8e
Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6528
diff
changeset
|
6142 #else |
1d0e03db9f8e
Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6528
diff
changeset
|
6143 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
|
6144 "transparent proxying is not supported " |
1d0e03db9f8e
Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6528
diff
changeset
|
6145 "on this platform, ignored"); |
1d0e03db9f8e
Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6528
diff
changeset
|
6146 #endif |
1d0e03db9f8e
Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6528
diff
changeset
|
6147 } else { |
1d0e03db9f8e
Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6528
diff
changeset
|
6148 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
|
6149 "invalid parameter \"%V\"", &value[2]); |
1d0e03db9f8e
Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6528
diff
changeset
|
6150 return NGX_CONF_ERROR; |
1d0e03db9f8e
Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6528
diff
changeset
|
6151 } |
1d0e03db9f8e
Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6528
diff
changeset
|
6152 } |
1d0e03db9f8e
Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6528
diff
changeset
|
6153 |
6528
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6154 return NGX_CONF_OK; |
3271
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3198
diff
changeset
|
6155 } |
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3198
diff
changeset
|
6156 |
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3198
diff
changeset
|
6157 |
6528
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6158 static ngx_int_t |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6159 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
|
6160 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
|
6161 { |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6162 ngx_int_t rc; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6163 ngx_str_t val; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6164 ngx_addr_t *addr; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6165 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6166 if (local == NULL) { |
6528
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6167 u->peer.local = NULL; |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6168 return NGX_OK; |
5008
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6169 } |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6170 |
6530
1d0e03db9f8e
Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6528
diff
changeset
|
6171 #if (NGX_HAVE_TRANSPARENT_PROXY) |
1d0e03db9f8e
Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6528
diff
changeset
|
6172 u->peer.transparent = local->transparent; |
1d0e03db9f8e
Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6528
diff
changeset
|
6173 #endif |
1d0e03db9f8e
Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6528
diff
changeset
|
6174 |
5008
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6175 if (local->value == NULL) { |
6528
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6176 u->peer.local = local->addr; |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6177 return NGX_OK; |
5008
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6178 } |
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_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
|
6181 return NGX_ERROR; |
5008
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 if (val.len == 0) { |
6528
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6185 return NGX_OK; |
5008
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6186 } |
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 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
|
6189 if (addr == NULL) { |
6528
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6190 return NGX_ERROR; |
5008
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6191 } |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6192 |
6594
3c87b82b17d4
Upstream: support for port in proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6536
diff
changeset
|
6193 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
|
6194 if (rc == NGX_ERROR) { |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6195 return NGX_ERROR; |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6196 } |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6197 |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6198 if (rc != NGX_OK) { |
5008
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6199 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
|
6200 "invalid local address \"%V\"", &val); |
6528
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6201 return NGX_OK; |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6202 } |
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 addr->name = val; |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6205 u->peer.local = addr; |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6206 |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6207 return NGX_OK; |
5008
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6208 } |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6209 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6210 |
4328
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6211 char * |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6212 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
|
6213 void *conf) |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6214 { |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6215 char *p = conf; |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6216 |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6217 ngx_str_t *value; |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6218 ngx_array_t **a; |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6219 ngx_http_upstream_param_t *param; |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6220 |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6221 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
|
6222 |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6223 if (*a == NULL) { |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6224 *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
|
6225 if (*a == NULL) { |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6226 return NGX_CONF_ERROR; |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6227 } |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6228 } |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6229 |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6230 param = ngx_array_push(*a); |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6231 if (param == NULL) { |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6232 return NGX_CONF_ERROR; |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6233 } |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6234 |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6235 value = cf->args->elts; |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6236 |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6237 param->key = value[1]; |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6238 param->value = value[2]; |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6239 param->skip_empty = 0; |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6240 |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6241 if (cf->args->nelts == 4) { |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6242 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
|
6243 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
|
6244 "invalid parameter \"%V\"", &value[3]); |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6245 return NGX_CONF_ERROR; |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6246 } |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6247 |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6248 param->skip_empty = 1; |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6249 } |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6250 |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6251 return NGX_CONF_OK; |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6252 } |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6253 |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6254 |
1701
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6255 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
|
6256 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
|
6257 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
|
6258 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
|
6259 { |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6260 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
|
6261 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
|
6262 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
|
6263 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
|
6264 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6265 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
|
6266 && 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
|
6267 { |
4769
f88555d76886
Upstream: hide_headers/pass_headers inheritance fix.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4766
diff
changeset
|
6268 conf->hide_headers = prev->hide_headers; |
f88555d76886
Upstream: hide_headers/pass_headers inheritance fix.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4766
diff
changeset
|
6269 conf->pass_headers = prev->pass_headers; |
f88555d76886
Upstream: hide_headers/pass_headers inheritance fix.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4766
diff
changeset
|
6270 |
1701
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6271 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
|
6272 |
6744
7e5199f172fb
Upstream: hide_headers_hash inherited regardless of cache settings.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6705
diff
changeset
|
6273 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
|
6274 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
|
6275 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6276 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6277 } else { |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6278 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
|
6279 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
|
6280 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6281 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6282 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
|
6283 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
|
6284 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6285 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6286 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6287 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
|
6288 != NGX_OK) |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6289 { |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6290 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
|
6291 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6292 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6293 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
|
6294 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
|
6295 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
|
6296 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
|
6297 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6298 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6299 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
|
6300 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
|
6301 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
|
6302 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6303 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6304 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
|
6305 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6306 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
|
6307 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6308 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
|
6309 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6310 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
|
6311 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6312 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
|
6313 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
|
6314 goto exist; |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6315 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6316 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6317 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6318 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
|
6319 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
|
6320 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
|
6321 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6322 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6323 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
|
6324 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
|
6325 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
|
6326 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6327 exist: |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6328 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6329 continue; |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6330 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6331 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6332 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6333 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
|
6334 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6335 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
|
6336 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
|
6337 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6338 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
|
6339 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
|
6340 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6341 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
|
6342 continue; |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6343 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6344 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6345 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
|
6346 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
|
6347 break; |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6348 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6349 } |
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 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6352 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6353 hash->hash = &conf->hide_headers_hash; |
1706
9242e21d2f8d
style fix: remove trailing spaces
Igor Sysoev <igor@sysoev.ru>
parents:
1705
diff
changeset
|
6354 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
|
6355 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
|
6356 hash->temp_pool = NULL; |
1706
9242e21d2f8d
style fix: remove trailing spaces
Igor Sysoev <igor@sysoev.ru>
parents:
1705
diff
changeset
|
6357 |
6745
93121485c39b
Upstream: hide_headers_hash handling at http level.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6744
diff
changeset
|
6358 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
|
6359 return NGX_ERROR; |
93121485c39b
Upstream: hide_headers_hash handling at http level.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6744
diff
changeset
|
6360 } |
93121485c39b
Upstream: hide_headers_hash handling at http level.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6744
diff
changeset
|
6361 |
93121485c39b
Upstream: hide_headers_hash handling at http level.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6744
diff
changeset
|
6362 /* |
93121485c39b
Upstream: hide_headers_hash handling at http level.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6744
diff
changeset
|
6363 * 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
|
6364 * 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
|
6365 */ |
93121485c39b
Upstream: hide_headers_hash handling at http level.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6744
diff
changeset
|
6366 |
93121485c39b
Upstream: hide_headers_hash handling at http level.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6744
diff
changeset
|
6367 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
|
6368 && conf->hide_headers == prev->hide_headers |
93121485c39b
Upstream: hide_headers_hash handling at http level.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6744
diff
changeset
|
6369 && conf->pass_headers == prev->pass_headers) |
93121485c39b
Upstream: hide_headers_hash handling at http level.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6744
diff
changeset
|
6370 { |
93121485c39b
Upstream: hide_headers_hash handling at http level.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6744
diff
changeset
|
6371 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
|
6372 } |
93121485c39b
Upstream: hide_headers_hash handling at http level.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6744
diff
changeset
|
6373 |
93121485c39b
Upstream: hide_headers_hash handling at http level.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6744
diff
changeset
|
6374 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
|
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 |
509 | 6378 static void * |
6379 ngx_http_upstream_create_main_conf(ngx_conf_t *cf) | |
6380 { | |
6381 ngx_http_upstream_main_conf_t *umcf; | |
6382 | |
6383 umcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_upstream_main_conf_t)); | |
6384 if (umcf == NULL) { | |
6385 return NULL; | |
6386 } | |
6387 | |
651 | 6388 if (ngx_array_init(&umcf->upstreams, cf->pool, 4, |
6389 sizeof(ngx_http_upstream_srv_conf_t *)) | |
6390 != NGX_OK) | |
6391 { | |
2912
c7d57b539248
return NULL instead of NGX_CONF_ERROR on a create conf failure
Igor Sysoev <igor@sysoev.ru>
parents:
2882
diff
changeset
|
6392 return NULL; |
651 | 6393 } |
6394 | |
509 | 6395 return umcf; |
6396 } | |
6397 | |
6398 | |
6399 static char * | |
651 | 6400 ngx_http_upstream_init_main_conf(ngx_conf_t *cf, void *conf) |
509 | 6401 { |
6402 ngx_http_upstream_main_conf_t *umcf = conf; | |
6403 | |
651 | 6404 ngx_uint_t i; |
6405 ngx_array_t headers_in; | |
6406 ngx_hash_key_t *hk; | |
6407 ngx_hash_init_t hash; | |
884 | 6408 ngx_http_upstream_init_pt init; |
651 | 6409 ngx_http_upstream_header_t *header; |
6410 ngx_http_upstream_srv_conf_t **uscfp; | |
6411 | |
6412 uscfp = umcf->upstreams.elts; | |
6413 | |
6414 for (i = 0; i < umcf->upstreams.nelts; i++) { | |
884 | 6415 |
6416 init = uscfp[i]->peer.init_upstream ? uscfp[i]->peer.init_upstream: | |
6417 ngx_http_upstream_init_round_robin; | |
6418 | |
6419 if (init(cf, uscfp[i]) != NGX_OK) { | |
651 | 6420 return NGX_CONF_ERROR; |
6421 } | |
6422 } | |
649 | 6423 |
663 | 6424 |
884 | 6425 /* upstream_headers_in_hash */ |
6426 | |
649 | 6427 if (ngx_array_init(&headers_in, cf->temp_pool, 32, sizeof(ngx_hash_key_t)) |
6428 != NGX_OK) | |
509 | 6429 { |
6430 return NGX_CONF_ERROR; | |
6431 } | |
6432 | |
649 | 6433 for (header = ngx_http_upstream_headers_in; header->name.len; header++) { |
6434 hk = ngx_array_push(&headers_in); | |
6435 if (hk == NULL) { | |
6436 return NGX_CONF_ERROR; | |
6437 } | |
6438 | |
6439 hk->key = header->name; | |
6440 hk->key_hash = ngx_hash_key_lc(header->name.data, header->name.len); | |
6441 hk->value = header; | |
6442 } | |
6443 | |
6444 hash.hash = &umcf->headers_in_hash; | |
6445 hash.key = ngx_hash_key_lc; | |
6446 hash.max_size = 512; | |
751
bae59a740c40
align hash bucket size to cache line
Igor Sysoev <igor@sysoev.ru>
parents:
750
diff
changeset
|
6447 hash.bucket_size = ngx_align(64, ngx_cacheline_size); |
649 | 6448 hash.name = "upstream_headers_in_hash"; |
6449 hash.pool = cf->pool; | |
6450 hash.temp_pool = NULL; | |
6451 | |
6452 if (ngx_hash_init(&hash, headers_in.elts, headers_in.nelts) != NGX_OK) { | |
6453 return NGX_CONF_ERROR; | |
6454 } | |
509 | 6455 |
6456 return NGX_CONF_OK; | |
6457 } |