Mercurial > hg > nginx
annotate src/http/ngx_http_upstream.c @ 6923:fbdaad9b0e7b
Added missing "static" specifiers found by gcc -Wtraditional.
author | Ruslan Ermilov <ru@nginx.com> |
---|---|
date | Mon, 06 Mar 2017 11:09:47 +0300 |
parents | a72886067bbb |
children | 4cb4ffe06785 |
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); |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
58 static void ngx_http_upstream_process_body_in_memory(ngx_http_request_t *r, |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
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); |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6876
diff
changeset
|
169 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
|
170 ngx_http_variable_value_t *v, uintptr_t data); |
573 | 171 |
651 | 172 static char *ngx_http_upstream(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy); |
173 static char *ngx_http_upstream_server(ngx_conf_t *cf, ngx_command_t *cmd, | |
174 void *conf); | |
175 | |
6528
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
176 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
|
177 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
|
178 |
509 | 179 static void *ngx_http_upstream_create_main_conf(ngx_conf_t *cf); |
651 | 180 static char *ngx_http_upstream_init_main_conf(ngx_conf_t *cf, void *conf); |
509 | 181 |
577 | 182 #if (NGX_HTTP_SSL) |
591 | 183 static void ngx_http_upstream_ssl_init_connection(ngx_http_request_t *, |
184 ngx_http_upstream_t *u, ngx_connection_t *c); | |
577 | 185 static void ngx_http_upstream_ssl_handshake(ngx_connection_t *c); |
5660
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
186 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
|
187 ngx_http_upstream_t *u, ngx_connection_t *c); |
577 | 188 #endif |
189 | |
509 | 190 |
6922
a72886067bbb
Added missing static specifiers.
Eran Kornblau <erankor@gmail.com>
parents:
6909
diff
changeset
|
191 static ngx_http_upstream_header_t ngx_http_upstream_headers_in[] = { |
509 | 192 |
193 { ngx_string("Status"), | |
194 ngx_http_upstream_process_header_line, | |
195 offsetof(ngx_http_upstream_headers_in_t, status), | |
649 | 196 ngx_http_upstream_copy_header_line, 0, 0 }, |
509 | 197 |
198 { ngx_string("Content-Type"), | |
199 ngx_http_upstream_process_header_line, | |
200 offsetof(ngx_http_upstream_headers_in_t, content_type), | |
673 | 201 ngx_http_upstream_copy_content_type, 0, 1 }, |
509 | 202 |
203 { ngx_string("Content-Length"), | |
5731
02674312be45
Upstream: removed unused offset to content_length.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5730
diff
changeset
|
204 ngx_http_upstream_process_content_length, 0, |
4117
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
205 ngx_http_upstream_ignore_header_line, 0, 0 }, |
509 | 206 |
207 { ngx_string("Date"), | |
208 ngx_http_upstream_process_header_line, | |
209 offsetof(ngx_http_upstream_headers_in_t, date), | |
649 | 210 ngx_http_upstream_copy_header_line, |
211 offsetof(ngx_http_headers_out_t, date), 0 }, | |
509 | 212 |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
213 { ngx_string("Last-Modified"), |
5732
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
214 ngx_http_upstream_process_last_modified, 0, |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
215 ngx_http_upstream_copy_last_modified, 0, 0 }, |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
216 |
3037 | 217 { ngx_string("ETag"), |
218 ngx_http_upstream_process_header_line, | |
219 offsetof(ngx_http_upstream_headers_in_t, etag), | |
220 ngx_http_upstream_copy_header_line, | |
221 offsetof(ngx_http_headers_out_t, etag), 0 }, | |
222 | |
509 | 223 { ngx_string("Server"), |
224 ngx_http_upstream_process_header_line, | |
225 offsetof(ngx_http_upstream_headers_in_t, server), | |
649 | 226 ngx_http_upstream_copy_header_line, |
227 offsetof(ngx_http_headers_out_t, server), 0 }, | |
509 | 228 |
529 | 229 { ngx_string("WWW-Authenticate"), |
230 ngx_http_upstream_process_header_line, | |
231 offsetof(ngx_http_upstream_headers_in_t, www_authenticate), | |
232 ngx_http_upstream_copy_header_line, 0, 0 }, | |
233 | |
509 | 234 { ngx_string("Location"), |
2140
dce5ddef5af9
if upstream sent a location header without status use 302
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
235 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
|
236 offsetof(ngx_http_upstream_headers_in_t, location), |
515 | 237 ngx_http_upstream_rewrite_location, 0, 0 }, |
509 | 238 |
239 { ngx_string("Refresh"), | |
240 ngx_http_upstream_ignore_header_line, 0, | |
515 | 241 ngx_http_upstream_rewrite_refresh, 0, 0 }, |
242 | |
243 { ngx_string("Set-Cookie"), | |
5677
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
244 ngx_http_upstream_process_set_cookie, |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
245 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
|
246 ngx_http_upstream_rewrite_set_cookie, 0, 1 }, |
531 | 247 |
248 { ngx_string("Content-Disposition"), | |
249 ngx_http_upstream_ignore_header_line, 0, | |
250 ngx_http_upstream_copy_header_line, 0, 1 }, | |
509 | 251 |
252 { 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
|
253 ngx_http_upstream_process_cache_control, 0, |
509 | 254 ngx_http_upstream_copy_multi_header_lines, |
515 | 255 offsetof(ngx_http_headers_out_t, cache_control), 1 }, |
509 | 256 |
573 | 257 { ngx_string("Expires"), |
2666 | 258 ngx_http_upstream_process_expires, 0, |
573 | 259 ngx_http_upstream_copy_header_line, |
260 offsetof(ngx_http_headers_out_t, expires), 1 }, | |
261 | |
577 | 262 { ngx_string("Accept-Ranges"), |
263 ngx_http_upstream_process_header_line, | |
264 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
|
265 ngx_http_upstream_copy_allow_ranges, |
577 | 266 offsetof(ngx_http_headers_out_t, accept_ranges), 1 }, |
267 | |
6316
f44de0d12143
Upstream: fill r->headers_out.content_range from upstream response.
Roman Arutyunyan <arut@nginx.com>
parents:
6313
diff
changeset
|
268 { ngx_string("Content-Range"), |
f44de0d12143
Upstream: fill r->headers_out.content_range from upstream response.
Roman Arutyunyan <arut@nginx.com>
parents:
6313
diff
changeset
|
269 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
|
270 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
|
271 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
|
272 |
509 | 273 { ngx_string("Connection"), |
4124
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
274 ngx_http_upstream_process_connection, 0, |
515 | 275 ngx_http_upstream_ignore_header_line, 0, 0 }, |
509 | 276 |
641 | 277 { ngx_string("Keep-Alive"), |
278 ngx_http_upstream_ignore_header_line, 0, | |
279 ngx_http_upstream_ignore_header_line, 0, 0 }, | |
280 | |
5877
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
281 { ngx_string("Vary"), |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
282 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
|
283 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
|
284 |
509 | 285 { ngx_string("X-Powered-By"), |
286 ngx_http_upstream_ignore_header_line, 0, | |
649 | 287 ngx_http_upstream_copy_header_line, 0, 0 }, |
509 | 288 |
289 { ngx_string("X-Accel-Expires"), | |
2664 | 290 ngx_http_upstream_process_accel_expires, 0, |
649 | 291 ngx_http_upstream_copy_header_line, 0, 0 }, |
515 | 292 |
293 { ngx_string("X-Accel-Redirect"), | |
294 ngx_http_upstream_process_header_line, | |
295 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
|
296 ngx_http_upstream_copy_header_line, 0, 0 }, |
509 | 297 |
527 | 298 { ngx_string("X-Accel-Limit-Rate"), |
299 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
|
300 ngx_http_upstream_copy_header_line, 0, 0 }, |
527 | 301 |
649 | 302 { ngx_string("X-Accel-Buffering"), |
303 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
|
304 ngx_http_upstream_copy_header_line, 0, 0 }, |
649 | 305 |
657 | 306 { ngx_string("X-Accel-Charset"), |
307 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
|
308 ngx_http_upstream_copy_header_line, 0, 0 }, |
657 | 309 |
4123
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
310 { ngx_string("Transfer-Encoding"), |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
311 ngx_http_upstream_process_transfer_encoding, 0, |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
312 ngx_http_upstream_ignore_header_line, 0, 0 }, |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
313 |
509 | 314 #if (NGX_HTTP_GZIP) |
315 { ngx_string("Content-Encoding"), | |
316 ngx_http_upstream_process_header_line, | |
317 offsetof(ngx_http_upstream_headers_in_t, content_encoding), | |
515 | 318 ngx_http_upstream_copy_content_encoding, 0, 0 }, |
509 | 319 #endif |
320 | |
515 | 321 { ngx_null_string, NULL, 0, NULL, 0, 0 } |
509 | 322 }; |
479 | 323 |
324 | |
651 | 325 static ngx_command_t ngx_http_upstream_commands[] = { |
326 | |
327 { ngx_string("upstream"), | |
328 NGX_HTTP_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_TAKE1, | |
329 ngx_http_upstream, | |
330 0, | |
331 0, | |
332 NULL }, | |
333 | |
334 { ngx_string("server"), | |
884 | 335 NGX_HTTP_UPS_CONF|NGX_CONF_1MORE, |
651 | 336 ngx_http_upstream_server, |
337 NGX_HTTP_SRV_CONF_OFFSET, | |
338 0, | |
339 NULL }, | |
340 | |
341 ngx_null_command | |
342 }; | |
343 | |
344 | |
345 static ngx_http_module_t ngx_http_upstream_module_ctx = { | |
573 | 346 ngx_http_upstream_add_variables, /* preconfiguration */ |
509 | 347 NULL, /* postconfiguration */ |
348 | |
349 ngx_http_upstream_create_main_conf, /* create main configuration */ | |
651 | 350 ngx_http_upstream_init_main_conf, /* init main configuration */ |
479 | 351 |
352 NULL, /* create server configuration */ | |
353 NULL, /* merge server configuration */ | |
354 | |
355 NULL, /* create location configuration */ | |
356 NULL /* merge location configuration */ | |
357 }; | |
577 | 358 |
479 | 359 |
360 ngx_module_t ngx_http_upstream_module = { | |
509 | 361 NGX_MODULE_V1, |
479 | 362 &ngx_http_upstream_module_ctx, /* module context */ |
651 | 363 ngx_http_upstream_commands, /* module directives */ |
479 | 364 NGX_HTTP_MODULE, /* module type */ |
541 | 365 NULL, /* init master */ |
479 | 366 NULL, /* init module */ |
541 | 367 NULL, /* init process */ |
368 NULL, /* init thread */ | |
369 NULL, /* exit thread */ | |
370 NULL, /* exit process */ | |
371 NULL, /* exit master */ | |
372 NGX_MODULE_V1_PADDING | |
479 | 373 }; |
374 | |
375 | |
573 | 376 static ngx_http_variable_t ngx_http_upstream_vars[] = { |
377 | |
1181 | 378 { 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
|
379 ngx_http_upstream_addr_variable, 0, |
3898
bd1222fb0192
allow to use $upstream_... variables in SSI
Igor Sysoev <igor@sysoev.ru>
parents:
3879
diff
changeset
|
380 NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
1181 | 381 |
637 | 382 { 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
|
383 ngx_http_upstream_status_variable, 0, |
3898
bd1222fb0192
allow to use $upstream_... variables in SSI
Igor Sysoev <igor@sysoev.ru>
parents:
3879
diff
changeset
|
384 NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
573 | 385 |
6147
74b6ef56ea56
Upstream: $upstream_connect_time.
Ruslan Ermilov <ru@nginx.com>
parents:
6146
diff
changeset
|
386 { ngx_string("upstream_connect_time"), NULL, |
74b6ef56ea56
Upstream: $upstream_connect_time.
Ruslan Ermilov <ru@nginx.com>
parents:
6146
diff
changeset
|
387 ngx_http_upstream_response_time_variable, 2, |
74b6ef56ea56
Upstream: $upstream_connect_time.
Ruslan Ermilov <ru@nginx.com>
parents:
6146
diff
changeset
|
388 NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
74b6ef56ea56
Upstream: $upstream_connect_time.
Ruslan Ermilov <ru@nginx.com>
parents:
6146
diff
changeset
|
389 |
5964
0a198a517eaf
Upstream: $upstream_header_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
5960
diff
changeset
|
390 { ngx_string("upstream_header_time"), NULL, |
0a198a517eaf
Upstream: $upstream_header_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
5960
diff
changeset
|
391 ngx_http_upstream_response_time_variable, 1, |
0a198a517eaf
Upstream: $upstream_header_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
5960
diff
changeset
|
392 NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
0a198a517eaf
Upstream: $upstream_header_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
5960
diff
changeset
|
393 |
637 | 394 { 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
|
395 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
|
396 NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
573 | 397 |
2402 | 398 { ngx_string("upstream_response_length"), NULL, |
399 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
|
400 NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
2402 | 401 |
6654
c131f20c9562
Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6594
diff
changeset
|
402 { ngx_string("upstream_bytes_received"), NULL, |
c131f20c9562
Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6594
diff
changeset
|
403 ngx_http_upstream_response_length_variable, 1, |
c131f20c9562
Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6594
diff
changeset
|
404 NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
c131f20c9562
Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6594
diff
changeset
|
405 |
2957
b4f39842523b
fix building --without-http-cache, broken in r2953
Igor Sysoev <igor@sysoev.ru>
parents:
2953
diff
changeset
|
406 #if (NGX_HTTP_CACHE) |
b4f39842523b
fix building --without-http-cache, broken in r2953
Igor Sysoev <igor@sysoev.ru>
parents:
2953
diff
changeset
|
407 |
2952 | 408 { ngx_string("upstream_cache_status"), NULL, |
409 ngx_http_upstream_cache_status, 0, | |
3898
bd1222fb0192
allow to use $upstream_... variables in SSI
Igor Sysoev <igor@sysoev.ru>
parents:
3879
diff
changeset
|
410 NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
2952 | 411 |
5441
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
412 { ngx_string("upstream_cache_last_modified"), NULL, |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
413 ngx_http_upstream_cache_last_modified, 0, |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
414 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
|
415 |
5738
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
416 { ngx_string("upstream_cache_etag"), NULL, |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
417 ngx_http_upstream_cache_etag, 0, |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
418 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
|
419 |
2957
b4f39842523b
fix building --without-http-cache, broken in r2953
Igor Sysoev <igor@sysoev.ru>
parents:
2953
diff
changeset
|
420 #endif |
b4f39842523b
fix building --without-http-cache, broken in r2953
Igor Sysoev <igor@sysoev.ru>
parents:
2953
diff
changeset
|
421 |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6876
diff
changeset
|
422 { ngx_string("upstream_http_"), NULL, ngx_http_upstream_header_variable, |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6876
diff
changeset
|
423 0, NGX_HTTP_VAR_NOCACHEABLE|NGX_HTTP_VAR_PREFIX, 0 }, |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6876
diff
changeset
|
424 |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6876
diff
changeset
|
425 { ngx_string("upstream_cookie_"), NULL, ngx_http_upstream_cookie_variable, |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6876
diff
changeset
|
426 0, NGX_HTTP_VAR_NOCACHEABLE|NGX_HTTP_VAR_PREFIX, 0 }, |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6876
diff
changeset
|
427 |
637 | 428 { ngx_null_string, NULL, NULL, 0, 0, 0 } |
573 | 429 }; |
430 | |
431 | |
2268
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
432 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
|
433 { 500, NGX_HTTP_UPSTREAM_FT_HTTP_500 }, |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
434 { 502, NGX_HTTP_UPSTREAM_FT_HTTP_502 }, |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
435 { 503, NGX_HTTP_UPSTREAM_FT_HTTP_503 }, |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
436 { 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
|
437 { 403, NGX_HTTP_UPSTREAM_FT_HTTP_403 }, |
2268
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
438 { 404, NGX_HTTP_UPSTREAM_FT_HTTP_404 }, |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
439 { 0, 0 } |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
440 }; |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
441 |
2875
6e1941b321b7
proxy_cache_methods and fastcgi_cache_methods
Igor Sysoev <igor@sysoev.ru>
parents:
2874
diff
changeset
|
442 |
6e1941b321b7
proxy_cache_methods and fastcgi_cache_methods
Igor Sysoev <igor@sysoev.ru>
parents:
2874
diff
changeset
|
443 ngx_conf_bitmask_t ngx_http_upstream_cache_method_mask[] = { |
6439 | 444 { ngx_string("GET"), NGX_HTTP_GET }, |
445 { ngx_string("HEAD"), NGX_HTTP_HEAD }, | |
446 { ngx_string("POST"), NGX_HTTP_POST }, | |
447 { ngx_null_string, 0 } | |
2875
6e1941b321b7
proxy_cache_methods and fastcgi_cache_methods
Igor Sysoev <igor@sysoev.ru>
parents:
2874
diff
changeset
|
448 }; |
6e1941b321b7
proxy_cache_methods and fastcgi_cache_methods
Igor Sysoev <igor@sysoev.ru>
parents:
2874
diff
changeset
|
449 |
6e1941b321b7
proxy_cache_methods and fastcgi_cache_methods
Igor Sysoev <igor@sysoev.ru>
parents:
2874
diff
changeset
|
450 |
3667
12bd9e26fadb
use shared ngx_http_upstream_ignore_headers_masks[]
Igor Sysoev <igor@sysoev.ru>
parents:
3527
diff
changeset
|
451 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
|
452 { 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
|
453 { 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
|
454 { 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
|
455 { 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
|
456 { 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
|
457 { 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
|
458 { 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
|
459 { 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
|
460 { 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
|
461 { ngx_null_string, 0 } |
12bd9e26fadb
use shared ngx_http_upstream_ignore_headers_masks[]
Igor Sysoev <igor@sysoev.ru>
parents:
3527
diff
changeset
|
462 }; |
12bd9e26fadb
use shared ngx_http_upstream_ignore_headers_masks[]
Igor Sysoev <igor@sysoev.ru>
parents:
3527
diff
changeset
|
463 |
12bd9e26fadb
use shared ngx_http_upstream_ignore_headers_masks[]
Igor Sysoev <igor@sysoev.ru>
parents:
3527
diff
changeset
|
464 |
3006
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
465 ngx_int_t |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
466 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
|
467 { |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
468 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
|
469 |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
470 u = r->upstream; |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
471 |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
472 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
|
473 r->main->count++; |
3006
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
474 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
|
475 } |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
476 |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
477 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
|
478 if (u == NULL) { |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
479 return NGX_ERROR; |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
480 } |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
481 |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
482 r->upstream = u; |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
483 |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
484 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
|
485 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
|
486 |
3056
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
487 #if (NGX_HTTP_CACHE) |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
488 r->cache = NULL; |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
489 #endif |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
490 |
4117
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
491 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
|
492 u->headers_in.last_modified_time = -1; |
4117
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
493 |
3006
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
494 return NGX_OK; |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
495 } |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
496 |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
3004
diff
changeset
|
497 |
487 | 498 void |
499 ngx_http_upstream_init(ngx_http_request_t *r) | |
479 | 500 { |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
501 ngx_connection_t *c; |
479 | 502 |
503 c = r->connection; | |
504 | |
505 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
506 "http init upstream, client timer: %d", c->read->timer_set); | |
507 | |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
6242
diff
changeset
|
508 #if (NGX_HTTP_V2) |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
6242
diff
changeset
|
509 if (r->stream) { |
5121
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
5113
diff
changeset
|
510 ngx_http_upstream_init_request(r); |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
5113
diff
changeset
|
511 return; |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
5113
diff
changeset
|
512 } |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
5113
diff
changeset
|
513 #endif |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
5113
diff
changeset
|
514 |
479 | 515 if (c->read->timer_set) { |
516 ngx_del_timer(c->read); | |
517 } | |
518 | |
519 if (ngx_event_flags & NGX_USE_CLEAR_EVENT) { | |
520 | |
521 if (!c->write->active) { | |
531 | 522 if (ngx_add_event(c->write, NGX_WRITE_EVENT, NGX_CLEAR_EVENT) |
523 == NGX_ERROR) | |
479 | 524 { |
525 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | |
526 return; | |
527 } | |
528 } | |
529 } | |
530 | |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
531 ngx_http_upstream_init_request(r); |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
532 } |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
533 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
534 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
535 static void |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
536 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
|
537 { |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
538 ngx_str_t *host; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
539 ngx_uint_t i; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
540 ngx_resolver_ctx_t *ctx, temp; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
541 ngx_http_cleanup_t *cln; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
542 ngx_http_upstream_t *u; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
543 ngx_http_core_loc_conf_t *clcf; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
544 ngx_http_upstream_srv_conf_t *uscf, **uscfp; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
545 ngx_http_upstream_main_conf_t *umcf; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
546 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
547 if (r->aio) { |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
548 return; |
537 | 549 } |
509 | 550 |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
551 u = r->upstream; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
552 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
553 #if (NGX_HTTP_CACHE) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
554 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
555 if (u->conf->cache) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
556 ngx_int_t rc; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
557 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
558 rc = ngx_http_upstream_cache(r, u); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
559 |
3055
92b6cfaa3c27
fix sending a cached file using AIO
Igor Sysoev <igor@sysoev.ru>
parents:
3053
diff
changeset
|
560 if (rc == NGX_BUSY) { |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
561 r->write_event_handler = ngx_http_upstream_init_request; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
562 return; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
563 } |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
564 |
3055
92b6cfaa3c27
fix sending a cached file using AIO
Igor Sysoev <igor@sysoev.ru>
parents:
3053
diff
changeset
|
565 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
|
566 |
5827
54e9b83d00f0
Upstream: avoided directly terminating the connection.
FengGu <flygoast@126.com>
parents:
5818
diff
changeset
|
567 if (rc == NGX_ERROR) { |
54e9b83d00f0
Upstream: avoided directly terminating the connection.
FengGu <flygoast@126.com>
parents:
5818
diff
changeset
|
568 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
|
569 return; |
54e9b83d00f0
Upstream: avoided directly terminating the connection.
FengGu <flygoast@126.com>
parents:
5818
diff
changeset
|
570 } |
54e9b83d00f0
Upstream: avoided directly terminating the connection.
FengGu <flygoast@126.com>
parents:
5818
diff
changeset
|
571 |
6242
0e3a45ec2a3a
Upstream: fixed cache send error handling.
Roman Arutyunyan <arut@nginx.com>
parents:
6180
diff
changeset
|
572 if (rc == NGX_OK) { |
0e3a45ec2a3a
Upstream: fixed cache send error handling.
Roman Arutyunyan <arut@nginx.com>
parents:
6180
diff
changeset
|
573 rc = ngx_http_upstream_cache_send(r, u); |
0e3a45ec2a3a
Upstream: fixed cache send error handling.
Roman Arutyunyan <arut@nginx.com>
parents:
6180
diff
changeset
|
574 |
0e3a45ec2a3a
Upstream: fixed cache send error handling.
Roman Arutyunyan <arut@nginx.com>
parents:
6180
diff
changeset
|
575 if (rc == NGX_DONE) { |
0e3a45ec2a3a
Upstream: fixed cache send error handling.
Roman Arutyunyan <arut@nginx.com>
parents:
6180
diff
changeset
|
576 return; |
0e3a45ec2a3a
Upstream: fixed cache send error handling.
Roman Arutyunyan <arut@nginx.com>
parents:
6180
diff
changeset
|
577 } |
0e3a45ec2a3a
Upstream: fixed cache send error handling.
Roman Arutyunyan <arut@nginx.com>
parents:
6180
diff
changeset
|
578 |
0e3a45ec2a3a
Upstream: fixed cache send error handling.
Roman Arutyunyan <arut@nginx.com>
parents:
6180
diff
changeset
|
579 if (rc == NGX_HTTP_UPSTREAM_INVALID_HEADER) { |
0e3a45ec2a3a
Upstream: fixed cache send error handling.
Roman Arutyunyan <arut@nginx.com>
parents:
6180
diff
changeset
|
580 rc = NGX_DECLINED; |
0e3a45ec2a3a
Upstream: fixed cache send error handling.
Roman Arutyunyan <arut@nginx.com>
parents:
6180
diff
changeset
|
581 r->cached = 0; |
0e3a45ec2a3a
Upstream: fixed cache send error handling.
Roman Arutyunyan <arut@nginx.com>
parents:
6180
diff
changeset
|
582 } |
6906
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
583 |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
584 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
|
585 rc = NGX_ERROR; |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
586 } |
6242
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 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
589 if (rc != NGX_DECLINED) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
590 ngx_http_finalize_request(r, rc); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
591 return; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
592 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
593 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
594 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
595 #endif |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
596 |
5947
d9025ea1f5a5
Upstream: simplified proxy_store and friends configuration code.
Valentin Bartenev <vbart@nginx.com>
parents:
5935
diff
changeset
|
597 u->store = u->conf->store; |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
598 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
599 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
|
600 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
|
601 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
|
602 } |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
603 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
604 if (r->request_body) { |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
605 u->request_bufs = r->request_body->bufs; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
606 } |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
607 |
537 | 608 if (u->create_request(r) != NGX_OK) { |
479 | 609 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); |
610 return; | |
611 } | |
612 | |
6528
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
613 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
|
614 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
|
615 return; |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
616 } |
3271
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3198
diff
changeset
|
617 |
509 | 618 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
479 | 619 |
3053 | 620 u->output.alignment = clcf->directio_alignment; |
479 | 621 u->output.pool = r->pool; |
622 u->output.bufs.num = 1; | |
509 | 623 u->output.bufs.size = clcf->client_body_buffer_size; |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
624 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
625 if (u->output.output_filter == NULL) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
626 u->output.output_filter = ngx_chain_writer; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
627 u->output.filter_ctx = &u->writer; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
628 } |
479 | 629 |
630 u->writer.pool = r->pool; | |
631 | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
632 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
|
633 |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
634 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
|
635 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
|
636 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
|
637 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
|
638 return; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
639 } |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
640 |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
641 } else { |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
642 |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
643 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
|
644 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
|
645 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
|
646 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
|
647 return; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
648 } |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
649 |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
650 ngx_memzero(u->state, sizeof(ngx_http_upstream_state_t)); |
479 | 651 } |
652 | |
593 | 653 cln = ngx_http_cleanup_add(r, 0); |
569 | 654 if (cln == NULL) { |
655 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | |
656 return; | |
657 } | |
658 | |
659 cln->handler = ngx_http_upstream_cleanup; | |
660 cln->data = r; | |
661 u->cleanup = &cln->handler; | |
662 | |
1658 | 663 if (u->resolved == NULL) { |
664 | |
665 uscf = u->conf->upstream; | |
666 | |
667 } else { | |
668 | |
5660
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
669 #if (NGX_HTTP_SSL) |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
670 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
|
671 #endif |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
672 |
6303
a93345ee8f52
Upstream: fixed "no port" detection in evaluated upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6290
diff
changeset
|
673 host = &u->resolved->host; |
a93345ee8f52
Upstream: fixed "no port" detection in evaluated upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6290
diff
changeset
|
674 |
6786
906ac20234ed
Upstream: do not unnecessarily create per-request upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6777
diff
changeset
|
675 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
|
676 |
906ac20234ed
Upstream: do not unnecessarily create per-request upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6777
diff
changeset
|
677 uscfp = umcf->upstreams.elts; |
906ac20234ed
Upstream: do not unnecessarily create per-request upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6777
diff
changeset
|
678 |
906ac20234ed
Upstream: do not unnecessarily create per-request upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6777
diff
changeset
|
679 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
|
680 |
906ac20234ed
Upstream: do not unnecessarily create per-request upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6777
diff
changeset
|
681 uscf = uscfp[i]; |
906ac20234ed
Upstream: do not unnecessarily create per-request upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6777
diff
changeset
|
682 |
906ac20234ed
Upstream: do not unnecessarily create per-request upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6777
diff
changeset
|
683 if (uscf->host.len == host->len |
906ac20234ed
Upstream: do not unnecessarily create per-request upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6777
diff
changeset
|
684 && ((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
|
685 || uscf->port == u->resolved->port) |
906ac20234ed
Upstream: do not unnecessarily create per-request upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6777
diff
changeset
|
686 && 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
|
687 { |
906ac20234ed
Upstream: do not unnecessarily create per-request upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6777
diff
changeset
|
688 goto found; |
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 } |
906ac20234ed
Upstream: do not unnecessarily create per-request upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6777
diff
changeset
|
691 |
2422
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2413
diff
changeset
|
692 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
|
693 |
6326
705c356ce664
Fixed fastcgi_pass with UNIX socket and variables (ticket #855).
Ruslan Ermilov <ru@nginx.com>
parents:
6316
diff
changeset
|
694 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
|
695 && 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
|
696 { |
6303
a93345ee8f52
Upstream: fixed "no port" detection in evaluated upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6290
diff
changeset
|
697 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
|
698 "no port in upstream \"%V\"", host); |
a93345ee8f52
Upstream: fixed "no port" detection in evaluated upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6290
diff
changeset
|
699 ngx_http_upstream_finalize_request(r, u, |
6313 | 700 NGX_HTTP_INTERNAL_SERVER_ERROR); |
6303
a93345ee8f52
Upstream: fixed "no port" detection in evaluated upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6290
diff
changeset
|
701 return; |
a93345ee8f52
Upstream: fixed "no port" detection in evaluated upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6290
diff
changeset
|
702 } |
a93345ee8f52
Upstream: fixed "no port" detection in evaluated upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6290
diff
changeset
|
703 |
2422
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2413
diff
changeset
|
704 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
|
705 != NGX_OK) |
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2413
diff
changeset
|
706 { |
3169
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
707 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
|
708 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
|
709 return; |
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2413
diff
changeset
|
710 } |
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2413
diff
changeset
|
711 |
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2413
diff
changeset
|
712 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
|
713 |
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2413
diff
changeset
|
714 return; |
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2413
diff
changeset
|
715 } |
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2413
diff
changeset
|
716 |
3879
502a6b0acf3f
fix case when a host in fastcgi_pass, scgi_pass, and uwsgi_pass
Igor Sysoev <igor@sysoev.ru>
parents:
3713
diff
changeset
|
717 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
|
718 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
|
719 "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
|
720 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
|
721 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
|
722 return; |
502a6b0acf3f
fix case when a host in fastcgi_pass, scgi_pass, and uwsgi_pass
Igor Sysoev <igor@sysoev.ru>
parents:
3713
diff
changeset
|
723 } |
502a6b0acf3f
fix case when a host in fastcgi_pass, scgi_pass, and uwsgi_pass
Igor Sysoev <igor@sysoev.ru>
parents:
3713
diff
changeset
|
724 |
1658 | 725 temp.name = *host; |
726 | |
727 ctx = ngx_resolve_start(clcf->resolver, &temp); | |
728 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
|
729 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
|
730 NGX_HTTP_INTERNAL_SERVER_ERROR); |
1658 | 731 return; |
732 } | |
733 | |
1683
1e0b028055ec
allow to use IP addresses without defined resolver
Igor Sysoev <igor@sysoev.ru>
parents:
1658
diff
changeset
|
734 if (ctx == NGX_NO_RESOLVER) { |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
735 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
|
736 "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
|
737 |
3169
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
738 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
|
739 return; |
1e0b028055ec
allow to use IP addresses without defined resolver
Igor Sysoev <igor@sysoev.ru>
parents:
1658
diff
changeset
|
740 } |
1e0b028055ec
allow to use IP addresses without defined resolver
Igor Sysoev <igor@sysoev.ru>
parents:
1658
diff
changeset
|
741 |
1658 | 742 ctx->name = *host; |
743 ctx->handler = ngx_http_upstream_resolve_handler; | |
744 ctx->data = r; | |
745 ctx->timeout = clcf->resolver_timeout; | |
746 | |
1959
4f16186f5603
quick resolving handles u->resolved->ctx by itself
Igor Sysoev <igor@sysoev.ru>
parents:
1958
diff
changeset
|
747 u->resolved->ctx = ctx; |
4f16186f5603
quick resolving handles u->resolved->ctx by itself
Igor Sysoev <igor@sysoev.ru>
parents:
1958
diff
changeset
|
748 |
1658 | 749 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
|
750 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
|
751 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
|
752 NGX_HTTP_INTERNAL_SERVER_ERROR); |
1658 | 753 return; |
754 } | |
755 | |
756 return; | |
757 } | |
758 | |
759 found: | |
760 | |
4964
2464ccebdb52
Upstream: fixed SIGSEGV with the "if" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4916
diff
changeset
|
761 if (uscf == NULL) { |
2464ccebdb52
Upstream: fixed SIGSEGV with the "if" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4916
diff
changeset
|
762 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
|
763 "no upstream configuration"); |
2464ccebdb52
Upstream: fixed SIGSEGV with the "if" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4916
diff
changeset
|
764 ngx_http_upstream_finalize_request(r, u, |
2464ccebdb52
Upstream: fixed SIGSEGV with the "if" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4916
diff
changeset
|
765 NGX_HTTP_INTERNAL_SERVER_ERROR); |
2464ccebdb52
Upstream: fixed SIGSEGV with the "if" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4916
diff
changeset
|
766 return; |
2464ccebdb52
Upstream: fixed SIGSEGV with the "if" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4916
diff
changeset
|
767 } |
2464ccebdb52
Upstream: fixed SIGSEGV with the "if" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4916
diff
changeset
|
768 |
6703
edcd9303a4d3
Upstream: introduced u->upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6699
diff
changeset
|
769 u->upstream = uscf; |
edcd9303a4d3
Upstream: introduced u->upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6699
diff
changeset
|
770 |
5682
110b50657d77
Upstream: restored workaround for "if".
Maxim Dounin <mdounin@mdounin.ru>
parents:
5677
diff
changeset
|
771 #if (NGX_HTTP_SSL) |
110b50657d77
Upstream: restored workaround for "if".
Maxim Dounin <mdounin@mdounin.ru>
parents:
5677
diff
changeset
|
772 u->ssl_name = uscf->host; |
110b50657d77
Upstream: restored workaround for "if".
Maxim Dounin <mdounin@mdounin.ru>
parents:
5677
diff
changeset
|
773 #endif |
110b50657d77
Upstream: restored workaround for "if".
Maxim Dounin <mdounin@mdounin.ru>
parents:
5677
diff
changeset
|
774 |
1658 | 775 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
|
776 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
|
777 NGX_HTTP_INTERNAL_SERVER_ERROR); |
1658 | 778 return; |
779 } | |
780 | |
5832
d09b689911ac
Upstream: limited next_upstream time and tries (ticket #544).
Roman Arutyunyan <arut@nginx.com>
parents:
5827
diff
changeset
|
781 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
|
782 |
d09b689911ac
Upstream: limited next_upstream time and tries (ticket #544).
Roman Arutyunyan <arut@nginx.com>
parents:
5827
diff
changeset
|
783 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
|
784 && 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
|
785 { |
d09b689911ac
Upstream: limited next_upstream time and tries (ticket #544).
Roman Arutyunyan <arut@nginx.com>
parents:
5827
diff
changeset
|
786 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
|
787 } |
d09b689911ac
Upstream: limited next_upstream time and tries (ticket #544).
Roman Arutyunyan <arut@nginx.com>
parents:
5827
diff
changeset
|
788 |
479 | 789 ngx_http_upstream_connect(r, u); |
790 } | |
791 | |
792 | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
793 #if (NGX_HTTP_CACHE) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
794 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
795 static ngx_int_t |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
796 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
|
797 { |
5951
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
798 ngx_int_t rc; |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
799 ngx_http_cache_t *c; |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
800 ngx_http_file_cache_t *cache; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
801 |
3056
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
802 c = r->cache; |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
803 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
804 if (c == NULL) { |
3056
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
805 |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
806 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
|
807 return NGX_DECLINED; |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
808 } |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
809 |
5951
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
810 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
|
811 |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
812 if (rc != NGX_OK) { |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
813 return rc; |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
814 } |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
815 |
6306
b1858fc47e3b
Style: unified request method checks.
Ruslan Ermilov <ru@nginx.com>
parents:
6303
diff
changeset
|
816 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
|
817 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
|
818 } |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
819 |
3698
d11227f0107f
rename ngx_http_file_cache_create() to ngx_http_file_cache_new()
Igor Sysoev <igor@sysoev.ru>
parents:
3697
diff
changeset
|
820 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
|
821 return NGX_ERROR; |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
822 } |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
823 |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
824 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
|
825 return NGX_ERROR; |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
826 } |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
827 |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
828 /* TODO: add keys */ |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
829 |
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
830 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
|
831 |
3976
215fe9223419
update r3945 with more descriptive error message
Igor Sysoev <igor@sysoev.ru>
parents:
3963
diff
changeset
|
832 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
|
833 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
|
834 "%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
|
835 "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
|
836 &u->conf->module, u->conf->buffer_size, |
215fe9223419
update r3945 with more descriptive error message
Igor Sysoev <igor@sysoev.ru>
parents:
3963
diff
changeset
|
837 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
|
838 |
f1f194ceab16
fix segfault if cache key is larger than upstream buffer size
Igor Sysoev <igor@sysoev.ru>
parents:
3940
diff
changeset
|
839 r->cache = NULL; |
f1f194ceab16
fix segfault if cache key is larger than upstream buffer size
Igor Sysoev <igor@sysoev.ru>
parents:
3940
diff
changeset
|
840 return NGX_DECLINED; |
f1f194ceab16
fix segfault if cache key is larger than upstream buffer size
Igor Sysoev <igor@sysoev.ru>
parents:
3940
diff
changeset
|
841 } |
f1f194ceab16
fix segfault if cache key is larger than upstream buffer size
Igor Sysoev <igor@sysoev.ru>
parents:
3940
diff
changeset
|
842 |
4176
2b5151a2300b
Fixed cache bypass caching of non-cacheable replies (ticket #21).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4152
diff
changeset
|
843 u->cacheable = 1; |
2b5151a2300b
Fixed cache bypass caching of non-cacheable replies (ticket #21).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4152
diff
changeset
|
844 |
5950
eaeecf00d5d7
Upstream: preset some cache configuration when bypassing.
Valentin Bartenev <vbart@nginx.com>
parents:
5949
diff
changeset
|
845 c = r->cache; |
eaeecf00d5d7
Upstream: preset some cache configuration when bypassing.
Valentin Bartenev <vbart@nginx.com>
parents:
5949
diff
changeset
|
846 |
eaeecf00d5d7
Upstream: preset some cache configuration when bypassing.
Valentin Bartenev <vbart@nginx.com>
parents:
5949
diff
changeset
|
847 c->body_start = u->conf->buffer_size; |
eaeecf00d5d7
Upstream: preset some cache configuration when bypassing.
Valentin Bartenev <vbart@nginx.com>
parents:
5949
diff
changeset
|
848 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
|
849 c->file_cache = cache; |
5950
eaeecf00d5d7
Upstream: preset some cache configuration when bypassing.
Valentin Bartenev <vbart@nginx.com>
parents:
5949
diff
changeset
|
850 |
3917
2a70484a6580
fix a broken cached response if bypass/no_cache directive values are different,
Igor Sysoev <igor@sysoev.ru>
parents:
3898
diff
changeset
|
851 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
|
852 |
2a70484a6580
fix a broken cached response if bypass/no_cache directive values are different,
Igor Sysoev <igor@sysoev.ru>
parents:
3898
diff
changeset
|
853 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
|
854 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
|
855 |
2a70484a6580
fix a broken cached response if bypass/no_cache directive values are different,
Igor Sysoev <igor@sysoev.ru>
parents:
3898
diff
changeset
|
856 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
|
857 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
|
858 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
|
859 |
2a70484a6580
fix a broken cached response if bypass/no_cache directive values are different,
Igor Sysoev <igor@sysoev.ru>
parents:
3898
diff
changeset
|
860 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
|
861 break; |
2a70484a6580
fix a broken cached response if bypass/no_cache directive values are different,
Igor Sysoev <igor@sysoev.ru>
parents:
3898
diff
changeset
|
862 } |
2a70484a6580
fix a broken cached response if bypass/no_cache directive values are different,
Igor Sysoev <igor@sysoev.ru>
parents:
3898
diff
changeset
|
863 |
4385
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4375
diff
changeset
|
864 c->lock = u->conf->cache_lock; |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4375
diff
changeset
|
865 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
|
866 c->lock_age = u->conf->cache_lock_age; |
4385
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4375
diff
changeset
|
867 |
3056
d22afd261e72
do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents:
3055
diff
changeset
|
868 u->cache_status = NGX_HTTP_CACHE_MISS; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
869 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
870 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
871 rc = ngx_http_file_cache_open(r); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
872 |
2926
80a314b63c56
delete useless r->cache->uses
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
873 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
|
874 "http upstream cache: %i", rc); |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
875 |
2952 | 876 switch (rc) { |
877 | |
6906
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
878 case NGX_HTTP_CACHE_STALE: |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
879 |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
880 if (((u->conf->cache_use_stale & NGX_HTTP_UPSTREAM_FT_UPDATING) |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
881 || c->stale_updating) && !r->cache_updater |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
882 && u->conf->cache_background_update) |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
883 { |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
884 r->cache->background = 1; |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
885 u->cache_status = rc; |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
886 rc = NGX_OK; |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
887 } |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
888 |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
889 break; |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
890 |
2952 | 891 case NGX_HTTP_CACHE_UPDATING: |
892 | |
6906
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) |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
894 || c->stale_updating) && !r->cache_updater) |
6905
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
895 { |
2952 | 896 u->cache_status = rc; |
2927
55ceaef03d34
proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents:
2926
diff
changeset
|
897 rc = NGX_OK; |
55ceaef03d34
proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents:
2926
diff
changeset
|
898 |
55ceaef03d34
proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents:
2926
diff
changeset
|
899 } else { |
55ceaef03d34
proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents:
2926
diff
changeset
|
900 rc = NGX_HTTP_CACHE_STALE; |
55ceaef03d34
proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents:
2926
diff
changeset
|
901 } |
2952 | 902 |
903 break; | |
904 | |
905 case NGX_OK: | |
906 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
|
907 } |
55ceaef03d34
proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents:
2926
diff
changeset
|
908 |
2952 | 909 switch (rc) { |
910 | |
911 case NGX_OK: | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
912 |
6242
0e3a45ec2a3a
Upstream: fixed cache send error handling.
Roman Arutyunyan <arut@nginx.com>
parents:
6180
diff
changeset
|
913 return NGX_OK; |
2952 | 914 |
915 case NGX_HTTP_CACHE_STALE: | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
916 |
2665
4d627567c324
fix r2664: ..._cache_valid did not work for stale responses
Igor Sysoev <igor@sysoev.ru>
parents:
2664
diff
changeset
|
917 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
|
918 c->updating_sec = 0; |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
919 c->error_sec = 0; |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
920 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
921 u->buffer.start = NULL; |
2952 | 922 u->cache_status = NGX_HTTP_CACHE_EXPIRED; |
923 | |
924 break; | |
925 | |
926 case NGX_DECLINED: | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
927 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
928 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
|
929 u->buffer.start = NULL; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
930 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
931 } else { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
932 u->buffer.pos = u->buffer.start + c->header_start; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
933 u->buffer.last = u->buffer.pos; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
934 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
935 |
2952 | 936 break; |
937 | |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
938 case NGX_HTTP_CACHE_SCARCE: |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
939 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
940 u->cacheable = 0; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
941 |
2952 | 942 break; |
943 | |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
944 case NGX_AGAIN: |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
945 |
3055
92b6cfaa3c27
fix sending a cached file using AIO
Igor Sysoev <igor@sysoev.ru>
parents:
3053
diff
changeset
|
946 return NGX_BUSY; |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
947 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
948 case NGX_ERROR: |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
949 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
950 return NGX_ERROR; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
951 |
2952 | 952 default: |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
953 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
954 /* 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
|
955 |
2952 | 956 u->cache_status = NGX_HTTP_CACHE_HIT; |
957 | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
958 return rc; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
959 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
960 |
6793
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
961 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
|
962 u->cacheable = 0; |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
963 } |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
964 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
965 r->cached = 0; |
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 return NGX_DECLINED; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
968 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
969 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
970 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
971 static ngx_int_t |
5951
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
972 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
|
973 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
|
974 { |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
975 ngx_str_t *name, val; |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
976 ngx_uint_t i; |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
977 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
|
978 |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
979 if (u->conf->cache_zone) { |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
980 *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
|
981 return NGX_OK; |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
982 } |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
983 |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
984 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
|
985 return NGX_ERROR; |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
986 } |
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 if (val.len == 0 |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
989 || (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
|
990 { |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
991 return NGX_DECLINED; |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
992 } |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
993 |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
994 caches = u->caches->elts; |
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 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
|
997 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
|
998 |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
999 if (name->len == val.len |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
1000 && 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
|
1001 { |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
1002 *cache = caches[i]; |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
1003 return NGX_OK; |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
1004 } |
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 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
|
1008 "cache \"%V\" not found", &val); |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
1009 |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
1010 return NGX_ERROR; |
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 |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
1013 |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5950
diff
changeset
|
1014 static ngx_int_t |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1015 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
|
1016 { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1017 ngx_int_t rc; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1018 ngx_http_cache_t *c; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1019 |
2952 | 1020 r->cached = 1; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1021 c = r->cache; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1022 |
3369
479468a7d982
fix handling cached HTTP/0.9 response
Igor Sysoev <igor@sysoev.ru>
parents:
3272
diff
changeset
|
1023 if (c->header_start == c->body_start) { |
479468a7d982
fix handling cached HTTP/0.9 response
Igor Sysoev <igor@sysoev.ru>
parents:
3272
diff
changeset
|
1024 r->http_version = NGX_HTTP_VERSION_9; |
479468a7d982
fix handling cached HTTP/0.9 response
Igor Sysoev <igor@sysoev.ru>
parents:
3272
diff
changeset
|
1025 return ngx_http_cache_send(r); |
479468a7d982
fix handling cached HTTP/0.9 response
Igor Sysoev <igor@sysoev.ru>
parents:
3272
diff
changeset
|
1026 } |
479468a7d982
fix handling cached HTTP/0.9 response
Igor Sysoev <igor@sysoev.ru>
parents:
3272
diff
changeset
|
1027 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1028 /* TODO: cache stack */ |
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 u->buffer = *c->buf; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1031 u->buffer.pos += c->header_start; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1032 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1033 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
|
1034 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
|
1035 u->headers_in.last_modified_time = -1; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1036 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1037 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
|
1038 sizeof(ngx_table_elt_t)) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1039 != NGX_OK) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1040 { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1041 return NGX_ERROR; |
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 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1044 rc = u->process_header(r); |
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 if (rc == NGX_OK) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1047 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1048 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
|
1049 return NGX_DONE; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1050 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1051 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1052 return ngx_http_cache_send(r); |
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 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1055 if (rc == NGX_ERROR) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1056 return NGX_ERROR; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1057 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1058 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1059 /* rc == NGX_HTTP_UPSTREAM_INVALID_HEADER */ |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1060 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1061 /* TODO: delete file */ |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1062 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1063 return rc; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1064 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1065 |
6793
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1066 |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1067 static ngx_int_t |
6906
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
1068 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
|
1069 ngx_http_upstream_t *u) |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
1070 { |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
1071 ngx_http_request_t *sr; |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
1072 |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
1073 if (!r->cached || !r->cache->background) { |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
1074 return NGX_OK; |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
1075 } |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
1076 |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
1077 if (ngx_http_subrequest(r, &r->uri, &r->args, &sr, NULL, |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
1078 NGX_HTTP_SUBREQUEST_CLONE) |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
1079 != NGX_OK) |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
1080 { |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
1081 return NGX_ERROR; |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
1082 } |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
1083 |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
1084 sr->header_only = 1; |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
1085 sr->cache_updater = 1; |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
1086 |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
1087 return NGX_OK; |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
1088 } |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
1089 |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
1090 |
1aeaae6e9446
Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6905
diff
changeset
|
1091 static ngx_int_t |
6793
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1092 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
|
1093 ngx_http_upstream_t *u) |
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 off_t offset; |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1096 u_char *p, *start; |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1097 ngx_table_elt_t *h; |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1098 |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1099 h = r->headers_in.range; |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1100 |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1101 if (h == NULL |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1102 || !u->cacheable |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1103 || 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
|
1104 { |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1105 return NGX_OK; |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1106 } |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1107 |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1108 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
|
1109 return NGX_DECLINED; |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1110 } |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1111 |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1112 if (h->value.len < 7 |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1113 || 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
|
1114 { |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1115 return NGX_OK; |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1116 } |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1117 |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1118 p = h->value.data + 6; |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1119 |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1120 while (*p == ' ') { p++; } |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1121 |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1122 if (*p == '-') { |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1123 return NGX_DECLINED; |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1124 } |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1125 |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1126 start = p; |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1127 |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1128 while (*p >= '0' && *p <= '9') { p++; } |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1129 |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1130 offset = ngx_atoof(start, p - start); |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1131 |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1132 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
|
1133 return NGX_DECLINED; |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1134 } |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1135 |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1136 return NGX_OK; |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1137 } |
0fba3ed4e7eb
Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6789
diff
changeset
|
1138 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1139 #endif |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1140 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1141 |
487 | 1142 static void |
1658 | 1143 ngx_http_upstream_resolve_handler(ngx_resolver_ctx_t *ctx) |
1144 { | |
5113
08b36f2afc3f
Upstream: fixed previous commit.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5112
diff
changeset
|
1145 ngx_connection_t *c; |
1658 | 1146 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
|
1147 ngx_http_upstream_t *u; |
1658 | 1148 ngx_http_upstream_resolved_t *ur; |
1149 | |
1150 r = ctx->data; | |
5113
08b36f2afc3f
Upstream: fixed previous commit.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5112
diff
changeset
|
1151 c = r->connection; |
1658 | 1152 |
3169
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
1153 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
|
1154 ur = u->resolved; |
1658 | 1155 |
5928
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5911
diff
changeset
|
1156 ngx_http_set_log_request(c->log, r); |
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5911
diff
changeset
|
1157 |
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5911
diff
changeset
|
1158 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, |
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5911
diff
changeset
|
1159 "http upstream resolve: \"%V?%V\"", &r->uri, &r->args); |
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5911
diff
changeset
|
1160 |
1658 | 1161 if (ctx->state) { |
1162 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
1163 "%V could not be resolved (%i: %s)", | |
1164 &ctx->name, ctx->state, | |
1165 ngx_resolver_strerror(ctx->state)); | |
1166 | |
3169
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
1167 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
|
1168 goto failed; |
1658 | 1169 } |
1170 | |
1171 ur->naddrs = ctx->naddrs; | |
1172 ur->addrs = ctx->addrs; | |
1173 | |
1174 #if (NGX_DEBUG) | |
1175 { | |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5453
diff
changeset
|
1176 u_char text[NGX_SOCKADDR_STRLEN]; |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5453
diff
changeset
|
1177 ngx_str_t addr; |
1658 | 1178 ngx_uint_t i; |
1179 | |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5453
diff
changeset
|
1180 addr.data = text; |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5453
diff
changeset
|
1181 |
1658 | 1182 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
|
1183 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
|
1184 text, NGX_SOCKADDR_STRLEN, 0); |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5453
diff
changeset
|
1185 |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5453
diff
changeset
|
1186 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
|
1187 "name was resolved to %V", &addr); |
1658 | 1188 } |
1189 } | |
1190 #endif | |
1191 | |
1192 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
|
1193 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
|
1194 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
|
1195 goto failed; |
1658 | 1196 } |
1197 | |
1198 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
|
1199 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
|
1200 |
5885
5a042519bfe7
Upstream: limited next_upstream time and tries when resolving DNS.
Gu Feng <flygoast@126.com>
parents:
5883
diff
changeset
|
1201 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
|
1202 |
5a042519bfe7
Upstream: limited next_upstream time and tries when resolving DNS.
Gu Feng <flygoast@126.com>
parents:
5883
diff
changeset
|
1203 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
|
1204 && 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
|
1205 { |
5a042519bfe7
Upstream: limited next_upstream time and tries when resolving DNS.
Gu Feng <flygoast@126.com>
parents:
5883
diff
changeset
|
1206 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
|
1207 } |
5a042519bfe7
Upstream: limited next_upstream time and tries when resolving DNS.
Gu Feng <flygoast@126.com>
parents:
5883
diff
changeset
|
1208 |
3169
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
1209 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
|
1210 |
d3c15c7831eb
Upstream: call ngx_http_run_posted_requests() on resolve errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5104
diff
changeset
|
1211 failed: |
d3c15c7831eb
Upstream: call ngx_http_run_posted_requests() on resolve errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5104
diff
changeset
|
1212 |
5113
08b36f2afc3f
Upstream: fixed previous commit.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5112
diff
changeset
|
1213 ngx_http_run_posted_requests(c); |
1658 | 1214 } |
1215 | |
1216 | |
1217 static void | |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1218 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
|
1219 { |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1220 ngx_connection_t *c; |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1221 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
|
1222 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
|
1223 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1224 c = ev->data; |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1225 r = c->data; |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1226 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1227 u = r->upstream; |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1228 c = r->connection; |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1229 |
5928
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5911
diff
changeset
|
1230 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
|
1231 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1232 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
|
1233 "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
|
1234 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1235 if (ev->write) { |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1236 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
|
1237 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1238 } else { |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1239 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
|
1240 } |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1241 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1242 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
|
1243 } |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1244 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1245 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1246 static void |
509 | 1247 ngx_http_upstream_rd_check_broken_connection(ngx_http_request_t *r) |
1248 { | |
1249 ngx_http_upstream_check_broken_connection(r, r->connection->read); | |
1250 } | |
1251 | |
1252 | |
1253 static void | |
1254 ngx_http_upstream_wr_check_broken_connection(ngx_http_request_t *r) | |
1255 { | |
1256 ngx_http_upstream_check_broken_connection(r, r->connection->write); | |
1257 } | |
1258 | |
1259 | |
1260 static void | |
1261 ngx_http_upstream_check_broken_connection(ngx_http_request_t *r, | |
1262 ngx_event_t *ev) | |
479 | 1263 { |
1264 int n; | |
1265 char buf[1]; | |
577 | 1266 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
|
1267 ngx_int_t event; |
479 | 1268 ngx_connection_t *c; |
1269 ngx_http_upstream_t *u; | |
1270 | |
527 | 1271 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, ev->log, 0, |
1272 "http upstream check client, write event:%d, \"%V\"", | |
1273 ev->write, &r->uri); | |
479 | 1274 |
509 | 1275 c = r->connection; |
483 | 1276 u = r->upstream; |
1277 | |
583 | 1278 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
|
1279 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
|
1280 |
6ad4bba6313e
delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents:
2805
diff
changeset
|
1281 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
|
1282 |
6ad4bba6313e
delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents:
2805
diff
changeset
|
1283 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
|
1284 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
|
1285 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
|
1286 return; |
6ad4bba6313e
delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents:
2805
diff
changeset
|
1287 } |
6ad4bba6313e
delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents:
2805
diff
changeset
|
1288 } |
6ad4bba6313e
delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents:
2805
diff
changeset
|
1289 |
2757
9cc973b46af1
get a full response if the response is cacheable or storable even
Igor Sysoev <igor@sysoev.ru>
parents:
2708
diff
changeset
|
1290 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
|
1291 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
|
1292 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
|
1293 } |
2807
6ad4bba6313e
delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents:
2805
diff
changeset
|
1294 |
527 | 1295 return; |
1296 } | |
1297 | |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
6242
diff
changeset
|
1298 #if (NGX_HTTP_V2) |
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
6242
diff
changeset
|
1299 if (r->stream) { |
5121
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
5113
diff
changeset
|
1300 return; |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
5113
diff
changeset
|
1301 } |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
5113
diff
changeset
|
1302 #endif |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
5113
diff
changeset
|
1303 |
479 | 1304 #if (NGX_HAVE_KQUEUE) |
1305 | |
1306 if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) { | |
1307 | |
1308 if (!ev->pending_eof) { | |
1309 return; | |
1310 } | |
1311 | |
1312 ev->eof = 1; | |
583 | 1313 c->error = 1; |
479 | 1314 |
1315 if (ev->kq_errno) { | |
1316 ev->error = 1; | |
1317 } | |
1318 | |
2757
9cc973b46af1
get a full response if the response is cacheable or storable even
Igor Sysoev <igor@sysoev.ru>
parents:
2708
diff
changeset
|
1319 if (!u->cacheable && u->peer.connection) { |
479 | 1320 ngx_log_error(NGX_LOG_INFO, ev->log, ev->kq_errno, |
4182 | 1321 "kevent() reported that client prematurely closed " |
527 | 1322 "connection, so upstream connection is closed too"); |
479 | 1323 ngx_http_upstream_finalize_request(r, u, |
1324 NGX_HTTP_CLIENT_CLOSED_REQUEST); | |
1325 return; | |
1326 } | |
1327 | |
1328 ngx_log_error(NGX_LOG_INFO, ev->log, ev->kq_errno, | |
4182 | 1329 "kevent() reported that client prematurely closed " |
1330 "connection"); | |
479 | 1331 |
1332 if (u->peer.connection == NULL) { | |
1333 ngx_http_upstream_finalize_request(r, u, | |
1334 NGX_HTTP_CLIENT_CLOSED_REQUEST); | |
1335 } | |
1336 | |
1337 return; | |
1338 } | |
1339 | |
1340 #endif | |
1341 | |
5373
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1342 #if (NGX_HAVE_EPOLLRDHUP) |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1343 |
6536
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6530
diff
changeset
|
1344 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
|
1345 socklen_t len; |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1346 |
6536
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6530
diff
changeset
|
1347 if (!ev->pending_eof) { |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6530
diff
changeset
|
1348 return; |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6530
diff
changeset
|
1349 } |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6530
diff
changeset
|
1350 |
5373
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1351 ev->eof = 1; |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1352 c->error = 1; |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1353 |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1354 err = 0; |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1355 len = sizeof(ngx_err_t); |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1356 |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1357 /* |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1358 * 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
|
1359 * 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
|
1360 */ |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1361 |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1362 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
|
1363 == -1) |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1364 { |
5557
188481078faf
Use ngx_socket_errno where appropriate.
Piotr Sikora <piotr@cloudflare.com>
parents:
5546
diff
changeset
|
1365 err = ngx_socket_errno; |
5373
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1366 } |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1367 |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1368 if (err) { |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1369 ev->error = 1; |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1370 } |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1371 |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1372 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
|
1373 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
|
1374 "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
|
1375 "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
|
1376 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
|
1377 NGX_HTTP_CLIENT_CLOSED_REQUEST); |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1378 return; |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1379 } |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1380 |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1381 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
|
1382 "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
|
1383 "connection"); |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1384 |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1385 if (u->peer.connection == NULL) { |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1386 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
|
1387 NGX_HTTP_CLIENT_CLOSED_REQUEST); |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1388 } |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1389 |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1390 return; |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1391 } |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1392 |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1393 #endif |
46bdbca10dfc
Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents:
5368
diff
changeset
|
1394 |
479 | 1395 n = recv(c->fd, buf, 1, MSG_PEEK); |
1396 | |
1397 err = ngx_socket_errno; | |
1398 | |
1109 | 1399 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ev->log, err, |
1400 "http upstream recv(): %d", n); | |
1401 | |
479 | 1402 if (ev->write && (n >= 0 || err == NGX_EAGAIN)) { |
1403 return; | |
1404 } | |
1405 | |
1406 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
|
1407 |
6ad4bba6313e
delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents:
2805
diff
changeset
|
1408 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
|
1409 |
6ad4bba6313e
delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents:
2805
diff
changeset
|
1410 if (ngx_del_event(ev, event, 0) != NGX_OK) { |
479 | 1411 ngx_http_upstream_finalize_request(r, u, |
1412 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
1413 return; | |
1414 } | |
1415 } | |
1416 | |
1417 if (n > 0) { | |
1418 return; | |
1419 } | |
1420 | |
1421 if (n == -1) { | |
1422 if (err == NGX_EAGAIN) { | |
1423 return; | |
1424 } | |
1425 | |
1426 ev->error = 1; | |
1427 | |
483 | 1428 } else { /* n == 0 */ |
479 | 1429 err = 0; |
1430 } | |
1431 | |
529 | 1432 ev->eof = 1; |
583 | 1433 c->error = 1; |
529 | 1434 |
2757
9cc973b46af1
get a full response if the response is cacheable or storable even
Igor Sysoev <igor@sysoev.ru>
parents:
2708
diff
changeset
|
1435 if (!u->cacheable && u->peer.connection) { |
479 | 1436 ngx_log_error(NGX_LOG_INFO, ev->log, err, |
4182 | 1437 "client prematurely closed connection, " |
479 | 1438 "so upstream connection is closed too"); |
1439 ngx_http_upstream_finalize_request(r, u, | |
1440 NGX_HTTP_CLIENT_CLOSED_REQUEST); | |
1441 return; | |
1442 } | |
1443 | |
1444 ngx_log_error(NGX_LOG_INFO, ev->log, err, | |
4182 | 1445 "client prematurely closed connection"); |
479 | 1446 |
1447 if (u->peer.connection == NULL) { | |
1448 ngx_http_upstream_finalize_request(r, u, | |
1449 NGX_HTTP_CLIENT_CLOSED_REQUEST); | |
1450 } | |
1451 } | |
1452 | |
1453 | |
487 | 1454 static void |
1455 ngx_http_upstream_connect(ngx_http_request_t *r, ngx_http_upstream_t *u) | |
479 | 1456 { |
591 | 1457 ngx_int_t rc; |
1458 ngx_connection_t *c; | |
479 | 1459 |
483 | 1460 r->connection->log->action = "connecting to upstream"; |
479 | 1461 |
6146
59fc60585f1e
Upstream: times to obtain header/response are stored as ngx_msec_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6125
diff
changeset
|
1462 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
|
1463 u->state->response_time = ngx_current_msec - u->state->response_time; |
665 | 1464 } |
1465 | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
1466 u->state = ngx_array_push(r->upstream_states); |
665 | 1467 if (u->state == NULL) { |
1468 ngx_http_upstream_finalize_request(r, u, | |
1469 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
1470 return; | |
1471 } | |
1472 | |
1473 ngx_memzero(u->state, sizeof(ngx_http_upstream_state_t)); | |
1474 | |
6146
59fc60585f1e
Upstream: times to obtain header/response are stored as ngx_msec_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6125
diff
changeset
|
1475 u->state->response_time = ngx_current_msec; |
6147
74b6ef56ea56
Upstream: $upstream_connect_time.
Ruslan Ermilov <ru@nginx.com>
parents:
6146
diff
changeset
|
1476 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
|
1477 u->state->header_time = (ngx_msec_t) -1; |
665 | 1478 |
479 | 1479 rc = ngx_event_connect_peer(&u->peer); |
1480 | |
1481 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
1482 "http upstream connect: %i", rc); | |
1483 | |
1484 if (rc == NGX_ERROR) { | |
1485 ngx_http_upstream_finalize_request(r, u, | |
1486 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
1487 return; | |
1488 } | |
1489 | |
1707
f3188f6eae1f
$upstream_addr did not contain last address, the bug was introduced in r1659
Igor Sysoev <igor@sysoev.ru>
parents:
1706
diff
changeset
|
1490 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
|
1491 |
543 | 1492 if (rc == NGX_BUSY) { |
1493 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "no live upstreams"); | |
1378 | 1494 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_NOLIVE); |
1495 return; | |
543 | 1496 } |
1497 | |
1378 | 1498 if (rc == NGX_DECLINED) { |
479 | 1499 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR); |
1500 return; | |
1501 } | |
1502 | |
5261
af60a210cb78
Upstream: updated list of ngx_event_connect_peer() return values.
Ruslan Ermilov <ru@nginx.com>
parents:
5231
diff
changeset
|
1503 /* rc == NGX_OK || rc == NGX_AGAIN || rc == NGX_DONE */ |
577 | 1504 |
479 | 1505 c = u->peer.connection; |
1506 | |
1507 c->data = r; | |
591 | 1508 |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1509 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
|
1510 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
|
1511 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1512 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
|
1513 u->read_event_handler = ngx_http_upstream_process_header; |
479 | 1514 |
1397
6c25a49e548a
upstream sendfile bit was overridden by r->connection->sendfile
Igor Sysoev <igor@sysoev.ru>
parents:
1378
diff
changeset
|
1515 c->sendfile &= r->connection->sendfile; |
1958 | 1516 u->output.sendfile = c->sendfile; |
479 | 1517 |
4116
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1518 if (c->pool == NULL) { |
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1519 |
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1520 /* 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
|
1521 |
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1522 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
|
1523 if (c->pool == NULL) { |
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1524 ngx_http_upstream_finalize_request(r, u, |
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1525 NGX_HTTP_INTERNAL_SERVER_ERROR); |
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1526 return; |
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1527 } |
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1528 } |
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1529 |
2847 | 1530 c->log = r->connection->log; |
4116
9baf12ea5ca1
Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4115
diff
changeset
|
1531 c->pool->log = c->log; |
2847 | 1532 c->read->log = c->log; |
1533 c->write->log = c->log; | |
479 | 1534 |
1535 /* init or reinit the ngx_output_chain() and ngx_chain_writer() contexts */ | |
1536 | |
1537 u->writer.out = NULL; | |
1538 u->writer.last = &u->writer.out; | |
1539 u->writer.connection = c; | |
1540 u->writer.limit = 0; | |
1541 | |
1542 if (u->request_sent) { | |
509 | 1543 if (ngx_http_upstream_reinit(r, u) != NGX_OK) { |
1544 ngx_http_upstream_finalize_request(r, u, | |
1545 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
1546 return; | |
1547 } | |
479 | 1548 } |
1549 | |
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
|
1550 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
|
1551 && 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
|
1552 && 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
|
1553 && 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
|
1554 { |
573 | 1555 /* |
1556 * 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
|
1557 * the subrequests should allocate their own temporary bufs |
573 | 1558 */ |
1559 | |
1560 u->output.free = ngx_alloc_chain_link(r->pool); | |
1561 if (u->output.free == NULL) { | |
1562 ngx_http_upstream_finalize_request(r, u, | |
1563 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
1564 return; | |
479 | 1565 } |
573 | 1566 |
1567 u->output.free->buf = r->request_body->buf; | |
1568 u->output.free->next = NULL; | |
1569 u->output.allocated = 1; | |
1570 | |
1571 r->request_body->buf->pos = r->request_body->buf->start; | |
1572 r->request_body->buf->last = r->request_body->buf->start; | |
1573 r->request_body->buf->tag = u->output.tag; | |
479 | 1574 } |
1575 | |
1576 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
|
1577 u->request_body_sent = 0; |
479 | 1578 |
1579 if (rc == NGX_AGAIN) { | |
1580 ngx_add_timer(c->write, u->conf->connect_timeout); | |
1581 return; | |
1582 } | |
1583 | |
577 | 1584 #if (NGX_HTTP_SSL) |
1585 | |
1658 | 1586 if (u->ssl && c->ssl == NULL) { |
591 | 1587 ngx_http_upstream_ssl_init_connection(r, u, c); |
577 | 1588 return; |
1589 } | |
1590 | |
1591 #endif | |
1592 | |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1593 ngx_http_upstream_send_request(r, u, 1); |
479 | 1594 } |
1595 | |
1596 | |
577 | 1597 #if (NGX_HTTP_SSL) |
1598 | |
1599 static void | |
591 | 1600 ngx_http_upstream_ssl_init_connection(ngx_http_request_t *r, |
1601 ngx_http_upstream_t *u, ngx_connection_t *c) | |
1602 { | |
6068
643f2ce02f1c
Upstream: abbreviated SSL handshake may interact badly with Nagle.
Ruslan Ermilov <ru@nginx.com>
parents:
6050
diff
changeset
|
1603 int tcp_nodelay; |
643f2ce02f1c
Upstream: abbreviated SSL handshake may interact badly with Nagle.
Ruslan Ermilov <ru@nginx.com>
parents:
6050
diff
changeset
|
1604 ngx_int_t rc; |
643f2ce02f1c
Upstream: abbreviated SSL handshake may interact badly with Nagle.
Ruslan Ermilov <ru@nginx.com>
parents:
6050
diff
changeset
|
1605 ngx_http_core_loc_conf_t *clcf; |
591 | 1606 |
5305
12b750d35162
Upstream: reliably detect connection failures with SSL peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5304
diff
changeset
|
1607 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
|
1608 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
|
1609 return; |
12b750d35162
Upstream: reliably detect connection failures with SSL peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5304
diff
changeset
|
1610 } |
12b750d35162
Upstream: reliably detect connection failures with SSL peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5304
diff
changeset
|
1611 |
591 | 1612 if (ngx_ssl_create_connection(u->conf->ssl, c, |
1613 NGX_SSL_BUFFER|NGX_SSL_CLIENT) | |
2536
a6d6d762c554
small optimization: " == NGX_ERROR" > " != NGX_OK"
Igor Sysoev <igor@sysoev.ru>
parents:
2463
diff
changeset
|
1614 != NGX_OK) |
591 | 1615 { |
1616 ngx_http_upstream_finalize_request(r, u, | |
1617 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
1618 return; | |
1619 } | |
1620 | |
1621 c->sendfile = 0; | |
619 | 1622 u->output.sendfile = 0; |
591 | 1623 |
5661
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1624 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
|
1625 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
|
1626 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
|
1627 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
|
1628 return; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1629 } |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1630 } |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1631 |
2184 | 1632 if (u->conf->ssl_session_reuse) { |
1633 if (u->peer.set_session(&u->peer, u->peer.data) != NGX_OK) { | |
1634 ngx_http_upstream_finalize_request(r, u, | |
1635 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
1636 return; | |
1637 } | |
6068
643f2ce02f1c
Upstream: abbreviated SSL handshake may interact badly with Nagle.
Ruslan Ermilov <ru@nginx.com>
parents:
6050
diff
changeset
|
1638 |
643f2ce02f1c
Upstream: abbreviated SSL handshake may interact badly with Nagle.
Ruslan Ermilov <ru@nginx.com>
parents:
6050
diff
changeset
|
1639 /* 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
|
1640 |
643f2ce02f1c
Upstream: abbreviated SSL handshake may interact badly with Nagle.
Ruslan Ermilov <ru@nginx.com>
parents:
6050
diff
changeset
|
1641 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
|
1642 |
643f2ce02f1c
Upstream: abbreviated SSL handshake may interact badly with Nagle.
Ruslan Ermilov <ru@nginx.com>
parents:
6050
diff
changeset
|
1643 if (clcf->tcp_nodelay && c->tcp_nodelay == NGX_TCP_NODELAY_UNSET) { |
643f2ce02f1c
Upstream: abbreviated SSL handshake may interact badly with Nagle.
Ruslan Ermilov <ru@nginx.com>
parents:
6050
diff
changeset
|
1644 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "tcp_nodelay"); |
643f2ce02f1c
Upstream: abbreviated SSL handshake may interact badly with Nagle.
Ruslan Ermilov <ru@nginx.com>
parents:
6050
diff
changeset
|
1645 |
643f2ce02f1c
Upstream: abbreviated SSL handshake may interact badly with Nagle.
Ruslan Ermilov <ru@nginx.com>
parents:
6050
diff
changeset
|
1646 tcp_nodelay = 1; |
643f2ce02f1c
Upstream: abbreviated SSL handshake may interact badly with Nagle.
Ruslan Ermilov <ru@nginx.com>
parents:
6050
diff
changeset
|
1647 |
643f2ce02f1c
Upstream: abbreviated SSL handshake may interact badly with Nagle.
Ruslan Ermilov <ru@nginx.com>
parents:
6050
diff
changeset
|
1648 if (setsockopt(c->fd, IPPROTO_TCP, TCP_NODELAY, |
643f2ce02f1c
Upstream: abbreviated SSL handshake may interact badly with Nagle.
Ruslan Ermilov <ru@nginx.com>
parents:
6050
diff
changeset
|
1649 (const void *) &tcp_nodelay, sizeof(int)) == -1) |
643f2ce02f1c
Upstream: abbreviated SSL handshake may interact badly with Nagle.
Ruslan Ermilov <ru@nginx.com>
parents:
6050
diff
changeset
|
1650 { |
643f2ce02f1c
Upstream: abbreviated SSL handshake may interact badly with Nagle.
Ruslan Ermilov <ru@nginx.com>
parents:
6050
diff
changeset
|
1651 ngx_connection_error(c, ngx_socket_errno, |
643f2ce02f1c
Upstream: abbreviated SSL handshake may interact badly with Nagle.
Ruslan Ermilov <ru@nginx.com>
parents:
6050
diff
changeset
|
1652 "setsockopt(TCP_NODELAY) failed"); |
643f2ce02f1c
Upstream: abbreviated SSL handshake may interact badly with Nagle.
Ruslan Ermilov <ru@nginx.com>
parents:
6050
diff
changeset
|
1653 ngx_http_upstream_finalize_request(r, u, |
643f2ce02f1c
Upstream: abbreviated SSL handshake may interact badly with Nagle.
Ruslan Ermilov <ru@nginx.com>
parents:
6050
diff
changeset
|
1654 NGX_HTTP_INTERNAL_SERVER_ERROR); |
643f2ce02f1c
Upstream: abbreviated SSL handshake may interact badly with Nagle.
Ruslan Ermilov <ru@nginx.com>
parents:
6050
diff
changeset
|
1655 return; |
643f2ce02f1c
Upstream: abbreviated SSL handshake may interact badly with Nagle.
Ruslan Ermilov <ru@nginx.com>
parents:
6050
diff
changeset
|
1656 } |
643f2ce02f1c
Upstream: abbreviated SSL handshake may interact badly with Nagle.
Ruslan Ermilov <ru@nginx.com>
parents:
6050
diff
changeset
|
1657 |
643f2ce02f1c
Upstream: abbreviated SSL handshake may interact badly with Nagle.
Ruslan Ermilov <ru@nginx.com>
parents:
6050
diff
changeset
|
1658 c->tcp_nodelay = NGX_TCP_NODELAY_SET; |
643f2ce02f1c
Upstream: abbreviated SSL handshake may interact badly with Nagle.
Ruslan Ermilov <ru@nginx.com>
parents:
6050
diff
changeset
|
1659 } |
591 | 1660 } |
1661 | |
641 | 1662 r->connection->log->action = "SSL handshaking to upstream"; |
1663 | |
591 | 1664 rc = ngx_ssl_handshake(c); |
1665 | |
1666 if (rc == NGX_AGAIN) { | |
5774
9bf58a3da25b
Upstream: SSL handshake timeouts.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5770
diff
changeset
|
1667 |
9bf58a3da25b
Upstream: SSL handshake timeouts.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5770
diff
changeset
|
1668 if (!c->write->timer_set) { |
9bf58a3da25b
Upstream: SSL handshake timeouts.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5770
diff
changeset
|
1669 ngx_add_timer(c->write, u->conf->connect_timeout); |
9bf58a3da25b
Upstream: SSL handshake timeouts.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5770
diff
changeset
|
1670 } |
9bf58a3da25b
Upstream: SSL handshake timeouts.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5770
diff
changeset
|
1671 |
591 | 1672 c->ssl->handler = ngx_http_upstream_ssl_handshake; |
1673 return; | |
1674 } | |
1675 | |
1676 ngx_http_upstream_ssl_handshake(c); | |
1677 } | |
1678 | |
1679 | |
1680 static void | |
577 | 1681 ngx_http_upstream_ssl_handshake(ngx_connection_t *c) |
1682 { | |
5661
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1683 long rc; |
577 | 1684 ngx_http_request_t *r; |
1685 ngx_http_upstream_t *u; | |
1686 | |
1687 r = c->data; | |
1688 u = r->upstream; | |
1689 | |
5928
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5911
diff
changeset
|
1690 ngx_http_set_log_request(c->log, r); |
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5911
diff
changeset
|
1691 |
577 | 1692 if (c->ssl->handshaked) { |
1693 | |
5661
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1694 if (u->conf->ssl_verify) { |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1695 rc = SSL_get_verify_result(c->ssl->connection); |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1696 |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1697 if (rc != X509_V_OK) { |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1698 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
|
1699 "upstream SSL certificate verify error: (%l:%s)", |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1700 rc, X509_verify_cert_error_string(rc)); |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1701 goto failed; |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1702 } |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1703 |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1704 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
|
1705 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
|
1706 "upstream SSL certificate does not match \"%V\"", |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1707 &u->ssl_name); |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1708 goto failed; |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1709 } |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1710 } |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1711 |
2184 | 1712 if (u->conf->ssl_session_reuse) { |
1713 u->peer.save_session(&u->peer, u->peer.data); | |
1714 } | |
884 | 1715 |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1716 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
|
1717 c->read->handler = ngx_http_upstream_handler; |
577 | 1718 |
5340
13a5f4765887
Upstream: posted requests handling after ssl handshake errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5305
diff
changeset
|
1719 c = r->connection; |
13a5f4765887
Upstream: posted requests handling after ssl handshake errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5305
diff
changeset
|
1720 |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1721 ngx_http_upstream_send_request(r, u, 1); |
577 | 1722 |
5340
13a5f4765887
Upstream: posted requests handling after ssl handshake errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5305
diff
changeset
|
1723 ngx_http_run_posted_requests(c); |
577 | 1724 return; |
1725 } | |
1726 | |
6799
d8d037f20484
Upstream: handling of upstream SSL handshake timeouts.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6795
diff
changeset
|
1727 if (c->write->timedout) { |
d8d037f20484
Upstream: handling of upstream SSL handshake timeouts.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6795
diff
changeset
|
1728 c = r->connection; |
d8d037f20484
Upstream: handling of upstream SSL handshake timeouts.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6795
diff
changeset
|
1729 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
|
1730 ngx_http_run_posted_requests(c); |
d8d037f20484
Upstream: handling of upstream SSL handshake timeouts.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6795
diff
changeset
|
1731 return; |
d8d037f20484
Upstream: handling of upstream SSL handshake timeouts.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6795
diff
changeset
|
1732 } |
d8d037f20484
Upstream: handling of upstream SSL handshake timeouts.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6795
diff
changeset
|
1733 |
5661
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1734 failed: |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1735 |
5340
13a5f4765887
Upstream: posted requests handling after ssl handshake errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5305
diff
changeset
|
1736 c = r->connection; |
13a5f4765887
Upstream: posted requests handling after ssl handshake errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5305
diff
changeset
|
1737 |
577 | 1738 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR); |
1739 | |
5340
13a5f4765887
Upstream: posted requests handling after ssl handshake errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5305
diff
changeset
|
1740 ngx_http_run_posted_requests(c); |
577 | 1741 } |
1742 | |
5660
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1743 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1744 static ngx_int_t |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1745 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
|
1746 ngx_connection_t *c) |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1747 { |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1748 u_char *p, *last; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1749 ngx_str_t name; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1750 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1751 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
|
1752 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
|
1753 return NGX_ERROR; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1754 } |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1755 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1756 } else { |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1757 name = u->ssl_name; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1758 } |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1759 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1760 if (name.len == 0) { |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1761 goto done; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1762 } |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1763 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1764 /* |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1765 * 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
|
1766 * 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
|
1767 */ |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1768 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1769 p = name.data; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1770 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
|
1771 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1772 if (*p == '[') { |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1773 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
|
1774 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1775 if (p == NULL) { |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1776 p = name.data; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1777 } |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1778 } |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1779 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1780 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
|
1781 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1782 if (p != NULL) { |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1783 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
|
1784 } |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1785 |
5661
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1786 if (!u->conf->ssl_server_name) { |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1787 goto done; |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1788 } |
060c2e692b96
Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5660
diff
changeset
|
1789 |
5660
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1790 #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
|
1791 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1792 /* 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
|
1793 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1794 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
|
1795 goto done; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1796 } |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1797 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1798 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
|
1799 goto done; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1800 } |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1801 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1802 /* |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1803 * 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
|
1804 * 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
|
1805 */ |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1806 |
5667
16405e02e612
Upstream: for ssl name, non-aligned memory allocation is enough.
Ruslan Ermilov <ru@nginx.com>
parents:
5661
diff
changeset
|
1807 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
|
1808 if (p == NULL) { |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1809 return NGX_ERROR; |
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 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1812 (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
|
1813 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1814 name.data = p; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1815 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1816 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
|
1817 "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
|
1818 |
6777
563a1ee345a4
SSL: compatibility with BoringSSL.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6745
diff
changeset
|
1819 if (SSL_set_tlsext_host_name(c->ssl->connection, |
563a1ee345a4
SSL: compatibility with BoringSSL.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6745
diff
changeset
|
1820 (char *) name.data) |
563a1ee345a4
SSL: compatibility with BoringSSL.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6745
diff
changeset
|
1821 == 0) |
563a1ee345a4
SSL: compatibility with BoringSSL.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6745
diff
changeset
|
1822 { |
5660
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1823 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
|
1824 "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
|
1825 return NGX_ERROR; |
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 #endif |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1829 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1830 done: |
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 u->ssl_name = name; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1833 |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1834 return NGX_OK; |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1835 } |
7022564a9e0e
Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5621
diff
changeset
|
1836 |
577 | 1837 #endif |
1838 | |
1839 | |
509 | 1840 static ngx_int_t |
487 | 1841 ngx_http_upstream_reinit(ngx_http_request_t *r, ngx_http_upstream_t *u) |
479 | 1842 { |
5848
106a8bfa4f42
Upstream: fixed file buffers reinit in ngx_http_upstream_reinit().
Roman Arutyunyan <arut@nginx.com>
parents:
5832
diff
changeset
|
1843 off_t file_pos; |
479 | 1844 ngx_chain_t *cl; |
1845 | |
509 | 1846 if (u->reinit_request(r) != NGX_OK) { |
1847 return NGX_ERROR; | |
1848 } | |
1849 | |
4120
42135dd1f0ea
Upstream: keepalive flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4119
diff
changeset
|
1850 u->keepalive = 0; |
5072
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
1851 u->upgrade = 0; |
4120
42135dd1f0ea
Upstream: keepalive flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4119
diff
changeset
|
1852 |
1705 | 1853 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
|
1854 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
|
1855 u->headers_in.last_modified_time = -1; |
1705 | 1856 |
1857 if (ngx_list_init(&u->headers_in.headers, r->pool, 8, | |
591 | 1858 sizeof(ngx_table_elt_t)) |
1859 != NGX_OK) | |
509 | 1860 { |
1861 return NGX_ERROR; | |
479 | 1862 } |
1863 | |
1864 /* reinit the request chain */ | |
577 | 1865 |
5848
106a8bfa4f42
Upstream: fixed file buffers reinit in ngx_http_upstream_reinit().
Roman Arutyunyan <arut@nginx.com>
parents:
5832
diff
changeset
|
1866 file_pos = 0; |
106a8bfa4f42
Upstream: fixed file buffers reinit in ngx_http_upstream_reinit().
Roman Arutyunyan <arut@nginx.com>
parents:
5832
diff
changeset
|
1867 |
509 | 1868 for (cl = u->request_bufs; cl; cl = cl->next) { |
479 | 1869 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
|
1870 |
106a8bfa4f42
Upstream: fixed file buffers reinit in ngx_http_upstream_reinit().
Roman Arutyunyan <arut@nginx.com>
parents:
5832
diff
changeset
|
1871 /* 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
|
1872 |
106a8bfa4f42
Upstream: fixed file buffers reinit in ngx_http_upstream_reinit().
Roman Arutyunyan <arut@nginx.com>
parents:
5832
diff
changeset
|
1873 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
|
1874 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
|
1875 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
|
1876 } |
479 | 1877 } |
1878 | |
509 | 1879 /* reinit the subrequest's ngx_output_chain() context */ |
1880 | |
573 | 1881 if (r->request_body && r->request_body->temp_file |
597 | 1882 && r != r->main && u->output.buf) |
573 | 1883 { |
1884 u->output.free = ngx_alloc_chain_link(r->pool); | |
1885 if (u->output.free == NULL) { | |
1886 return NGX_ERROR; | |
509 | 1887 } |
573 | 1888 |
1889 u->output.free->buf = u->output.buf; | |
1890 u->output.free->next = NULL; | |
1891 | |
1892 u->output.buf->pos = u->output.buf->start; | |
1893 u->output.buf->last = u->output.buf->start; | |
509 | 1894 } |
479 | 1895 |
1896 u->output.buf = NULL; | |
1897 u->output.in = NULL; | |
1898 u->output.busy = NULL; | |
577 | 1899 |
581 | 1900 /* reinit u->buffer */ |
577 | 1901 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1902 u->buffer.pos = u->buffer.start; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1903 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1904 #if (NGX_HTTP_CACHE) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1905 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1906 if (r->cache) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1907 u->buffer.pos += r->cache->header_start; |
479 | 1908 } |
509 | 1909 |
479 | 1910 #endif |
1911 | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1912 u->buffer.last = u->buffer.pos; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1913 |
509 | 1914 return NGX_OK; |
479 | 1915 } |
1916 | |
1917 | |
487 | 1918 static void |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1919 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
|
1920 ngx_uint_t do_write) |
479 | 1921 { |
1153
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
1922 ngx_int_t rc; |
483 | 1923 ngx_connection_t *c; |
577 | 1924 |
479 | 1925 c = u->peer.connection; |
1926 | |
1927 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
1928 "http upstream send request"); | |
1929 | |
6147
74b6ef56ea56
Upstream: $upstream_connect_time.
Ruslan Ermilov <ru@nginx.com>
parents:
6146
diff
changeset
|
1930 if (u->state->connect_time == (ngx_msec_t) -1) { |
74b6ef56ea56
Upstream: $upstream_connect_time.
Ruslan Ermilov <ru@nginx.com>
parents:
6146
diff
changeset
|
1931 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
|
1932 } |
74b6ef56ea56
Upstream: $upstream_connect_time.
Ruslan Ermilov <ru@nginx.com>
parents:
6146
diff
changeset
|
1933 |
1153
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
1934 if (!u->request_sent && ngx_http_upstream_test_connect(c) != NGX_OK) { |
1166 | 1935 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
|
1936 return; |
479 | 1937 } |
1938 | |
483 | 1939 c->log->action = "sending request to upstream"; |
479 | 1940 |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1941 rc = ngx_http_upstream_send_request_body(r, u, do_write); |
479 | 1942 |
1943 if (rc == NGX_ERROR) { | |
1944 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR); | |
1945 return; | |
1946 } | |
1947 | |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1948 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1949 ngx_http_upstream_finalize_request(r, u, rc); |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1950 return; |
479 | 1951 } |
1952 | |
1953 if (rc == NGX_AGAIN) { | |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1954 if (!c->write->ready) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1955 ngx_add_timer(c->write, u->conf->send_timeout); |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1956 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1957 } else if (c->write->timer_set) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1958 ngx_del_timer(c->write); |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1959 } |
479 | 1960 |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1961 if (ngx_handle_write_event(c->write, u->conf->send_lowat) != NGX_OK) { |
479 | 1962 ngx_http_upstream_finalize_request(r, u, |
1963 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
1964 return; | |
1965 } | |
1966 | |
1967 return; | |
1968 } | |
1969 | |
1970 /* rc == NGX_OK */ | |
1971 | |
6332
78b4e10b4367
Upstream: don't keep connections on early responses (ticket #669).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6326
diff
changeset
|
1972 u->request_body_sent = 1; |
78b4e10b4367
Upstream: don't keep connections on early responses (ticket #669).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6326
diff
changeset
|
1973 |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1974 if (c->write->timer_set) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1975 ngx_del_timer(c->write); |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1976 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
1977 |
479 | 1978 if (c->tcp_nopush == NGX_TCP_NOPUSH_SET) { |
1979 if (ngx_tcp_push(c->fd) == NGX_ERROR) { | |
1980 ngx_log_error(NGX_LOG_CRIT, c->log, ngx_socket_errno, | |
1981 ngx_tcp_push_n " failed"); | |
1982 ngx_http_upstream_finalize_request(r, u, | |
1983 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
577 | 1984 return; |
479 | 1985 } |
1986 | |
1987 c->tcp_nopush = NGX_TCP_NOPUSH_UNSET; | |
1988 } | |
577 | 1989 |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
1990 u->write_event_handler = ngx_http_upstream_dummy_handler; |
479 | 1991 |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
1992 if (ngx_handle_write_event(c->write, 0) != NGX_OK) { |
479 | 1993 ngx_http_upstream_finalize_request(r, u, |
1994 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
1995 return; | |
1996 } | |
5745
9d3a9c45fc43
Upstream: fixed handling of write event after sending request.
Valentin Bartenev <vbart@nginx.com>
parents:
5738
diff
changeset
|
1997 |
9d3a9c45fc43
Upstream: fixed handling of write event after sending request.
Valentin Bartenev <vbart@nginx.com>
parents:
5738
diff
changeset
|
1998 ngx_add_timer(c->read, u->conf->read_timeout); |
9d3a9c45fc43
Upstream: fixed handling of write event after sending request.
Valentin Bartenev <vbart@nginx.com>
parents:
5738
diff
changeset
|
1999 |
9d3a9c45fc43
Upstream: fixed handling of write event after sending request.
Valentin Bartenev <vbart@nginx.com>
parents:
5738
diff
changeset
|
2000 if (c->read->ready) { |
9d3a9c45fc43
Upstream: fixed handling of write event after sending request.
Valentin Bartenev <vbart@nginx.com>
parents:
5738
diff
changeset
|
2001 ngx_http_upstream_process_header(r, u); |
9d3a9c45fc43
Upstream: fixed handling of write event after sending request.
Valentin Bartenev <vbart@nginx.com>
parents:
5738
diff
changeset
|
2002 return; |
9d3a9c45fc43
Upstream: fixed handling of write event after sending request.
Valentin Bartenev <vbart@nginx.com>
parents:
5738
diff
changeset
|
2003 } |
479 | 2004 } |
2005 | |
2006 | |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2007 static ngx_int_t |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2008 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
|
2009 ngx_http_upstream_t *u, ngx_uint_t do_write) |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2010 { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2011 int tcp_nodelay; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2012 ngx_int_t rc; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2013 ngx_chain_t *out, *cl, *ln; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2014 ngx_connection_t *c; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2015 ngx_http_core_loc_conf_t *clcf; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2016 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2017 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2018 "http upstream send request body"); |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2019 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2020 if (!r->request_body_no_buffering) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2021 |
6474 | 2022 /* buffered request body */ |
2023 | |
2024 if (!u->request_sent) { | |
2025 u->request_sent = 1; | |
2026 out = u->request_bufs; | |
2027 | |
2028 } else { | |
2029 out = NULL; | |
2030 } | |
2031 | |
2032 return ngx_output_chain(&u->output, out); | |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2033 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2034 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2035 if (!u->request_sent) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2036 u->request_sent = 1; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2037 out = u->request_bufs; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2038 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2039 if (r->request_body->bufs) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2040 for (cl = out; cl->next; cl = out->next) { /* void */ } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2041 cl->next = r->request_body->bufs; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2042 r->request_body->bufs = NULL; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2043 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2044 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2045 c = u->peer.connection; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2046 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
|
2047 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2048 if (clcf->tcp_nodelay && c->tcp_nodelay == NGX_TCP_NODELAY_UNSET) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2049 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "tcp_nodelay"); |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2050 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2051 tcp_nodelay = 1; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2052 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2053 if (setsockopt(c->fd, IPPROTO_TCP, TCP_NODELAY, |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2054 (const void *) &tcp_nodelay, sizeof(int)) == -1) |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2055 { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2056 ngx_connection_error(c, ngx_socket_errno, |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2057 "setsockopt(TCP_NODELAY) failed"); |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2058 return NGX_ERROR; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2059 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2060 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2061 c->tcp_nodelay = NGX_TCP_NODELAY_SET; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2062 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2063 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2064 r->read_event_handler = ngx_http_upstream_read_request_handler; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2065 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2066 } else { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2067 out = NULL; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2068 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2069 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2070 for ( ;; ) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2071 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2072 if (do_write) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2073 rc = ngx_output_chain(&u->output, out); |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2074 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2075 if (rc == NGX_ERROR) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2076 return NGX_ERROR; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2077 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2078 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2079 while (out) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2080 ln = out; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2081 out = out->next; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2082 ngx_free_chain(r->pool, ln); |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2083 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2084 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2085 if (rc == NGX_OK && !r->reading_body) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2086 break; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2087 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2088 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2089 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2090 if (r->reading_body) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2091 /* read client request body */ |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2092 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2093 rc = ngx_http_read_unbuffered_request_body(r); |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2094 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2095 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2096 return rc; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2097 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2098 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2099 out = r->request_body->bufs; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2100 r->request_body->bufs = NULL; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2101 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2102 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2103 /* stop if there is nothing to send */ |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2104 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2105 if (out == NULL) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2106 rc = NGX_AGAIN; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2107 break; |
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 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2110 do_write = 1; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2111 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2112 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2113 if (!r->reading_body) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2114 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
|
2115 r->read_event_handler = |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2116 ngx_http_upstream_rd_check_broken_connection; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2117 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2118 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2119 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2120 return rc; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2121 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2122 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2123 |
487 | 2124 static void |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2125 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
|
2126 ngx_http_upstream_t *u) |
479 | 2127 { |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2128 ngx_connection_t *c; |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2129 |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2130 c = u->peer.connection; |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2131 |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2132 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
479 | 2133 "http upstream send request handler"); |
2134 | |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2135 if (c->write->timedout) { |
479 | 2136 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_TIMEOUT); |
2137 return; | |
2138 } | |
2139 | |
591 | 2140 #if (NGX_HTTP_SSL) |
2141 | |
1658 | 2142 if (u->ssl && c->ssl == NULL) { |
591 | 2143 ngx_http_upstream_ssl_init_connection(r, u, c); |
2144 return; | |
2145 } | |
2146 | |
2147 #endif | |
2148 | |
651 | 2149 if (u->header_sent) { |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
2150 u->write_event_handler = ngx_http_upstream_dummy_handler; |
651 | 2151 |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2152 (void) ngx_handle_write_event(c->write, 0); |
651 | 2153 |
2154 return; | |
2155 } | |
2156 | |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2157 ngx_http_upstream_send_request(r, u, 1); |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2158 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2159 |
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 static void |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2162 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
|
2163 { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2164 ngx_connection_t *c; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2165 ngx_http_upstream_t *u; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2166 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2167 c = r->connection; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2168 u = r->upstream; |
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 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
|
2171 "http upstream read request handler"); |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2172 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2173 if (c->read->timedout) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2174 c->timedout = 1; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2175 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
|
2176 return; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2177 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2178 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6031
diff
changeset
|
2179 ngx_http_upstream_send_request(r, u, 0); |
479 | 2180 } |
2181 | |
2182 | |
487 | 2183 static void |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2184 ngx_http_upstream_process_header(ngx_http_request_t *r, ngx_http_upstream_t *u) |
479 | 2185 { |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2186 ssize_t n; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2187 ngx_int_t rc; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2188 ngx_connection_t *c; |
479 | 2189 |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2190 c = u->peer.connection; |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2191 |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2192 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, |
483 | 2193 "http upstream process header"); |
479 | 2194 |
483 | 2195 c->log->action = "reading response header from upstream"; |
479 | 2196 |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2197 if (c->read->timedout) { |
479 | 2198 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_TIMEOUT); |
2199 return; | |
2200 } | |
577 | 2201 |
1153
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2202 if (!u->request_sent && ngx_http_upstream_test_connect(c) != NGX_OK) { |
1166 | 2203 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
|
2204 return; |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2205 } |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2206 |
581 | 2207 if (u->buffer.start == NULL) { |
2208 u->buffer.start = ngx_palloc(r->pool, u->conf->buffer_size); | |
2209 if (u->buffer.start == NULL) { | |
479 | 2210 ngx_http_upstream_finalize_request(r, u, |
2211 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
2212 return; | |
2213 } | |
2214 | |
581 | 2215 u->buffer.pos = u->buffer.start; |
2216 u->buffer.last = u->buffer.start; | |
2217 u->buffer.end = u->buffer.start + u->conf->buffer_size; | |
2218 u->buffer.temporary = 1; | |
2219 | |
2220 u->buffer.tag = u->output.tag; | |
479 | 2221 |
1705 | 2222 if (ngx_list_init(&u->headers_in.headers, r->pool, 8, |
581 | 2223 sizeof(ngx_table_elt_t)) |
2224 != NGX_OK) | |
509 | 2225 { |
2226 ngx_http_upstream_finalize_request(r, u, | |
2227 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
2228 return; | |
2229 } | |
2230 | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2231 #if (NGX_HTTP_CACHE) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2232 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2233 if (r->cache) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2234 u->buffer.pos += r->cache->header_start; |
581 | 2235 u->buffer.last = u->buffer.pos; |
479 | 2236 } |
2237 #endif | |
2238 } | |
2239 | |
2360
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2240 for ( ;; ) { |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2241 |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2242 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
|
2243 |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2244 if (n == NGX_AGAIN) { |
479 | 2245 #if 0 |
2360
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2246 ngx_add_timer(rev, u->read_timeout); |
479 | 2247 #endif |
2248 | |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2249 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
|
2250 ngx_http_upstream_finalize_request(r, u, |
479 | 2251 NGX_HTTP_INTERNAL_SERVER_ERROR); |
2360
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2252 return; |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2253 } |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2254 |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2255 return; |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2256 } |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2257 |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2258 if (n == 0) { |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2259 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
|
2260 "upstream prematurely closed connection"); |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2261 } |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2262 |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2263 if (n == NGX_ERROR || n == 0) { |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2264 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR); |
479 | 2265 return; |
2266 } | |
2267 | |
6654
c131f20c9562
Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6594
diff
changeset
|
2268 u->state->bytes_received += n; |
c131f20c9562
Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6594
diff
changeset
|
2269 |
2360
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2270 u->buffer.last += n; |
479 | 2271 |
2272 #if 0 | |
2360
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2273 u->valid_header_in = 0; |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2274 |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2275 u->peer.cached = 0; |
479 | 2276 #endif |
2277 | |
2360
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2278 rc = u->process_header(r); |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2279 |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2280 if (rc == NGX_AGAIN) { |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2281 |
4460
6299d1c4dbb4
Upstream: fixed "too big header" check.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
2282 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
|
2283 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
|
2284 "upstream sent too big header"); |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2285 |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2286 ngx_http_upstream_next(r, u, |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2287 NGX_HTTP_UPSTREAM_FT_INVALID_HEADER); |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2288 return; |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2289 } |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2290 |
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2291 continue; |
479 | 2292 } |
2293 | |
2360
64854406b1f9
read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents:
2308
diff
changeset
|
2294 break; |
479 | 2295 } |
2296 | |
2297 if (rc == NGX_HTTP_UPSTREAM_INVALID_HEADER) { | |
2298 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_INVALID_HEADER); | |
2299 return; | |
2300 } | |
2301 | |
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
|
2302 if (rc == NGX_ERROR) { |
479 | 2303 ngx_http_upstream_finalize_request(r, u, |
2304 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
2305 return; | |
2306 } | |
2307 | |
2308 /* rc == NGX_OK */ | |
2309 | |
6146
59fc60585f1e
Upstream: times to obtain header/response are stored as ngx_msec_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6125
diff
changeset
|
2310 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
|
2311 |
5209
07e515e65984
Upstream: allow to intercept responses with status 300.
Ruslan Ermilov <ru@nginx.com>
parents:
5169
diff
changeset
|
2312 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
|
2313 |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2314 if (ngx_http_upstream_test_next(r, u) == NGX_OK) { |
509 | 2315 return; |
2316 } | |
2317 | |
2267
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2318 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
|
2319 return; |
487 | 2320 } |
2321 } | |
2322 | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2323 if (ngx_http_upstream_process_headers(r, u) != NGX_OK) { |
515 | 2324 return; |
2325 } | |
2326 | |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2327 if (!r->subrequest_in_memory) { |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2328 ngx_http_upstream_send_response(r, u); |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2329 return; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2330 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2331 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2332 /* subrequest content in memory */ |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2333 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2334 if (u->input_filter == NULL) { |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2335 u->input_filter_init = ngx_http_upstream_non_buffered_filter_init; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2336 u->input_filter = ngx_http_upstream_non_buffered_filter; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2337 u->input_filter_ctx = r; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2338 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2339 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2340 if (u->input_filter_init(u->input_filter_ctx) == NGX_ERROR) { |
5294
d44c3b36c53f
Upstream: consistent error handling after u->input_filter_init().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5293
diff
changeset
|
2341 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2342 return; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2343 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2344 |
2308
3f98400e31e9
memcached response was stored in variable with END
Igor Sysoev <igor@sysoev.ru>
parents:
2285
diff
changeset
|
2345 n = u->buffer.last - u->buffer.pos; |
3f98400e31e9
memcached response was stored in variable with END
Igor Sysoev <igor@sysoev.ru>
parents:
2285
diff
changeset
|
2346 |
3f98400e31e9
memcached response was stored in variable with END
Igor Sysoev <igor@sysoev.ru>
parents:
2285
diff
changeset
|
2347 if (n) { |
5216
4a40163772a1
Upstream: made the assignment more obvious.
Ruslan Ermilov <ru@nginx.com>
parents:
5209
diff
changeset
|
2348 u->buffer.last = u->buffer.pos; |
2308
3f98400e31e9
memcached response was stored in variable with END
Igor Sysoev <igor@sysoev.ru>
parents:
2285
diff
changeset
|
2349 |
2402 | 2350 u->state->response_length += n; |
2351 | |
2308
3f98400e31e9
memcached response was stored in variable with END
Igor Sysoev <igor@sysoev.ru>
parents:
2285
diff
changeset
|
2352 if (u->input_filter(u->input_filter_ctx, n) == NGX_ERROR) { |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2353 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2354 return; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2355 } |
5217
ddba4e308ecc
Upstream: slightly optimized ngx_http_upstream_process_header().
Ruslan Ermilov <ru@nginx.com>
parents:
5216
diff
changeset
|
2356 } |
ddba4e308ecc
Upstream: slightly optimized ngx_http_upstream_process_header().
Ruslan Ermilov <ru@nginx.com>
parents:
5216
diff
changeset
|
2357 |
ddba4e308ecc
Upstream: slightly optimized ngx_http_upstream_process_header().
Ruslan Ermilov <ru@nginx.com>
parents:
5216
diff
changeset
|
2358 if (u->length == 0) { |
ddba4e308ecc
Upstream: slightly optimized ngx_http_upstream_process_header().
Ruslan Ermilov <ru@nginx.com>
parents:
5216
diff
changeset
|
2359 ngx_http_upstream_finalize_request(r, u, 0); |
ddba4e308ecc
Upstream: slightly optimized ngx_http_upstream_process_header().
Ruslan Ermilov <ru@nginx.com>
parents:
5216
diff
changeset
|
2360 return; |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2361 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2362 |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
2363 u->read_event_handler = ngx_http_upstream_process_body_in_memory; |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2364 |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2365 ngx_http_upstream_process_body_in_memory(r, u); |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2366 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2367 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2368 |
1153
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2369 static ngx_int_t |
2268
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2370 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
|
2371 { |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2372 ngx_uint_t status; |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2373 ngx_http_upstream_next_t *un; |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2374 |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2375 status = u->headers_in.status_n; |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2376 |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2377 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
|
2378 |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2379 if (status != un->status) { |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2380 continue; |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2381 } |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2382 |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2383 if (u->peer.tries > 1 && (u->conf->next_upstream & un->mask)) { |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2384 ngx_http_upstream_next(r, u, un->mask); |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2385 return NGX_OK; |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2386 } |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2387 |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2388 #if (NGX_HTTP_CACHE) |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2389 |
2952 | 2390 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
|
2391 && ((u->conf->cache_use_stale & un->mask) || r->cache->stale_error)) |
2952 | 2392 { |
2824
d106509491b5
fix building --without-http-cache
Igor Sysoev <igor@sysoev.ru>
parents:
2807
diff
changeset
|
2393 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
|
2394 |
60551422e150
reinit proxy/fastcgi header parser before ngx_http_upstream_cache_send()
Igor Sysoev <igor@sysoev.ru>
parents:
2804
diff
changeset
|
2395 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
|
2396 |
60551422e150
reinit proxy/fastcgi header parser before ngx_http_upstream_cache_send()
Igor Sysoev <igor@sysoev.ru>
parents:
2804
diff
changeset
|
2397 if (rc == NGX_OK) { |
2952 | 2398 u->cache_status = NGX_HTTP_CACHE_STALE; |
2805
60551422e150
reinit proxy/fastcgi header parser before ngx_http_upstream_cache_send()
Igor Sysoev <igor@sysoev.ru>
parents:
2804
diff
changeset
|
2399 rc = ngx_http_upstream_cache_send(r, u); |
60551422e150
reinit proxy/fastcgi header parser before ngx_http_upstream_cache_send()
Igor Sysoev <igor@sysoev.ru>
parents:
2804
diff
changeset
|
2400 } |
60551422e150
reinit proxy/fastcgi header parser before ngx_http_upstream_cache_send()
Igor Sysoev <igor@sysoev.ru>
parents:
2804
diff
changeset
|
2401 |
60551422e150
reinit proxy/fastcgi header parser before ngx_http_upstream_cache_send()
Igor Sysoev <igor@sysoev.ru>
parents:
2804
diff
changeset
|
2402 ngx_http_upstream_finalize_request(r, u, rc); |
2268
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2403 return NGX_OK; |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2404 } |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2405 |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2406 #endif |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2407 } |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2408 |
5441
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2409 #if (NGX_HTTP_CACHE) |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2410 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2411 if (status == NGX_HTTP_NOT_MODIFIED |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2412 && u->cache_status == NGX_HTTP_CACHE_EXPIRED |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2413 && u->conf->cache_revalidate) |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2414 { |
6905
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
2415 time_t now, valid, updating, error; |
5441
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2416 ngx_int_t rc; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2417 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2418 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
|
2419 "http upstream not modified"); |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2420 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2421 now = ngx_time(); |
6905
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
2422 |
5441
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2423 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
|
2424 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
|
2425 error = r->cache->error_sec; |
5441
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2426 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2427 rc = u->reinit_request(r); |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2428 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2429 if (rc != NGX_OK) { |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2430 ngx_http_upstream_finalize_request(r, u, rc); |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2431 return NGX_OK; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2432 } |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2433 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2434 u->cache_status = NGX_HTTP_CACHE_REVALIDATED; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2435 rc = ngx_http_upstream_cache_send(r, u); |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2436 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2437 if (valid == 0) { |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2438 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
|
2439 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
|
2440 error = r->cache->error_sec; |
5441
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2441 } |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2442 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2443 if (valid == 0) { |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2444 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
|
2445 u->headers_in.status_n); |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2446 if (valid) { |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2447 valid = now + valid; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2448 } |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2449 } |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2450 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2451 if (valid) { |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2452 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
|
2453 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
|
2454 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
|
2455 |
5441
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2456 r->cache->date = now; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2457 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2458 ngx_http_file_cache_update_header(r); |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2459 } |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2460 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2461 ngx_http_upstream_finalize_request(r, u, rc); |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2462 return NGX_OK; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2463 } |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2464 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2465 #endif |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
2466 |
2268
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2467 return NGX_DECLINED; |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2468 } |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2469 |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2470 |
33556140681a
*) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents:
2267
diff
changeset
|
2471 static ngx_int_t |
2267
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2472 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
|
2473 ngx_http_upstream_t *u) |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2474 { |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2475 ngx_int_t status; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2476 ngx_uint_t i; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2477 ngx_table_elt_t *h; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2478 ngx_http_err_page_t *err_page; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2479 ngx_http_core_loc_conf_t *clcf; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2480 |
2441
0c117a89f399
in miss case memcached module returned END instead of default 404 page body
Igor Sysoev <igor@sysoev.ru>
parents:
2422
diff
changeset
|
2481 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
|
2482 |
0c117a89f399
in miss case memcached module returned END instead of default 404 page body
Igor Sysoev <igor@sysoev.ru>
parents:
2422
diff
changeset
|
2483 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
|
2484 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
|
2485 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
|
2486 } |
0c117a89f399
in miss case memcached module returned END instead of default 404 page body
Igor Sysoev <igor@sysoev.ru>
parents:
2422
diff
changeset
|
2487 |
2267
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2488 if (!u->conf->intercept_errors) { |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2489 return NGX_DECLINED; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2490 } |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2491 |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2492 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
|
2493 |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2494 if (clcf->error_pages == NULL) { |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2495 return NGX_DECLINED; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2496 } |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2497 |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2498 err_page = clcf->error_pages->elts; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2499 for (i = 0; i < clcf->error_pages->nelts; i++) { |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2500 |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2501 if (err_page[i].status == status) { |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2502 |
2953
aa12525236da
fix segfault if there is error_page 401, proxy_intercept_errors is on
Igor Sysoev <igor@sysoev.ru>
parents:
2952
diff
changeset
|
2503 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
|
2504 && 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
|
2505 { |
2267
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2506 h = ngx_list_push(&r->headers_out.headers); |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2507 |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2508 if (h == NULL) { |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2509 ngx_http_upstream_finalize_request(r, u, |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2510 NGX_HTTP_INTERNAL_SERVER_ERROR); |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2511 return NGX_OK; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2512 } |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2513 |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2514 *h = *u->headers_in.www_authenticate; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2515 |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2516 r->headers_out.www_authenticate = h; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2517 } |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2518 |
3706
ea908f6ae499
an intercepted error code was not cached
Igor Sysoev <igor@sysoev.ru>
parents:
3705
diff
changeset
|
2519 #if (NGX_HTTP_CACHE) |
ea908f6ae499
an intercepted error code was not cached
Igor Sysoev <igor@sysoev.ru>
parents:
3705
diff
changeset
|
2520 |
3709
64777690c697
fix r3707: cache node should be freed be a response is not cached
Igor Sysoev <igor@sysoev.ru>
parents:
3708
diff
changeset
|
2521 if (r->cache) { |
3706
ea908f6ae499
an intercepted error code was not cached
Igor Sysoev <igor@sysoev.ru>
parents:
3705
diff
changeset
|
2522 time_t valid; |
ea908f6ae499
an intercepted error code was not cached
Igor Sysoev <igor@sysoev.ru>
parents:
3705
diff
changeset
|
2523 |
ea908f6ae499
an intercepted error code was not cached
Igor Sysoev <igor@sysoev.ru>
parents:
3705
diff
changeset
|
2524 valid = ngx_http_file_cache_valid(u->conf->cache_valid, status); |
ea908f6ae499
an intercepted error code was not cached
Igor Sysoev <igor@sysoev.ru>
parents:
3705
diff
changeset
|
2525 |
ea908f6ae499
an intercepted error code was not cached
Igor Sysoev <igor@sysoev.ru>
parents:
3705
diff
changeset
|
2526 if (valid) { |
ea908f6ae499
an intercepted error code was not cached
Igor Sysoev <igor@sysoev.ru>
parents:
3705
diff
changeset
|
2527 r->cache->valid_sec = ngx_time() + valid; |
ea908f6ae499
an intercepted error code was not cached
Igor Sysoev <igor@sysoev.ru>
parents:
3705
diff
changeset
|
2528 r->cache->error = status; |
ea908f6ae499
an intercepted error code was not cached
Igor Sysoev <igor@sysoev.ru>
parents:
3705
diff
changeset
|
2529 } |
ea908f6ae499
an intercepted error code was not cached
Igor Sysoev <igor@sysoev.ru>
parents:
3705
diff
changeset
|
2530 |
3711
ce6ba077c270
several changes in cache cleanup handling:
Igor Sysoev <igor@sysoev.ru>
parents:
3709
diff
changeset
|
2531 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
|
2532 } |
ea908f6ae499
an intercepted error code was not cached
Igor Sysoev <igor@sysoev.ru>
parents:
3705
diff
changeset
|
2533 #endif |
2267
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2534 ngx_http_upstream_finalize_request(r, u, status); |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2535 |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2536 return NGX_OK; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2537 } |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2538 } |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2539 |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2540 return NGX_DECLINED; |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2541 } |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2542 |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2543 |
920be89a3d2d
ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents:
2244
diff
changeset
|
2544 static ngx_int_t |
1153
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2545 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
|
2546 { |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2547 int err; |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2548 socklen_t len; |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2549 |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2550 #if (NGX_HAVE_KQUEUE) |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2551 |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2552 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
|
2553 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
|
2554 if (c->write->pending_eof) { |
e62219793beb
Upstream: better detection of connect() failures with kqueue.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4895
diff
changeset
|
2555 err = c->write->kq_errno; |
e62219793beb
Upstream: better detection of connect() failures with kqueue.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4895
diff
changeset
|
2556 |
e62219793beb
Upstream: better detection of connect() failures with kqueue.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4895
diff
changeset
|
2557 } else { |
e62219793beb
Upstream: better detection of connect() failures with kqueue.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4895
diff
changeset
|
2558 err = c->read->kq_errno; |
e62219793beb
Upstream: better detection of connect() failures with kqueue.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4895
diff
changeset
|
2559 } |
e62219793beb
Upstream: better detection of connect() failures with kqueue.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4895
diff
changeset
|
2560 |
1469
0a269c464eaf
connection error should be logged with "connecting to upstream" action,
Igor Sysoev <igor@sysoev.ru>
parents:
1468
diff
changeset
|
2561 c->log->action = "connecting to upstream"; |
4916
79c8e87b1fcb
Trailing whitespace fix.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4915
diff
changeset
|
2562 (void) ngx_connection_error(c, err, |
1166 | 2563 "kevent() reported that connect() failed"); |
2564 return NGX_ERROR; | |
2565 } | |
1153
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2566 |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2567 } else |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2568 #endif |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2569 { |
1166 | 2570 err = 0; |
2571 len = sizeof(int); | |
2572 | |
2573 /* | |
2574 * BSDs and Linux return 0 and set a pending error in err | |
2575 * Solaris returns -1 and sets errno | |
2576 */ | |
2577 | |
2578 if (getsockopt(c->fd, SOL_SOCKET, SO_ERROR, (void *) &err, &len) | |
2579 == -1) | |
2580 { | |
5557
188481078faf
Use ngx_socket_errno where appropriate.
Piotr Sikora <piotr@cloudflare.com>
parents:
5546
diff
changeset
|
2581 err = ngx_socket_errno; |
1166 | 2582 } |
2583 | |
2584 if (err) { | |
1469
0a269c464eaf
connection error should be logged with "connecting to upstream" action,
Igor Sysoev <igor@sysoev.ru>
parents:
1468
diff
changeset
|
2585 c->log->action = "connecting to upstream"; |
1166 | 2586 (void) ngx_connection_error(c, err, "connect() failed"); |
2587 return NGX_ERROR; | |
2588 } | |
1153
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2589 } |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2590 |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2591 return NGX_OK; |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2592 } |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2593 |
c843f3df3b85
separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents:
1143
diff
changeset
|
2594 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2595 static ngx_int_t |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2596 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
|
2597 { |
5489
6d357b2a9d6e
Upstream: keep $upstream_http_x_accel_redirect intact.
Ruslan Ermilov <ru@nginx.com>
parents:
5477
diff
changeset
|
2598 ngx_str_t uri, args; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2599 ngx_uint_t i, flags; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2600 ngx_list_part_t *part; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2601 ngx_table_elt_t *h; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2602 ngx_http_upstream_header_t *hh; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2603 ngx_http_upstream_main_conf_t *umcf; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2604 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2605 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
|
2606 |
2786
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
2607 if (u->headers_in.x_accel_redirect |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
2608 && !(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
|
2609 { |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2610 ngx_http_upstream_finalize_request(r, u, NGX_DECLINED); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2611 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2612 part = &u->headers_in.headers.part; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2613 h = part->elts; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2614 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2615 for (i = 0; /* void */; i++) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2616 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2617 if (i >= part->nelts) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2618 if (part->next == NULL) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2619 break; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2620 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2621 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2622 part = part->next; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2623 h = part->elts; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2624 i = 0; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2625 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2626 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2627 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
|
2628 h[i].lowcase_key, h[i].key.len); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2629 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2630 if (hh && hh->redirect) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2631 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
|
2632 ngx_http_finalize_request(r, |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2633 NGX_HTTP_INTERNAL_SERVER_ERROR); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2634 return NGX_DONE; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2635 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2636 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2637 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2638 |
5489
6d357b2a9d6e
Upstream: keep $upstream_http_x_accel_redirect intact.
Ruslan Ermilov <ru@nginx.com>
parents:
5477
diff
changeset
|
2639 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
|
2640 |
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2641 if (uri.data[0] == '@') { |
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2642 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
|
2643 |
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2644 } else { |
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2645 ngx_str_null(&args); |
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2646 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
|
2647 |
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2648 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
|
2649 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
|
2650 return NGX_DONE; |
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2651 } |
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2652 |
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2653 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
|
2654 r->method = NGX_HTTP_GET; |
6334
b31928ca3870
Upstream: fixed changing method on X-Accel-Redirect.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6332
diff
changeset
|
2655 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
|
2656 } |
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2657 |
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2658 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
|
2659 } |
7d7eac6e31df
Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents:
5885
diff
changeset
|
2660 |
3120
40b8b398dbbc
fix request counter for X-Accel-Redirect, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3112
diff
changeset
|
2661 ngx_http_finalize_request(r, NGX_DONE); |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2662 return NGX_DONE; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2663 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2664 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2665 part = &u->headers_in.headers.part; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2666 h = part->elts; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2667 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2668 for (i = 0; /* void */; i++) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2669 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2670 if (i >= part->nelts) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2671 if (part->next == NULL) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2672 break; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2673 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2674 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2675 part = part->next; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2676 h = part->elts; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2677 i = 0; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2678 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2679 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2680 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
|
2681 h[i].lowcase_key, h[i].key.len)) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2682 { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2683 continue; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2684 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2685 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2686 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
|
2687 h[i].lowcase_key, h[i].key.len); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2688 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2689 if (hh) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2690 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
|
2691 ngx_http_upstream_finalize_request(r, u, |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2692 NGX_HTTP_INTERNAL_SERVER_ERROR); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2693 return NGX_DONE; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2694 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2695 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2696 continue; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2697 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2698 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2699 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
|
2700 ngx_http_upstream_finalize_request(r, u, |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2701 NGX_HTTP_INTERNAL_SERVER_ERROR); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2702 return NGX_DONE; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2703 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2704 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2705 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2706 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
|
2707 r->headers_out.server->hash = 0; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2708 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2709 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2710 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
|
2711 r->headers_out.date->hash = 0; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2712 } |
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 r->headers_out.status = u->headers_in.status_n; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2715 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
|
2716 |
4117
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
2717 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
|
2718 |
5735
5fb1e57c758a
Entity tags: explicit flag to skip not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5732
diff
changeset
|
2719 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
|
2720 |
5874
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
2721 if (u->conf->force_ranges) { |
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
2722 r->allow_ranges = 1; |
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
2723 r->single_range = 1; |
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
2724 |
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
2725 #if (NGX_HTTP_CACHE) |
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
2726 if (r->cached) { |
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
2727 r->single_range = 0; |
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
2728 } |
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
2729 #endif |
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
2730 } |
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
2731 |
5300
f538a67c9f77
Upstream: u->length now defaults to -1 (API change).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5299
diff
changeset
|
2732 u->length = -1; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2733 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2734 return NGX_OK; |
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 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2737 |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2738 static void |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2739 ngx_http_upstream_process_body_in_memory(ngx_http_request_t *r, |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2740 ngx_http_upstream_t *u) |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2741 { |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2742 size_t size; |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2743 ssize_t n; |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2744 ngx_buf_t *b; |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2745 ngx_event_t *rev; |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2746 ngx_connection_t *c; |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2747 |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2748 c = u->peer.connection; |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2749 rev = c->read; |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2750 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2751 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2752 "http upstream process body on memory"); |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2753 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2754 if (rev->timedout) { |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2755 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
|
2756 ngx_http_upstream_finalize_request(r, u, NGX_HTTP_GATEWAY_TIME_OUT); |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2757 return; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2758 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2759 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2760 b = &u->buffer; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2761 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2762 for ( ;; ) { |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2763 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2764 size = b->end - b->last; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2765 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2766 if (size == 0) { |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2767 ngx_log_error(NGX_LOG_ALERT, c->log, 0, |
3708 | 2768 "upstream buffer is too small to read response"); |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2769 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2770 return; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2771 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2772 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2773 n = c->recv(c, b->last, size); |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2774 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2775 if (n == NGX_AGAIN) { |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2776 break; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2777 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2778 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2779 if (n == 0 || n == NGX_ERROR) { |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2780 ngx_http_upstream_finalize_request(r, u, n); |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2781 return; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2782 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2783 |
6654
c131f20c9562
Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6594
diff
changeset
|
2784 u->state->bytes_received += n; |
2402 | 2785 u->state->response_length += n; |
2786 | |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2787 if (u->input_filter(u->input_filter_ctx, n) == NGX_ERROR) { |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2788 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2789 return; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2790 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2791 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2792 if (!rev->ready) { |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2793 break; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2794 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2795 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2796 |
4120
42135dd1f0ea
Upstream: keepalive flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4119
diff
changeset
|
2797 if (u->length == 0) { |
42135dd1f0ea
Upstream: keepalive flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4119
diff
changeset
|
2798 ngx_http_upstream_finalize_request(r, u, 0); |
42135dd1f0ea
Upstream: keepalive flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4119
diff
changeset
|
2799 return; |
42135dd1f0ea
Upstream: keepalive flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4119
diff
changeset
|
2800 } |
42135dd1f0ea
Upstream: keepalive flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4119
diff
changeset
|
2801 |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
2802 if (ngx_handle_read_event(rev, 0) != NGX_OK) { |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2803 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2804 return; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2805 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2806 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2807 if (rev->active) { |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2808 ngx_add_timer(rev, u->conf->read_timeout); |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2809 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2810 } else if (rev->timer_set) { |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2811 ngx_del_timer(rev); |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
757
diff
changeset
|
2812 } |
681 | 2813 } |
2814 | |
2815 | |
2816 static void | |
2817 ngx_http_upstream_send_response(ngx_http_request_t *r, ngx_http_upstream_t *u) | |
2818 { | |
2819 int tcp_nodelay; | |
2402 | 2820 ssize_t n; |
681 | 2821 ngx_int_t rc; |
2822 ngx_event_pipe_t *p; | |
2823 ngx_connection_t *c; | |
2824 ngx_http_core_loc_conf_t *clcf; | |
2825 | |
509 | 2826 rc = ngx_http_send_header(r); |
479 | 2827 |
2701 | 2828 if (rc == NGX_ERROR || rc > NGX_OK || r->post_action) { |
485 | 2829 ngx_http_upstream_finalize_request(r, u, rc); |
479 | 2830 return; |
2831 } | |
2832 | |
5353
1608b1135a1d
Upstream: setting u->header_sent before ngx_http_upstream_upgrade().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5340
diff
changeset
|
2833 u->header_sent = 1; |
1608b1135a1d
Upstream: setting u->header_sent before ngx_http_upstream_upgrade().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5340
diff
changeset
|
2834 |
5072
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2835 if (u->upgrade) { |
6794
93b294c5d581
Upstream: avoid holding a cache node with upgraded connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6793
diff
changeset
|
2836 |
93b294c5d581
Upstream: avoid holding a cache node with upgraded connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6793
diff
changeset
|
2837 #if (NGX_HTTP_CACHE) |
93b294c5d581
Upstream: avoid holding a cache node with upgraded connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6793
diff
changeset
|
2838 |
93b294c5d581
Upstream: avoid holding a cache node with upgraded connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6793
diff
changeset
|
2839 if (r->cache) { |
93b294c5d581
Upstream: avoid holding a cache node with upgraded connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6793
diff
changeset
|
2840 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
|
2841 } |
93b294c5d581
Upstream: avoid holding a cache node with upgraded connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6793
diff
changeset
|
2842 |
93b294c5d581
Upstream: avoid holding a cache node with upgraded connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6793
diff
changeset
|
2843 #endif |
93b294c5d581
Upstream: avoid holding a cache node with upgraded connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6793
diff
changeset
|
2844 |
5072
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2845 ngx_http_upstream_upgrade(r, u); |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2846 return; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2847 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
2848 |
2704
ac1e2e199c9f
shutdown client connection for cacheable header only responses
Igor Sysoev <igor@sysoev.ru>
parents:
2703
diff
changeset
|
2849 c = r->connection; |
ac1e2e199c9f
shutdown client connection for cacheable header only responses
Igor Sysoev <igor@sysoev.ru>
parents:
2703
diff
changeset
|
2850 |
2701 | 2851 if (r->header_only) { |
2704
ac1e2e199c9f
shutdown client connection for cacheable header only responses
Igor Sysoev <igor@sysoev.ru>
parents:
2703
diff
changeset
|
2852 |
5746
35990c69b3ac
Upstream: p->downstream_error instead of closing connection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5745
diff
changeset
|
2853 if (!u->buffering) { |
2701 | 2854 ngx_http_upstream_finalize_request(r, u, rc); |
2855 return; | |
2856 } | |
5746
35990c69b3ac
Upstream: p->downstream_error instead of closing connection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5745
diff
changeset
|
2857 |
35990c69b3ac
Upstream: p->downstream_error instead of closing connection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5745
diff
changeset
|
2858 if (!u->cacheable && !u->store) { |
35990c69b3ac
Upstream: p->downstream_error instead of closing connection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5745
diff
changeset
|
2859 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
|
2860 return; |
35990c69b3ac
Upstream: p->downstream_error instead of closing connection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5745
diff
changeset
|
2861 } |
35990c69b3ac
Upstream: p->downstream_error instead of closing connection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5745
diff
changeset
|
2862 |
35990c69b3ac
Upstream: p->downstream_error instead of closing connection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5745
diff
changeset
|
2863 u->pipe->downstream_error = 1; |
2701 | 2864 } |
2865 | |
573 | 2866 if (r->request_body && r->request_body->temp_file) { |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2867 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
|
2868 r->request_body->temp_file->file.fd = NGX_INVALID_FILE; |
563 | 2869 } |
2870 | |
581 | 2871 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
2872 | |
649 | 2873 if (!u->buffering) { |
581 | 2874 |
6794
93b294c5d581
Upstream: avoid holding a cache node with upgraded connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6793
diff
changeset
|
2875 #if (NGX_HTTP_CACHE) |
93b294c5d581
Upstream: avoid holding a cache node with upgraded connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6793
diff
changeset
|
2876 |
93b294c5d581
Upstream: avoid holding a cache node with upgraded connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6793
diff
changeset
|
2877 if (r->cache) { |
93b294c5d581
Upstream: avoid holding a cache node with upgraded connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6793
diff
changeset
|
2878 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
|
2879 } |
93b294c5d581
Upstream: avoid holding a cache node with upgraded connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6793
diff
changeset
|
2880 |
93b294c5d581
Upstream: avoid holding a cache node with upgraded connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6793
diff
changeset
|
2881 #endif |
93b294c5d581
Upstream: avoid holding a cache node with upgraded connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6793
diff
changeset
|
2882 |
581 | 2883 if (u->input_filter == NULL) { |
2884 u->input_filter_init = ngx_http_upstream_non_buffered_filter_init; | |
2885 u->input_filter = ngx_http_upstream_non_buffered_filter; | |
2886 u->input_filter_ctx = r; | |
2887 } | |
2888 | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2889 u->read_event_handler = ngx_http_upstream_process_non_buffered_upstream; |
581 | 2890 r->write_event_handler = |
2891 ngx_http_upstream_process_non_buffered_downstream; | |
2892 | |
2893 r->limit_rate = 0; | |
2894 | |
2895 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
|
2896 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
581 | 2897 return; |
2898 } | |
2899 | |
583 | 2900 if (clcf->tcp_nodelay && c->tcp_nodelay == NGX_TCP_NODELAY_UNSET) { |
2901 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "tcp_nodelay"); | |
2902 | |
2903 tcp_nodelay = 1; | |
2904 | |
2905 if (setsockopt(c->fd, IPPROTO_TCP, TCP_NODELAY, | |
2906 (const void *) &tcp_nodelay, sizeof(int)) == -1) | |
2907 { | |
2908 ngx_connection_error(c, ngx_socket_errno, | |
2909 "setsockopt(TCP_NODELAY) failed"); | |
5295
a489c31c9783
Upstream: ngx_http_upstream_finalize_request(NGX_ERROR) on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5294
diff
changeset
|
2910 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
583 | 2911 return; |
2912 } | |
2913 | |
2914 c->tcp_nodelay = NGX_TCP_NODELAY_SET; | |
2915 } | |
2916 | |
2402 | 2917 n = u->buffer.last - u->buffer.pos; |
2918 | |
2919 if (n) { | |
581 | 2920 u->buffer.last = u->buffer.pos; |
2921 | |
2402 | 2922 u->state->response_length += n; |
2923 | |
2924 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
|
2925 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
581 | 2926 return; |
2927 } | |
2928 | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
2929 ngx_http_upstream_process_non_buffered_downstream(r); |
581 | 2930 |
2931 } else { | |
2932 u->buffer.pos = u->buffer.start; | |
2933 u->buffer.last = u->buffer.start; | |
2934 | |
2935 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
|
2936 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
581 | 2937 return; |
2938 } | |
1468
491e5059ea19
read EOF of header only responses in non-buffered proxying
Igor Sysoev <igor@sysoev.ru>
parents:
1397
diff
changeset
|
2939 |
4120
42135dd1f0ea
Upstream: keepalive flag.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4119
diff
changeset
|
2940 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
|
2941 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
|
2942 } |
581 | 2943 } |
2944 | |
2945 return; | |
2946 } | |
2947 | |
479 | 2948 /* TODO: preallocate event_pipe bufs, look "Content-Length" */ |
2949 | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2950 #if (NGX_HTTP_CACHE) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2951 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2952 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
|
2953 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
|
2954 r->cache->file.fd = NGX_INVALID_FILE; |
479 | 2955 } |
2956 | |
3699
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2957 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
|
2958 |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2959 case NGX_ERROR: |
5295
a489c31c9783
Upstream: ngx_http_upstream_finalize_request(NGX_ERROR) on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5294
diff
changeset
|
2960 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
|
2961 return; |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2962 |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2963 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
|
2964 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
|
2965 break; |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2966 |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2967 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
|
2968 |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2969 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
|
2970 |
5950
eaeecf00d5d7
Upstream: preset some cache configuration when bypassing.
Valentin Bartenev <vbart@nginx.com>
parents:
5949
diff
changeset
|
2971 /* 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
|
2972 |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2973 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
|
2974 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
|
2975 return; |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2976 } |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2977 } |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2978 |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2979 break; |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2980 } |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
2981 |
1565 | 2982 if (u->cacheable) { |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2983 time_t now, valid; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2984 |
2663
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
2985 now = ngx_time(); |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
2986 |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
2987 valid = r->cache->valid_sec; |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
2988 |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
2989 if (valid == 0) { |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
2990 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
|
2991 u->headers_in.status_n); |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
2992 if (valid) { |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
2993 r->cache->valid_sec = now + valid; |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
2994 } |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
2995 } |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
2996 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2997 if (valid) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2998 r->cache->date = now; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2999 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
|
3000 |
5935
1573fc7875fa
Cache: send conditional requests only for cached 200/206 responses.
Piotr Sikora <piotr@cloudflare.com>
parents:
5928
diff
changeset
|
3001 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
|
3002 || 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
|
3003 { |
1573fc7875fa
Cache: send conditional requests only for cached 200/206 responses.
Piotr Sikora <piotr@cloudflare.com>
parents:
5928
diff
changeset
|
3004 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
|
3005 |
1573fc7875fa
Cache: send conditional requests only for cached 200/206 responses.
Piotr Sikora <piotr@cloudflare.com>
parents:
5928
diff
changeset
|
3006 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
|
3007 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
|
3008 |
174512857ccf
Cache: do not inherit last_modified and etag from stale response.
Roman Arutyunyan <arut@nginx.com>
parents:
5977
diff
changeset
|
3009 } else { |
174512857ccf
Cache: do not inherit last_modified and etag from stale response.
Roman Arutyunyan <arut@nginx.com>
parents:
5977
diff
changeset
|
3010 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
|
3011 } |
5992
174512857ccf
Cache: do not inherit last_modified and etag from stale response.
Roman Arutyunyan <arut@nginx.com>
parents:
5977
diff
changeset
|
3012 |
174512857ccf
Cache: do not inherit last_modified and etag from stale response.
Roman Arutyunyan <arut@nginx.com>
parents:
5977
diff
changeset
|
3013 } else { |
174512857ccf
Cache: do not inherit last_modified and etag from stale response.
Roman Arutyunyan <arut@nginx.com>
parents:
5977
diff
changeset
|
3014 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
|
3015 ngx_str_null(&r->cache->etag); |
5737
44b9ab7752e3
Cache: ETag now saved into cache header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5735
diff
changeset
|
3016 } |
44b9ab7752e3
Cache: ETag now saved into cache header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5735
diff
changeset
|
3017 |
5959
f7584d7c0ccb
Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents:
5951
diff
changeset
|
3018 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
|
3019 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
|
3020 return; |
f7584d7c0ccb
Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents:
5951
diff
changeset
|
3021 } |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3022 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3023 } else { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3024 u->cacheable = 0; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3025 } |
479 | 3026 } |
3027 | |
2690 | 3028 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, |
3029 "http cacheable: %d", u->cacheable); | |
3030 | |
3083
ffe8bfb38184
clean cache updating state if a response has uncacheable code or
Igor Sysoev <igor@sysoev.ru>
parents:
3056
diff
changeset
|
3031 if (u->cacheable == 0 && r->cache) { |
3711
ce6ba077c270
several changes in cache cleanup handling:
Igor Sysoev <igor@sysoev.ru>
parents:
3709
diff
changeset
|
3032 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
|
3033 } |
ffe8bfb38184
clean cache updating state if a response has uncacheable code or
Igor Sysoev <igor@sysoev.ru>
parents:
3056
diff
changeset
|
3034 |
6428
545b5e4d83b2
Upstream: avoid closing client connection in edge case.
Justin Li <jli.justinli@gmail.com>
parents:
6427
diff
changeset
|
3035 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
|
3036 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
|
3037 return; |
545b5e4d83b2
Upstream: avoid closing client connection in edge case.
Justin Li <jli.justinli@gmail.com>
parents:
6427
diff
changeset
|
3038 } |
545b5e4d83b2
Upstream: avoid closing client connection in edge case.
Justin Li <jli.justinli@gmail.com>
parents:
6427
diff
changeset
|
3039 |
479 | 3040 #endif |
3041 | |
581 | 3042 p = u->pipe; |
479 | 3043 |
6443
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3044 p->output_filter = ngx_http_upstream_output_filter; |
479 | 3045 p->output_ctx = r; |
3046 p->tag = u->output.tag; | |
577 | 3047 p->bufs = u->conf->bufs; |
479 | 3048 p->busy_size = u->conf->busy_buffers_size; |
3049 p->upstream = u->peer.connection; | |
583 | 3050 p->downstream = c; |
479 | 3051 p->pool = r->pool; |
583 | 3052 p->log = c->log; |
5883
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3053 p->limit_rate = u->conf->limit_rate; |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3054 p->start_sec = ngx_time(); |
577 | 3055 |
1565 | 3056 p->cacheable = u->cacheable || u->store; |
479 | 3057 |
501 | 3058 p->temp_file = ngx_pcalloc(r->pool, sizeof(ngx_temp_file_t)); |
3059 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
|
3060 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
479 | 3061 return; |
3062 } | |
3063 | |
3064 p->temp_file->file.fd = NGX_INVALID_FILE; | |
583 | 3065 p->temp_file->file.log = c->log; |
479 | 3066 p->temp_file->path = u->conf->temp_path; |
3067 p->temp_file->pool = r->pool; | |
577 | 3068 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3069 if (p->cacheable) { |
479 | 3070 p->temp_file->persistent = 1; |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3071 |
5960
e9effef98874
Upstream: use_temp_path parameter of proxy_cache_path and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5959
diff
changeset
|
3072 #if (NGX_HTTP_CACHE) |
6795
1a917932db96
Cache: prefix-based temporary files.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6794
diff
changeset
|
3073 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
|
3074 p->temp_file->path = r->cache->file_cache->path; |
1a917932db96
Cache: prefix-based temporary files.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6794
diff
changeset
|
3075 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
|
3076 } |
e9effef98874
Upstream: use_temp_path parameter of proxy_cache_path and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5959
diff
changeset
|
3077 #endif |
e9effef98874
Upstream: use_temp_path parameter of proxy_cache_path and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5959
diff
changeset
|
3078 |
479 | 3079 } else { |
667 | 3080 p->temp_file->log_level = NGX_LOG_WARN; |
479 | 3081 p->temp_file->warn = "an upstream response is buffered " |
3082 "to a temporary file"; | |
3083 } | |
3084 | |
3085 p->max_temp_file_size = u->conf->max_temp_file_size; | |
3086 p->temp_file_write_size = u->conf->temp_file_write_size; | |
3087 | |
6443
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3088 #if (NGX_THREADS) |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3089 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
|
3090 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
|
3091 p->thread_ctx = r; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3092 } |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3093 #endif |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3094 |
501 | 3095 p->preread_bufs = ngx_alloc_chain_link(r->pool); |
3096 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
|
3097 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
479 | 3098 return; |
3099 } | |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3100 |
581 | 3101 p->preread_bufs->buf = &u->buffer; |
479 | 3102 p->preread_bufs->next = NULL; |
581 | 3103 u->buffer.recycled = 1; |
3104 | |
3105 p->preread_size = u->buffer.last - u->buffer.pos; | |
479 | 3106 |
1565 | 3107 if (u->cacheable) { |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3108 |
479 | 3109 p->buf_to_file = ngx_calloc_buf(r->pool); |
3110 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
|
3111 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
479 | 3112 return; |
3113 } | |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3114 |
4895
508e61393b6c
Event pipe: fixed handling of buf_to_file data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4769
diff
changeset
|
3115 p->buf_to_file->start = u->buffer.start; |
581 | 3116 p->buf_to_file->pos = u->buffer.start; |
3117 p->buf_to_file->last = u->buffer.pos; | |
479 | 3118 p->buf_to_file->temporary = 1; |
3119 } | |
3120 | |
6125
4dc8e7b62216
Removed the obsolete aio module.
Ruslan Ermilov <ru@nginx.com>
parents:
6068
diff
changeset
|
3121 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
|
3122 /* the posted aio operation may corrupt a shadow buffer */ |
479 | 3123 p->single_buf = 1; |
3124 } | |
3125 | |
3126 /* TODO: p->free_bufs = 0 if use ngx_create_chain_of_bufs() */ | |
3127 p->free_bufs = 1; | |
3128 | |
3129 /* | |
581 | 3130 * event_pipe would do u->buffer.last += p->preread_size |
479 | 3131 * as though these bytes were read |
3132 */ | |
581 | 3133 u->buffer.last = u->buffer.pos; |
479 | 3134 |
3135 if (u->conf->cyclic_temp_file) { | |
3136 | |
3137 /* | |
3138 * we need to disable the use of sendfile() if we use cyclic temp file | |
3139 * because the writing a new data may interfere with sendfile() | |
3140 * that uses the same kernel file pages (at least on FreeBSD) | |
3141 */ | |
3142 | |
3143 p->cyclic_temp_file = 1; | |
583 | 3144 c->sendfile = 0; |
479 | 3145 |
3146 } else { | |
3147 p->cyclic_temp_file = 0; | |
3148 } | |
3149 | |
3150 p->read_timeout = u->conf->read_timeout; | |
3151 p->send_timeout = clcf->send_timeout; | |
3152 p->send_lowat = clcf->send_lowat; | |
3153 | |
4119
b66712cde67d
Upstream: pipe length and input_filter_init in buffered mode.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4118
diff
changeset
|
3154 p->length = -1; |
b66712cde67d
Upstream: pipe length and input_filter_init in buffered mode.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4118
diff
changeset
|
3155 |
b66712cde67d
Upstream: pipe length and input_filter_init in buffered mode.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4118
diff
changeset
|
3156 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
|
3157 && 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
|
3158 { |
5295
a489c31c9783
Upstream: ngx_http_upstream_finalize_request(NGX_ERROR) on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5294
diff
changeset
|
3159 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
|
3160 return; |
b66712cde67d
Upstream: pipe length and input_filter_init in buffered mode.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4118
diff
changeset
|
3161 } |
b66712cde67d
Upstream: pipe length and input_filter_init in buffered mode.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4118
diff
changeset
|
3162 |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3163 u->read_event_handler = ngx_http_upstream_process_upstream; |
509 | 3164 r->write_event_handler = ngx_http_upstream_process_downstream; |
479 | 3165 |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
3166 ngx_http_upstream_process_upstream(r, u); |
479 | 3167 } |
3168 | |
3169 | |
487 | 3170 static void |
5072
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3171 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
|
3172 { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3173 int tcp_nodelay; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3174 ngx_connection_t *c; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3175 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
|
3176 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3177 c = r->connection; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3178 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
|
3179 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3180 /* 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
|
3181 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3182 r->keepalive = 0; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3183 c->log->action = "proxying upgraded connection"; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3184 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3185 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
|
3186 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
|
3187 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
|
3188 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
|
3189 |
5142
afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5132
diff
changeset
|
3190 if (clcf->tcp_nodelay) { |
5072
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3191 tcp_nodelay = 1; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3192 |
5142
afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5132
diff
changeset
|
3193 if (c->tcp_nodelay == NGX_TCP_NODELAY_UNSET) { |
afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5132
diff
changeset
|
3194 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "tcp_nodelay"); |
afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5132
diff
changeset
|
3195 |
afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5132
diff
changeset
|
3196 if (setsockopt(c->fd, IPPROTO_TCP, TCP_NODELAY, |
afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5132
diff
changeset
|
3197 (const void *) &tcp_nodelay, sizeof(int)) == -1) |
afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5132
diff
changeset
|
3198 { |
afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5132
diff
changeset
|
3199 ngx_connection_error(c, ngx_socket_errno, |
afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5132
diff
changeset
|
3200 "setsockopt(TCP_NODELAY) failed"); |
5295
a489c31c9783
Upstream: ngx_http_upstream_finalize_request(NGX_ERROR) on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5294
diff
changeset
|
3201 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
5142
afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5132
diff
changeset
|
3202 return; |
afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5132
diff
changeset
|
3203 } |
afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5132
diff
changeset
|
3204 |
afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5132
diff
changeset
|
3205 c->tcp_nodelay = NGX_TCP_NODELAY_SET; |
5072
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3206 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3207 |
5142
afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5132
diff
changeset
|
3208 if (u->peer.connection->tcp_nodelay == NGX_TCP_NODELAY_UNSET) { |
afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5132
diff
changeset
|
3209 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, u->peer.connection->log, 0, |
afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5132
diff
changeset
|
3210 "tcp_nodelay"); |
afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5132
diff
changeset
|
3211 |
afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5132
diff
changeset
|
3212 if (setsockopt(u->peer.connection->fd, IPPROTO_TCP, TCP_NODELAY, |
afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5132
diff
changeset
|
3213 (const void *) &tcp_nodelay, sizeof(int)) == -1) |
afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5132
diff
changeset
|
3214 { |
afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5132
diff
changeset
|
3215 ngx_connection_error(u->peer.connection, ngx_socket_errno, |
afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5132
diff
changeset
|
3216 "setsockopt(TCP_NODELAY) failed"); |
5295
a489c31c9783
Upstream: ngx_http_upstream_finalize_request(NGX_ERROR) on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5294
diff
changeset
|
3217 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
5142
afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5132
diff
changeset
|
3218 return; |
afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5132
diff
changeset
|
3219 } |
afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5132
diff
changeset
|
3220 |
afea5259e05c
Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5132
diff
changeset
|
3221 u->peer.connection->tcp_nodelay = NGX_TCP_NODELAY_SET; |
5072
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3222 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3223 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3224 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3225 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
|
3226 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
|
3227 return; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3228 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3229 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3230 if (u->peer.connection->read->ready |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3231 || u->buffer.pos != u->buffer.last) |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3232 { |
5579
7586e7b2dbe9
Upstream: ngx_post_event() instead of upgraded call (ticket #503).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5557
diff
changeset
|
3233 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
|
3234 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
|
3235 return; |
5072
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3236 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3237 |
5532
17134d29782e
Upstream: reading from a client after connection upgrade.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5500
diff
changeset
|
3238 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
|
3239 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3240 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3241 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3242 static void |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3243 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
|
3244 { |
5073
52eb762c68a9
Proxy: fixed do_write handling in previous commit.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5072
diff
changeset
|
3245 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
|
3246 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3247 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3248 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3249 static void |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3250 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
|
3251 { |
5073
52eb762c68a9
Proxy: fixed do_write handling in previous commit.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5072
diff
changeset
|
3252 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
|
3253 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3254 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3255 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3256 static void |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3257 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
|
3258 ngx_http_upstream_t *u) |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3259 { |
5073
52eb762c68a9
Proxy: fixed do_write handling in previous commit.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5072
diff
changeset
|
3260 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
|
3261 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3262 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3263 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3264 static void |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3265 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
|
3266 ngx_http_upstream_t *u) |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3267 { |
5073
52eb762c68a9
Proxy: fixed do_write handling in previous commit.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5072
diff
changeset
|
3268 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
|
3269 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3270 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3271 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3272 static void |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3273 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
|
3274 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
|
3275 { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3276 size_t size; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3277 ssize_t n; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3278 ngx_buf_t *b; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3279 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
|
3280 ngx_http_upstream_t *u; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3281 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
|
3282 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3283 c = r->connection; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3284 u = r->upstream; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3285 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3286 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
|
3287 "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
|
3288 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3289 downstream = c; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3290 upstream = u->peer.connection; |
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 if (downstream->write->timedout) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3293 c->timedout = 1; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3294 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
|
3295 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
|
3296 return; |
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 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
|
3300 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
|
3301 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
|
3302 return; |
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 if (from_upstream) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3306 src = upstream; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3307 dst = downstream; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3308 b = &u->buffer; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3309 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3310 } else { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3311 src = downstream; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3312 dst = upstream; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3313 b = &u->from_client; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3314 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3315 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
|
3316 b = r->header_in; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3317 b->end = b->last; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3318 do_write = 1; |
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 if (b->start == NULL) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3322 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
|
3323 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
|
3324 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
|
3325 return; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3326 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3327 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3328 b->pos = b->start; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3329 b->last = b->start; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3330 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
|
3331 b->temporary = 1; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3332 b->tag = u->output.tag; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3333 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3334 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3335 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3336 for ( ;; ) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3337 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3338 if (do_write) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3339 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3340 size = b->last - b->pos; |
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 (size && dst->write->ready) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3343 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3344 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
|
3345 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3346 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
|
3347 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
|
3348 return; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3349 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3350 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3351 if (n > 0) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3352 b->pos += n; |
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 if (b->pos == b->last) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3355 b->pos = b->start; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3356 b->last = b->start; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3357 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3358 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3359 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3360 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3361 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3362 size = b->end - b->last; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3363 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3364 if (size && src->read->ready) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3365 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3366 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
|
3367 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3368 if (n == NGX_AGAIN || n == 0) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3369 break; |
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 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3372 if (n > 0) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3373 do_write = 1; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3374 b->last += n; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3375 |
6654
c131f20c9562
Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6594
diff
changeset
|
3376 if (from_upstream) { |
c131f20c9562
Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6594
diff
changeset
|
3377 u->state->bytes_received += n; |
c131f20c9562
Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6594
diff
changeset
|
3378 } |
c131f20c9562
Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6594
diff
changeset
|
3379 |
5072
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3380 continue; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3381 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3382 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3383 if (n == NGX_ERROR) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3384 src->read->eof = 1; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3385 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3386 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3387 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3388 break; |
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 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3391 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
|
3392 || (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
|
3393 || (downstream->read->eof && upstream->read->eof)) |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3394 { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3395 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
|
3396 "http upstream upgraded done"); |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3397 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
|
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 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
|
3402 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3403 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
|
3404 != NGX_OK) |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3405 { |
5295
a489c31c9783
Upstream: ngx_http_upstream_finalize_request(NGX_ERROR) on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5294
diff
changeset
|
3406 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
|
3407 return; |
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 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
|
3411 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
|
3412 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3413 } else if (upstream->write->timer_set) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3414 ngx_del_timer(upstream->write); |
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 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3417 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
|
3418 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
|
3419 return; |
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 (upstream->read->active && !upstream->read->ready) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3423 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
|
3424 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3425 } else if (upstream->read->timer_set) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3426 ngx_del_timer(upstream->read); |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3427 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3428 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3429 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
|
3430 != NGX_OK) |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3431 { |
5295
a489c31c9783
Upstream: ngx_http_upstream_finalize_request(NGX_ERROR) on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5294
diff
changeset
|
3432 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
|
3433 return; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3434 } |
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 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
|
3437 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
|
3438 return; |
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 (downstream->write->active && !downstream->write->ready) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3442 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
|
3443 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3444 } else if (downstream->write->timer_set) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3445 ngx_del_timer(downstream->write); |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3446 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3447 } |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3448 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3449 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5008
diff
changeset
|
3450 static void |
581 | 3451 ngx_http_upstream_process_non_buffered_downstream(ngx_http_request_t *r) |
3452 { | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3453 ngx_event_t *wev; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3454 ngx_connection_t *c; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3455 ngx_http_upstream_t *u; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3456 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3457 c = r->connection; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3458 u = r->upstream; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3459 wev = c->write; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3460 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3461 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
|
3462 "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
|
3463 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3464 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
|
3465 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3466 if (wev->timedout) { |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3467 c->timedout = 1; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3468 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
|
3469 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
|
3470 return; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3471 } |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3472 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3473 ngx_http_upstream_process_non_buffered_request(r, 1); |
581 | 3474 } |
3475 | |
3476 | |
3477 static void | |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
3478 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
|
3479 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
|
3480 { |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
3481 ngx_connection_t *c; |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
3482 |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
3483 c = u->peer.connection; |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3484 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3485 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
|
3486 "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
|
3487 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3488 c->log->action = "reading upstream"; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3489 |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
3490 if (c->read->timedout) { |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3491 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
|
3492 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
|
3493 return; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3494 } |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3495 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3496 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
|
3497 } |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3498 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3499 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3500 static void |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3501 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
|
3502 ngx_uint_t do_write) |
581 | 3503 { |
3504 size_t size; | |
3505 ssize_t n; | |
3506 ngx_buf_t *b; | |
583 | 3507 ngx_int_t rc; |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3508 ngx_connection_t *downstream, *upstream; |
581 | 3509 ngx_http_upstream_t *u; |
3510 ngx_http_core_loc_conf_t *clcf; | |
3511 | |
756
d904b5cb3bba
fix building introduced by previous commit
Igor Sysoev <igor@sysoev.ru>
parents:
755
diff
changeset
|
3512 u = r->upstream; |
884 | 3513 downstream = r->connection; |
3514 upstream = u->peer.connection; | |
581 | 3515 |
3516 b = &u->buffer; | |
3517 | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3518 do_write = do_write || u->length == 0; |
581 | 3519 |
3520 for ( ;; ) { | |
3521 | |
3522 if (do_write) { | |
3523 | |
3524 if (u->out_bufs || u->busy_bufs) { | |
583 | 3525 rc = ngx_http_output_filter(r, u->out_bufs); |
3526 | |
3527 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
|
3528 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
581 | 3529 return; |
3530 } | |
3531 | |
4114
5db098f97e0e
API change: ngx_chain_update_chains() now requires pool.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3976
diff
changeset
|
3532 ngx_chain_update_chains(r->pool, &u->free_bufs, &u->busy_bufs, |
581 | 3533 &u->out_bufs, u->output.tag); |
3534 } | |
3535 | |
3536 if (u->busy_bufs == NULL) { | |
3537 | |
3538 if (u->length == 0 | |
5301
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3539 || (upstream->read->eof && u->length == -1)) |
581 | 3540 { |
3541 ngx_http_upstream_finalize_request(r, u, 0); | |
3542 return; | |
3543 } | |
3544 | |
5301
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3545 if (upstream->read->eof) { |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3546 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
|
3547 "upstream prematurely closed connection"); |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3548 |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3549 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
|
3550 NGX_HTTP_BAD_GATEWAY); |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3551 return; |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3552 } |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3553 |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3554 if (upstream->read->error) { |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3555 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
|
3556 NGX_HTTP_BAD_GATEWAY); |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3557 return; |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3558 } |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3559 |
581 | 3560 b->pos = b->start; |
3561 b->last = b->start; | |
3562 } | |
3563 } | |
3564 | |
3565 size = b->end - b->last; | |
3566 | |
884 | 3567 if (size && upstream->read->ready) { |
3568 | |
3569 n = upstream->recv(upstream, b->last, size); | |
581 | 3570 |
3571 if (n == NGX_AGAIN) { | |
3572 break; | |
3573 } | |
3574 | |
3575 if (n > 0) { | |
6654
c131f20c9562
Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6594
diff
changeset
|
3576 u->state->bytes_received += n; |
2402 | 3577 u->state->response_length += n; |
3578 | |
581 | 3579 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
|
3580 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
581 | 3581 return; |
3582 } | |
3583 } | |
3584 | |
3585 do_write = 1; | |
3586 | |
3587 continue; | |
3588 } | |
3589 | |
3590 break; | |
3591 } | |
3592 | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3593 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
|
3594 |
884 | 3595 if (downstream->data == r) { |
3596 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
|
3597 != NGX_OK) |
583 | 3598 { |
5295
a489c31c9783
Upstream: ngx_http_upstream_finalize_request(NGX_ERROR) on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5294
diff
changeset
|
3599 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
583 | 3600 return; |
3601 } | |
581 | 3602 } |
3603 | |
1063
e2a6ecc5a3ae
a non-active client connection must not closed after send timeout
Igor Sysoev <igor@sysoev.ru>
parents:
1031
diff
changeset
|
3604 if (downstream->write->active && !downstream->write->ready) { |
884 | 3605 ngx_add_timer(downstream->write, clcf->send_timeout); |
3606 | |
3607 } else if (downstream->write->timer_set) { | |
3608 ngx_del_timer(downstream->write); | |
581 | 3609 } |
3610 | |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
3611 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
|
3612 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
581 | 3613 return; |
3614 } | |
3615 | |
1063
e2a6ecc5a3ae
a non-active client connection must not closed after send timeout
Igor Sysoev <igor@sysoev.ru>
parents:
1031
diff
changeset
|
3616 if (upstream->read->active && !upstream->read->ready) { |
884 | 3617 ngx_add_timer(upstream->read, u->conf->read_timeout); |
3618 | |
3619 } else if (upstream->read->timer_set) { | |
3620 ngx_del_timer(upstream->read); | |
581 | 3621 } |
3622 } | |
3623 | |
3624 | |
3625 static ngx_int_t | |
3626 ngx_http_upstream_non_buffered_filter_init(void *data) | |
3627 { | |
3628 return NGX_OK; | |
3629 } | |
3630 | |
3631 | |
3632 static ngx_int_t | |
3633 ngx_http_upstream_non_buffered_filter(void *data, ssize_t bytes) | |
3634 { | |
3635 ngx_http_request_t *r = data; | |
3636 | |
3637 ngx_buf_t *b; | |
3638 ngx_chain_t *cl, **ll; | |
3639 ngx_http_upstream_t *u; | |
3640 | |
3641 u = r->upstream; | |
3642 | |
3643 for (cl = u->out_bufs, ll = &u->out_bufs; cl; cl = cl->next) { | |
3644 ll = &cl->next; | |
3645 } | |
3646 | |
3647 cl = ngx_chain_get_free_buf(r->pool, &u->free_bufs); | |
3648 if (cl == NULL) { | |
3649 return NGX_ERROR; | |
3650 } | |
3651 | |
3652 *ll = cl; | |
3653 | |
3654 cl->buf->flush = 1; | |
3655 cl->buf->memory = 1; | |
3656 | |
3657 b = &u->buffer; | |
3658 | |
3659 cl->buf->pos = b->last; | |
3660 b->last += bytes; | |
3661 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
|
3662 cl->buf->tag = u->output.tag; |
581 | 3663 |
4118
dbddec65fdab
Upstream: r->upstream->length type change to off_t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4117
diff
changeset
|
3664 if (u->length == -1) { |
581 | 3665 return NGX_OK; |
3666 } | |
3667 | |
3668 u->length -= bytes; | |
3669 | |
3670 return NGX_OK; | |
3671 } | |
3672 | |
3673 | |
6443
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3674 #if (NGX_THREADS) |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3675 |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3676 static ngx_int_t |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3677 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
|
3678 { |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3679 ngx_str_t name; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3680 ngx_event_pipe_t *p; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3681 ngx_thread_pool_t *tp; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3682 ngx_http_request_t *r; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3683 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
|
3684 |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3685 r = file->thread_ctx; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3686 p = r->upstream->pipe; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3687 |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3688 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
|
3689 tp = clcf->thread_pool; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3690 |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3691 if (tp == NULL) { |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3692 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
|
3693 != NGX_OK) |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3694 { |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3695 return NGX_ERROR; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3696 } |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3697 |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3698 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
|
3699 |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3700 if (tp == NULL) { |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3701 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
|
3702 "thread pool \"%V\" not found", &name); |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3703 return NGX_ERROR; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3704 } |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3705 } |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3706 |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3707 task->event.data = r; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3708 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
|
3709 |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3710 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
|
3711 return NGX_ERROR; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3712 } |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3713 |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3714 r->main->blocked++; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3715 r->aio = 1; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3716 p->aio = 1; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3717 |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3718 return NGX_OK; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3719 } |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3720 |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3721 |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3722 static void |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3723 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
|
3724 { |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3725 ngx_connection_t *c; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3726 ngx_http_request_t *r; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3727 |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3728 r = ev->data; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3729 c = r->connection; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3730 |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3731 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
|
3732 |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3733 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
|
3734 "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
|
3735 |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3736 r->main->blocked--; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3737 r->aio = 0; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3738 |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3739 r->write_event_handler(r); |
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 ngx_http_run_posted_requests(c); |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3742 } |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3743 |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3744 #endif |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3745 |
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 static ngx_int_t |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3748 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
|
3749 { |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3750 ngx_int_t rc; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3751 ngx_event_pipe_t *p; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3752 ngx_http_request_t *r; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3753 |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3754 r = data; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3755 p = r->upstream->pipe; |
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 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
|
3758 |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3759 p->aio = r->aio; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3760 |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3761 return rc; |
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 |
581 | 3765 static void |
509 | 3766 ngx_http_upstream_process_downstream(ngx_http_request_t *r) |
3767 { | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3768 ngx_event_t *wev; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3769 ngx_connection_t *c; |
509 | 3770 ngx_event_pipe_t *p; |
479 | 3771 ngx_http_upstream_t *u; |
3772 | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3773 c = r->connection; |
479 | 3774 u = r->upstream; |
581 | 3775 p = u->pipe; |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3776 wev = c->write; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3777 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3778 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
|
3779 "http upstream process downstream"); |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3780 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3781 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
|
3782 |
6443
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3783 #if (NGX_THREADS) |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3784 p->aio = r->aio; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3785 #endif |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3786 |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3787 if (wev->timedout) { |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3788 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3789 if (wev->delayed) { |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3790 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3791 wev->timedout = 0; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3792 wev->delayed = 0; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3793 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3794 if (!wev->ready) { |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3795 ngx_add_timer(wev, p->send_timeout); |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3796 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3797 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
|
3798 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
|
3799 } |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3800 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3801 return; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3802 } |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3803 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3804 if (ngx_event_pipe(p, wev->write) == NGX_ABORT) { |
5297
0ae9a2958886
Upstream: NGX_ERROR after pipe errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5296
diff
changeset
|
3805 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
|
3806 return; |
527 | 3807 } |
479 | 3808 |
3809 } else { | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3810 p->downstream_error = 1; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3811 c->timedout = 1; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3812 ngx_connection_error(c, NGX_ETIMEDOUT, "client timed out"); |
479 | 3813 } |
3814 | |
3815 } else { | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3816 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3817 if (wev->delayed) { |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3818 |
527 | 3819 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, |
3820 "http downstream delayed"); | |
3821 | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3822 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
|
3823 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
527 | 3824 } |
3825 | |
3826 return; | |
3827 } | |
3828 | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3829 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
|
3830 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
479 | 3831 return; |
3832 } | |
3833 } | |
577 | 3834 |
5995
5f179f344096
Upstream: upstream argument in ngx_http_upstream_process_request().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5994
diff
changeset
|
3835 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
|
3836 } |
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 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3839 static void |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
3840 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
|
3841 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
|
3842 { |
5883
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3843 ngx_event_t *rev; |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3844 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
|
3845 ngx_connection_t *c; |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
3846 |
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
3847 c = u->peer.connection; |
5883
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3848 p = u->pipe; |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3849 rev = c->read; |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3850 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3851 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
|
3852 "http upstream process upstream"); |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3853 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3854 c->log->action = "reading upstream"; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3855 |
5883
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3856 if (rev->timedout) { |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3857 |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3858 if (rev->delayed) { |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3859 |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3860 rev->timedout = 0; |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3861 rev->delayed = 0; |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3862 |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3863 if (!rev->ready) { |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3864 ngx_add_timer(rev, p->read_timeout); |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3865 |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3866 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
|
3867 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
|
3868 } |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3869 |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3870 return; |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3871 } |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3872 |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3873 if (ngx_event_pipe(p, 0) == NGX_ABORT) { |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3874 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
|
3875 return; |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3876 } |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3877 |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3878 } else { |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3879 p->upstream_error = 1; |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3880 ngx_connection_error(c, NGX_ETIMEDOUT, "upstream timed out"); |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3881 } |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3882 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3883 } else { |
5883
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3884 |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3885 if (rev->delayed) { |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3886 |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3887 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
|
3888 "http upstream delayed"); |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3889 |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3890 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
|
3891 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
|
3892 } |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3893 |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3894 return; |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3895 } |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3896 |
973ee2276300
Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5878
diff
changeset
|
3897 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
|
3898 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
|
3899 return; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3900 } |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3901 } |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3902 |
5995
5f179f344096
Upstream: upstream argument in ngx_http_upstream_process_request().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5994
diff
changeset
|
3903 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
|
3904 } |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3905 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3906 |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3907 static void |
5995
5f179f344096
Upstream: upstream argument in ngx_http_upstream_process_request().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5994
diff
changeset
|
3908 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
|
3909 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
|
3910 { |
5996 | 3911 ngx_temp_file_t *tf; |
3912 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
|
3913 |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3914 p = u->pipe; |
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
3915 |
6443
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3916 #if (NGX_THREADS) |
6876
a5d1b1383dea
Upstream: fixed cache corruption and socket leaks with aio_write.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6853
diff
changeset
|
3917 |
a5d1b1383dea
Upstream: fixed cache corruption and socket leaks with aio_write.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6853
diff
changeset
|
3918 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
|
3919 |
a5d1b1383dea
Upstream: fixed cache corruption and socket leaks with aio_write.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6853
diff
changeset
|
3920 /* |
a5d1b1383dea
Upstream: fixed cache corruption and socket leaks with aio_write.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6853
diff
changeset
|
3921 * 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
|
3922 * 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
|
3923 */ |
a5d1b1383dea
Upstream: fixed cache corruption and socket leaks with aio_write.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6853
diff
changeset
|
3924 |
a5d1b1383dea
Upstream: fixed cache corruption and socket leaks with aio_write.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6853
diff
changeset
|
3925 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
|
3926 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
|
3927 return; |
a5d1b1383dea
Upstream: fixed cache corruption and socket leaks with aio_write.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6853
diff
changeset
|
3928 } |
a5d1b1383dea
Upstream: fixed cache corruption and socket leaks with aio_write.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6853
diff
changeset
|
3929 } |
a5d1b1383dea
Upstream: fixed cache corruption and socket leaks with aio_write.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6853
diff
changeset
|
3930 |
6443
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3931 if (p->writing) { |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3932 return; |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3933 } |
6876
a5d1b1383dea
Upstream: fixed cache corruption and socket leaks with aio_write.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6853
diff
changeset
|
3934 |
6443
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3935 #endif |
fc72784b1f52
Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6439
diff
changeset
|
3936 |
479 | 3937 if (u->peer.connection) { |
3938 | |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3939 if (u->store) { |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3940 |
2463 | 3941 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
|
3942 |
5298
a7b2db9119e0
Upstream: replaced u->pipe->temp_file with p->temp_file.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5297
diff
changeset
|
3943 tf = p->temp_file; |
4469
24c0dca04eb9
Fix for proxy_store leaving temporary files for subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4464
diff
changeset
|
3944 |
2445
3c6af1fb7586
proxy/fastcgi_store did not delete incomplete files
Igor Sysoev <igor@sysoev.ru>
parents:
2441
diff
changeset
|
3945 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
|
3946 && (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
|
3947 && (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
|
3948 || 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
|
3949 { |
3c6af1fb7586
proxy/fastcgi_store did not delete incomplete files
Igor Sysoev <igor@sysoev.ru>
parents:
2441
diff
changeset
|
3950 ngx_http_upstream_store(r, u); |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3951 } |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3952 } |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3953 } |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
3954 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3955 #if (NGX_HTTP_CACHE) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3956 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3957 if (u->cacheable) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3958 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3959 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
|
3960 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
|
3961 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3962 } else if (p->upstream_eof) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3963 |
5298
a7b2db9119e0
Upstream: replaced u->pipe->temp_file with p->temp_file.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5297
diff
changeset
|
3964 tf = p->temp_file; |
4298
186f02886bed
Upstream: don't cache unfinished responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4197
diff
changeset
|
3965 |
5299
b779728b180c
Upstream: fixed store/cache of unfinished responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5298
diff
changeset
|
3966 if (p->length == -1 |
b779728b180c
Upstream: fixed store/cache of unfinished responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5298
diff
changeset
|
3967 && (u->headers_in.content_length_n == -1 |
b779728b180c
Upstream: fixed store/cache of unfinished responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5298
diff
changeset
|
3968 || u->headers_in.content_length_n |
b779728b180c
Upstream: fixed store/cache of unfinished responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5298
diff
changeset
|
3969 == 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
|
3970 { |
186f02886bed
Upstream: don't cache unfinished responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4197
diff
changeset
|
3971 ngx_http_file_cache_update(r, tf); |
186f02886bed
Upstream: don't cache unfinished responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4197
diff
changeset
|
3972 |
186f02886bed
Upstream: don't cache unfinished responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4197
diff
changeset
|
3973 } else { |
186f02886bed
Upstream: don't cache unfinished responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4197
diff
changeset
|
3974 ngx_http_file_cache_free(r->cache, tf); |
186f02886bed
Upstream: don't cache unfinished responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4197
diff
changeset
|
3975 } |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3976 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
3977 } 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
|
3978 ngx_http_file_cache_free(r->cache, p->temp_file); |
479 | 3979 } |
3980 } | |
3981 | |
3982 #endif | |
3983 | |
3984 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
|
3985 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
483 | 3986 "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
|
3987 |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3988 if (p->upstream_done |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3989 || (p->upstream_eof && p->length == -1)) |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3990 { |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3991 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
|
3992 return; |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3993 } |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3994 |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3995 if (p->upstream_eof) { |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3996 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
|
3997 "upstream prematurely closed connection"); |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3998 } |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
3999 |
a50e26148d21
Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
4000 ngx_http_upstream_finalize_request(r, u, NGX_HTTP_BAD_GATEWAY); |
479 | 4001 return; |
4002 } | |
4003 } | |
4004 | |
4005 if (p->downstream_error) { | |
2381
3d7a70173d77
fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents:
2377
diff
changeset
|
4006 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
483 | 4007 "http upstream downstream error"); |
479 | 4008 |
2757
9cc973b46af1
get a full response if the response is cacheable or storable even
Igor Sysoev <igor@sysoev.ru>
parents:
2708
diff
changeset
|
4009 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
|
4010 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
479 | 4011 } |
4012 } | |
4013 } | |
4014 | |
4015 | |
487 | 4016 static void |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4017 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
|
4018 { |
1947
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
4019 size_t root; |
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
4020 time_t lm; |
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
4021 ngx_str_t path; |
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
4022 ngx_temp_file_t *tf; |
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
4023 ngx_ext_rename_file_t ext; |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4024 |
1777 | 4025 tf = u->pipe->temp_file; |
4026 | |
4027 if (tf->file.fd == NGX_INVALID_FILE) { | |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4028 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4029 /* create file for empty 200 response */ |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4030 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4031 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
|
4032 if (tf == NULL) { |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4033 return; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4034 } |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4035 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4036 tf->file.fd = NGX_INVALID_FILE; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4037 tf->file.log = r->connection->log; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4038 tf->path = u->conf->temp_path; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4039 tf->pool = r->pool; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4040 tf->persistent = 1; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4041 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4042 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
|
4043 tf->persistent, tf->clean, tf->access) |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4044 != NGX_OK) |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4045 { |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4046 return; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4047 } |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4048 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4049 u->pipe->temp_file = tf; |
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 |
1947
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
4052 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
|
4053 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
|
4054 ext.time = -1; |
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
4055 ext.create_path = 1; |
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
4056 ext.delete_file = 1; |
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
4057 ext.log = r->connection->log; |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4058 |
1705 | 4059 if (u->headers_in.last_modified) { |
4060 | |
6180
8b6fa4842133
Moved ngx_http_parse_time() to core, renamed accordingly.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6147
diff
changeset
|
4061 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
|
4062 u->headers_in.last_modified->value.len); |
1291
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 if (lm != NGX_ERROR) { |
1947
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
4065 ext.time = lm; |
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
4066 ext.fd = tf->file.fd; |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4067 } |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4068 } |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4069 |
1295
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
4070 if (u->conf->store_lengths == NULL) { |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
4071 |
5770
9de5820bb3e0
Upstream: ngx_http_upstream_store() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5757
diff
changeset
|
4072 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
|
4073 return; |
9de5820bb3e0
Upstream: ngx_http_upstream_store() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5757
diff
changeset
|
4074 } |
1295
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
4075 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
4076 } else { |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
4077 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
|
4078 u->conf->store_values->elts) |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
4079 == NULL) |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
4080 { |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
4081 return; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
4082 } |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
4083 } |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4084 |
3032
524ba56ba9f7
fix copy destination name length, introduced in r3025
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
4085 path.len--; |
524ba56ba9f7
fix copy destination name length, introduced in r3025
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
4086 |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4087 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
|
4088 "upstream stores \"%s\" to \"%s\"", |
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
4089 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
|
4090 |
94b03bbd328e
use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1916
diff
changeset
|
4091 (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
|
4092 |
9de5820bb3e0
Upstream: ngx_http_upstream_store() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5757
diff
changeset
|
4093 u->store = 0; |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4094 } |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4095 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4096 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
4097 static void |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
4098 ngx_http_upstream_dummy_handler(ngx_http_request_t *r, ngx_http_upstream_t *u) |
479 | 4099 { |
2386
4ccaa42de633
use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents:
2381
diff
changeset
|
4100 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
479 | 4101 "http upstream dummy handler"); |
4102 } | |
4103 | |
4104 | |
487 | 4105 static void |
4106 ngx_http_upstream_next(ngx_http_request_t *r, ngx_http_upstream_t *u, | |
4107 ngx_uint_t ft_type) | |
479 | 4108 { |
5832
d09b689911ac
Upstream: limited next_upstream time and tries (ticket #544).
Roman Arutyunyan <arut@nginx.com>
parents:
5827
diff
changeset
|
4109 ngx_msec_t timeout; |
884 | 4110 ngx_uint_t status, state; |
479 | 4111 |
4112 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
884 | 4113 "http next upstream, %xi", ft_type); |
479 | 4114 |
5132
9bcf89ca78d2
Upstream: only call peer.free() if peer.get() selected a peer.
Ruslan Ermilov <ru@nginx.com>
parents:
5121
diff
changeset
|
4115 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
|
4116 |
5231
05c53652e7b4
Upstream: http_403 support in proxy_next_upstream (and friends).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5217
diff
changeset
|
4117 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
|
4118 || 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
|
4119 { |
5132
9bcf89ca78d2
Upstream: only call peer.free() if peer.get() selected a peer.
Ruslan Ermilov <ru@nginx.com>
parents:
5121
diff
changeset
|
4120 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
|
4121 |
5132
9bcf89ca78d2
Upstream: only call peer.free() if peer.get() selected a peer.
Ruslan Ermilov <ru@nginx.com>
parents:
5121
diff
changeset
|
4122 } else { |
9bcf89ca78d2
Upstream: only call peer.free() if peer.get() selected a peer.
Ruslan Ermilov <ru@nginx.com>
parents:
5121
diff
changeset
|
4123 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
|
4124 } |
9bcf89ca78d2
Upstream: only call peer.free() if peer.get() selected a peer.
Ruslan Ermilov <ru@nginx.com>
parents:
5121
diff
changeset
|
4125 |
1378 | 4126 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
|
4127 u->peer.sockaddr = NULL; |
1378 | 4128 } |
525 | 4129 |
479 | 4130 if (ft_type == NGX_HTTP_UPSTREAM_FT_TIMEOUT) { |
4131 ngx_log_error(NGX_LOG_ERR, r->connection->log, NGX_ETIMEDOUT, | |
4132 "upstream timed out"); | |
4133 } | |
577 | 4134 |
6466
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4135 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
|
4136 /* TODO: inform balancer instead */ |
70a45a504905
Workaround for cpu hog on errors with cached connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4114
diff
changeset
|
4137 u->peer.tries++; |
6466
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4138 } |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4139 |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4140 switch (ft_type) { |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4141 |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4142 case NGX_HTTP_UPSTREAM_FT_TIMEOUT: |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4143 status = NGX_HTTP_GATEWAY_TIME_OUT; |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4144 break; |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4145 |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4146 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
|
4147 status = NGX_HTTP_INTERNAL_SERVER_ERROR; |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4148 break; |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4149 |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4150 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
|
4151 status = NGX_HTTP_FORBIDDEN; |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4152 break; |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4153 |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4154 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
|
4155 status = NGX_HTTP_NOT_FOUND; |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4156 break; |
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 /* |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4159 * 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
|
4160 * never reach here |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4161 */ |
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 default: |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4164 status = NGX_HTTP_BAD_GATEWAY; |
479 | 4165 } |
4166 | |
583 | 4167 if (r->connection->error) { |
479 | 4168 ngx_http_upstream_finalize_request(r, u, |
4169 NGX_HTTP_CLIENT_CLOSED_REQUEST); | |
4170 return; | |
4171 } | |
4172 | |
6466
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4173 u->state->status = status; |
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 timeout = u->conf->next_upstream_timeout; |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4176 |
6467
91c8d990fb45
Upstream: proxy_next_upstream non_idempotent.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6466
diff
changeset
|
4177 if (u->request_sent |
91c8d990fb45
Upstream: proxy_next_upstream non_idempotent.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6466
diff
changeset
|
4178 && (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
|
4179 { |
91c8d990fb45
Upstream: proxy_next_upstream non_idempotent.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6466
diff
changeset
|
4180 ft_type |= NGX_HTTP_UPSTREAM_FT_NON_IDEMPOTENT; |
91c8d990fb45
Upstream: proxy_next_upstream non_idempotent.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6466
diff
changeset
|
4181 } |
91c8d990fb45
Upstream: proxy_next_upstream non_idempotent.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6466
diff
changeset
|
4182 |
6466
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4183 if (u->peer.tries == 0 |
6467
91c8d990fb45
Upstream: proxy_next_upstream non_idempotent.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6466
diff
changeset
|
4184 || ((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
|
4185 || (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
|
4186 || (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
|
4187 { |
479 | 4188 #if (NGX_HTTP_CACHE) |
4189 | |
6466
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4190 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
|
4191 && ((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
|
4192 { |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4193 ngx_int_t rc; |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4194 |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4195 rc = u->reinit_request(r); |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4196 |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4197 if (rc == NGX_OK) { |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4198 u->cache_status = NGX_HTTP_CACHE_STALE; |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4199 rc = ngx_http_upstream_cache_send(r, u); |
479 | 4200 } |
6466
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4201 |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4202 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
|
4203 return; |
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4204 } |
479 | 4205 #endif |
4206 | |
6466
984687f25998
Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6443
diff
changeset
|
4207 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
|
4208 return; |
479 | 4209 } |
4210 | |
4211 if (u->peer.connection) { | |
4212 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
4213 "close http upstream connection: %d", | |
4214 u->peer.connection->fd); | |
577 | 4215 #if (NGX_HTTP_SSL) |
884 | 4216 |
577 | 4217 if (u->peer.connection->ssl) { |
884 | 4218 u->peer.connection->ssl->no_wait_shutdown = 1; |
4219 u->peer.connection->ssl->no_send_shutdown = 1; | |
4220 | |
4221 (void) ngx_ssl_shutdown(u->peer.connection); | |
577 | 4222 } |
4223 #endif | |
884 | 4224 |
4138
70e1ee2307f9
Fix of separate pool for upstream connections (r4117).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4124
diff
changeset
|
4225 if (u->peer.connection->pool) { |
70e1ee2307f9
Fix of separate pool for upstream connections (r4117).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4124
diff
changeset
|
4226 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
|
4227 } |
70e1ee2307f9
Fix of separate pool for upstream connections (r4117).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4124
diff
changeset
|
4228 |
479 | 4229 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
|
4230 u->peer.connection = NULL; |
479 | 4231 } |
4232 | |
4233 ngx_http_upstream_connect(r, u); | |
4234 } | |
4235 | |
4236 | |
487 | 4237 static void |
569 | 4238 ngx_http_upstream_cleanup(void *data) |
4239 { | |
4240 ngx_http_request_t *r = data; | |
4241 | |
4242 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
4243 "cleanup http upstream request: \"%V\"", &r->uri); | |
4244 | |
5167
85ee9d858dcb
Upstream: removed surplus ngx_resolve_name_done() call.
Valentin Bartenev <vbart@nginx.com>
parents:
5142
diff
changeset
|
4245 ngx_http_upstream_finalize_request(r, r->upstream, NGX_DONE); |
569 | 4246 } |
4247 | |
4248 | |
4249 static void | |
487 | 4250 ngx_http_upstream_finalize_request(ngx_http_request_t *r, |
4251 ngx_http_upstream_t *u, ngx_int_t rc) | |
479 | 4252 { |
6146
59fc60585f1e
Upstream: times to obtain header/response are stored as ngx_msec_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6125
diff
changeset
|
4253 ngx_uint_t flush; |
563 | 4254 |
483 | 4255 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
4256 "finalize http upstream request: %i", rc); | |
479 | 4257 |
5994
5abf5af257a7
Upstream: avoid duplicate finalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5992
diff
changeset
|
4258 if (u->cleanup == NULL) { |
5abf5af257a7
Upstream: avoid duplicate finalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5992
diff
changeset
|
4259 /* the request was already finalized */ |
5abf5af257a7
Upstream: avoid duplicate finalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5992
diff
changeset
|
4260 ngx_http_finalize_request(r, NGX_DONE); |
5abf5af257a7
Upstream: avoid duplicate finalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5992
diff
changeset
|
4261 return; |
5abf5af257a7
Upstream: avoid duplicate finalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5992
diff
changeset
|
4262 } |
5abf5af257a7
Upstream: avoid duplicate finalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5992
diff
changeset
|
4263 |
5abf5af257a7
Upstream: avoid duplicate finalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5992
diff
changeset
|
4264 *u->cleanup = NULL; |
5abf5af257a7
Upstream: avoid duplicate finalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5992
diff
changeset
|
4265 u->cleanup = NULL; |
569 | 4266 |
3169
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
4267 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
|
4268 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
|
4269 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
|
4270 } |
b1013d768911
fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3161
diff
changeset
|
4271 |
6146
59fc60585f1e
Upstream: times to obtain header/response are stored as ngx_msec_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6125
diff
changeset
|
4272 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
|
4273 u->state->response_time = ngx_current_msec - u->state->response_time; |
2402 | 4274 |
5169
f6bbe77794aa
Upstream: fixed $upstream_response_length without buffering.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5167
diff
changeset
|
4275 if (u->pipe && u->pipe->read_length) { |
6654
c131f20c9562
Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6594
diff
changeset
|
4276 u->state->bytes_received += u->pipe->read_length |
c131f20c9562
Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6594
diff
changeset
|
4277 - u->pipe->preread_size; |
2402 | 4278 u->state->response_length = u->pipe->read_length; |
4279 } | |
563 | 4280 } |
4281 | |
479 | 4282 u->finalize_request(r, rc); |
4283 | |
5132
9bcf89ca78d2
Upstream: only call peer.free() if peer.get() selected a peer.
Ruslan Ermilov <ru@nginx.com>
parents:
5121
diff
changeset
|
4284 if (u->peer.free && u->peer.sockaddr) { |
1658 | 4285 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
|
4286 u->peer.sockaddr = NULL; |
1658 | 4287 } |
884 | 4288 |
479 | 4289 if (u->peer.connection) { |
884 | 4290 |
577 | 4291 #if (NGX_HTTP_SSL) |
4292 | |
4293 /* TODO: do not shutdown persistent connection */ | |
4294 | |
4295 if (u->peer.connection->ssl) { | |
884 | 4296 |
4297 /* | |
4298 * We send the "close notify" shutdown alert to the upstream only | |
4299 * and do not wait its "close notify" shutdown alert. | |
4300 * It is acceptable according to the TLS standard. | |
4301 */ | |
4302 | |
4303 u->peer.connection->ssl->no_wait_shutdown = 1; | |
4304 | |
4305 (void) ngx_ssl_shutdown(u->peer.connection); | |
577 | 4306 } |
4307 #endif | |
884 | 4308 |
4309 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
4310 "close http upstream connection: %d", | |
4311 u->peer.connection->fd); | |
4312 | |
4138
70e1ee2307f9
Fix of separate pool for upstream connections (r4117).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4124
diff
changeset
|
4313 if (u->peer.connection->pool) { |
70e1ee2307f9
Fix of separate pool for upstream connections (r4117).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4124
diff
changeset
|
4314 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
|
4315 } |
70e1ee2307f9
Fix of separate pool for upstream connections (r4117).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4124
diff
changeset
|
4316 |
479 | 4317 ngx_close_connection(u->peer.connection); |
4318 } | |
4319 | |
483 | 4320 u->peer.connection = NULL; |
4321 | |
581 | 4322 if (u->pipe && u->pipe->temp_file) { |
479 | 4323 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
4324 "http upstream temp fd: %d", | |
581 | 4325 u->pipe->temp_file->file.fd); |
479 | 4326 } |
4327 | |
4469
24c0dca04eb9
Fix for proxy_store leaving temporary files for subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4464
diff
changeset
|
4328 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
|
4329 && 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
|
4330 { |
24c0dca04eb9
Fix for proxy_store leaving temporary files for subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4464
diff
changeset
|
4331 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
|
4332 == NGX_FILE_ERROR) |
24c0dca04eb9
Fix for proxy_store leaving temporary files for subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4464
diff
changeset
|
4333 { |
24c0dca04eb9
Fix for proxy_store leaving temporary files for subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4464
diff
changeset
|
4334 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
|
4335 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
|
4336 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
|
4337 } |
24c0dca04eb9
Fix for proxy_store leaving temporary files for subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4464
diff
changeset
|
4338 } |
24c0dca04eb9
Fix for proxy_store leaving temporary files for subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4464
diff
changeset
|
4339 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4340 #if (NGX_HTTP_CACHE) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4341 |
3940
22f3e9197096
revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents:
3934
diff
changeset
|
4342 if (r->cache) { |
22f3e9197096
revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents:
3934
diff
changeset
|
4343 |
22f3e9197096
revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents:
3934
diff
changeset
|
4344 if (u->cacheable) { |
22f3e9197096
revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents:
3934
diff
changeset
|
4345 |
22f3e9197096
revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents:
3934
diff
changeset
|
4346 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
|
4347 time_t valid; |
22f3e9197096
revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents:
3934
diff
changeset
|
4348 |
22f3e9197096
revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents:
3934
diff
changeset
|
4349 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
|
4350 |
22f3e9197096
revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents:
3934
diff
changeset
|
4351 if (valid) { |
22f3e9197096
revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents:
3934
diff
changeset
|
4352 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
|
4353 r->cache->error = rc; |
22f3e9197096
revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents:
3934
diff
changeset
|
4354 } |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4355 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4356 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4357 |
3711
ce6ba077c270
several changes in cache cleanup handling:
Igor Sysoev <igor@sysoev.ru>
parents:
3709
diff
changeset
|
4358 ngx_http_file_cache_free(r->cache, u->pipe->temp_file); |
479 | 4359 } |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4360 |
479 | 4361 #endif |
4362 | |
5392
f1caf7b8ae1d
Upstream: subrequest_in_memory fix.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5373
diff
changeset
|
4363 if (r->subrequest_in_memory |
f1caf7b8ae1d
Upstream: subrequest_in_memory fix.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5373
diff
changeset
|
4364 && u->headers_in.status_n >= NGX_HTTP_SPECIAL_RESPONSE) |
f1caf7b8ae1d
Upstream: subrequest_in_memory fix.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5373
diff
changeset
|
4365 { |
f1caf7b8ae1d
Upstream: subrequest_in_memory fix.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5373
diff
changeset
|
4366 u->buffer.last = u->buffer.pos; |
f1caf7b8ae1d
Upstream: subrequest_in_memory fix.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5373
diff
changeset
|
4367 } |
f1caf7b8ae1d
Upstream: subrequest_in_memory fix.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5373
diff
changeset
|
4368 |
6909
5850fed24639
Upstream: read handler cleared on upstream finalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6906
diff
changeset
|
4369 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
|
4370 |
515 | 4371 if (rc == NGX_DECLINED) { |
4372 return; | |
4373 } | |
4374 | |
483 | 4375 r->connection->log->action = "sending to client"; |
4376 | |
5303
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
4377 if (!u->header_sent |
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
4378 || rc == NGX_HTTP_REQUEST_TIME_OUT |
6427
ad3f342f14ba
Upstream: fixed "zero size buf" alerts with cache (ticket #918).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6379
diff
changeset
|
4379 || rc == NGX_HTTP_CLIENT_CLOSED_REQUEST |
ad3f342f14ba
Upstream: fixed "zero size buf" alerts with cache (ticket #918).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6379
diff
changeset
|
4380 || (u->pipe && u->pipe->downstream_error)) |
4151
3549db8ceaf2
Cache: fix for sending of stale responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4143
diff
changeset
|
4381 { |
5303
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
4382 ngx_http_finalize_request(r, rc); |
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
4383 return; |
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
4384 } |
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
4385 |
5304
d3eab5e2df5f
Upstream: no last buffer on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5303
diff
changeset
|
4386 flush = 0; |
d3eab5e2df5f
Upstream: no last buffer on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5303
diff
changeset
|
4387 |
d3eab5e2df5f
Upstream: no last buffer on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5303
diff
changeset
|
4388 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) { |
d3eab5e2df5f
Upstream: no last buffer on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5303
diff
changeset
|
4389 rc = NGX_ERROR; |
d3eab5e2df5f
Upstream: no last buffer on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5303
diff
changeset
|
4390 flush = 1; |
5303
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
4391 } |
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
4392 |
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
4393 if (r->header_only) { |
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
4394 ngx_http_finalize_request(r, rc); |
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
4395 return; |
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
4396 } |
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
4397 |
0fb714d80909
Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5302
diff
changeset
|
4398 if (rc == 0) { |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2360
diff
changeset
|
4399 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
|
4400 |
d3eab5e2df5f
Upstream: no last buffer on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5303
diff
changeset
|
4401 } else if (flush) { |
d3eab5e2df5f
Upstream: no last buffer on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5303
diff
changeset
|
4402 r->keepalive = 0; |
d3eab5e2df5f
Upstream: no last buffer on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5303
diff
changeset
|
4403 rc = ngx_http_send_special(r, NGX_HTTP_FLUSH); |
479 | 4404 } |
4405 | |
4406 ngx_http_finalize_request(r, rc); | |
4407 } | |
4408 | |
4409 | |
509 | 4410 static ngx_int_t |
4411 ngx_http_upstream_process_header_line(ngx_http_request_t *r, ngx_table_elt_t *h, | |
4412 ngx_uint_t offset) | |
577 | 4413 { |
509 | 4414 ngx_table_elt_t **ph; |
577 | 4415 |
509 | 4416 ph = (ngx_table_elt_t **) ((char *) &r->upstream->headers_in + offset); |
4417 | |
4418 if (*ph == NULL) { | |
4419 *ph = h; | |
4420 } | |
4421 | |
4422 return NGX_OK; | |
4423 } | |
4424 | |
4425 | |
4426 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
|
4427 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
|
4428 ngx_uint_t offset) |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4429 { |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4430 return NGX_OK; |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4431 } |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4432 |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4433 |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4434 static ngx_int_t |
4117
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
4435 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
|
4436 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
|
4437 { |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
4438 ngx_http_upstream_t *u; |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
4439 |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
4440 u = r->upstream; |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
4441 |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
4442 u->headers_in.content_length = h; |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
4443 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
|
4444 |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
4445 return NGX_OK; |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
4446 } |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
4447 |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
4448 |
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4116
diff
changeset
|
4449 static ngx_int_t |
5732
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
4450 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
|
4451 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
|
4452 { |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
4453 ngx_http_upstream_t *u; |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
4454 |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
4455 u = r->upstream; |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
4456 |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
4457 u->headers_in.last_modified = h; |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
4458 |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
4459 #if (NGX_HTTP_CACHE) |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
4460 |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
4461 if (u->cacheable) { |
6180
8b6fa4842133
Moved ngx_http_parse_time() to core, renamed accordingly.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6147
diff
changeset
|
4462 u->headers_in.last_modified_time = ngx_parse_http_time(h->value.data, |
5732
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
4463 h->value.len); |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
4464 } |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
4465 |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
4466 #endif |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
4467 |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
4468 return NGX_OK; |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
4469 } |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
4470 |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
4471 |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
4472 static ngx_int_t |
3669
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
4473 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
|
4474 ngx_uint_t offset) |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
4475 { |
5677
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4476 ngx_array_t *pa; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4477 ngx_table_elt_t **ph; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4478 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
|
4479 |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
4480 u = r->upstream; |
5677
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4481 pa = &u->headers_in.cookies; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4482 |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4483 if (pa->elts == NULL) { |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4484 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
|
4485 { |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4486 return NGX_ERROR; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4487 } |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4488 } |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4489 |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4490 ph = ngx_array_push(pa); |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4491 if (ph == NULL) { |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4492 return NGX_ERROR; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4493 } |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4494 |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4495 *ph = h; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4496 |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
4497 #if (NGX_HTTP_CACHE) |
3669
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
4498 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
|
4499 u->cacheable = 0; |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
4500 } |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
4501 #endif |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
4502 |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
4503 return NGX_OK; |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
4504 } |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
4505 |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
4506 |
1f5841b1fcd7
treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents:
3667
diff
changeset
|
4507 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
|
4508 ngx_http_upstream_process_cache_control(ngx_http_request_t *r, |
509 | 4509 ngx_table_elt_t *h, ngx_uint_t offset) |
4510 { | |
2786
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4511 ngx_array_t *pa; |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4512 ngx_table_elt_t **ph; |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4513 ngx_http_upstream_t *u; |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4514 |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4515 u = r->upstream; |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4516 pa = &u->headers_in.cache_control; |
509 | 4517 |
4518 if (pa->elts == NULL) { | |
6474 | 4519 if (ngx_array_init(pa, r->pool, 2, sizeof(ngx_table_elt_t *)) != NGX_OK) |
4520 { | |
4521 return NGX_ERROR; | |
4522 } | |
509 | 4523 } |
4524 | |
4525 ph = ngx_array_push(pa); | |
4526 if (ph == NULL) { | |
4527 return NGX_ERROR; | |
4528 } | |
4529 | |
4530 *ph = h; | |
4531 | |
2708
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
4532 #if (NGX_HTTP_CACHE) |
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
4533 { |
5911
88d55e5934f7
Cache: add support for Cache-Control's s-maxage response directive.
Piotr Sikora <piotr@cloudflare.com>
parents:
5905
diff
changeset
|
4534 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
|
4535 ngx_int_t n; |
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
4536 |
2786
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4537 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
|
4538 return NGX_OK; |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4539 } |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4540 |
2669
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4541 if (r->cache == NULL) { |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4542 return NGX_OK; |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4543 } |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4544 |
5500
6a3ab6fdd70f
Upstream: Cache-Control preferred over Expires.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5489
diff
changeset
|
4545 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
|
4546 return NGX_OK; |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4547 } |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4548 |
5911
88d55e5934f7
Cache: add support for Cache-Control's s-maxage response directive.
Piotr Sikora <piotr@cloudflare.com>
parents:
5905
diff
changeset
|
4549 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
|
4550 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
|
4551 |
88d55e5934f7
Cache: add support for Cache-Control's s-maxage response directive.
Piotr Sikora <piotr@cloudflare.com>
parents:
5905
diff
changeset
|
4552 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
|
4553 || 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
|
4554 || 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
|
4555 { |
2786
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4556 u->cacheable = 0; |
2669
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4557 return NGX_OK; |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4558 } |
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4559 |
5911
88d55e5934f7
Cache: add support for Cache-Control's s-maxage response directive.
Piotr Sikora <piotr@cloudflare.com>
parents:
5905
diff
changeset
|
4560 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
|
4561 offset = 9; |
88d55e5934f7
Cache: add support for Cache-Control's s-maxage response directive.
Piotr Sikora <piotr@cloudflare.com>
parents:
5905
diff
changeset
|
4562 |
88d55e5934f7
Cache: add support for Cache-Control's s-maxage response directive.
Piotr Sikora <piotr@cloudflare.com>
parents:
5905
diff
changeset
|
4563 if (p == NULL) { |
88d55e5934f7
Cache: add support for Cache-Control's s-maxage response directive.
Piotr Sikora <piotr@cloudflare.com>
parents:
5905
diff
changeset
|
4564 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
|
4565 offset = 8; |
88d55e5934f7
Cache: add support for Cache-Control's s-maxage response directive.
Piotr Sikora <piotr@cloudflare.com>
parents:
5905
diff
changeset
|
4566 } |
2669
5e4d8bd4486c
support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2667
diff
changeset
|
4567 |
6905
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4568 if (p) { |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4569 n = 0; |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4570 |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4571 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
|
4572 if (*p == ',' || *p == ';' || *p == ' ') { |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4573 break; |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4574 } |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4575 |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4576 if (*p >= '0' && *p <= '9') { |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4577 n = n * 10 + *p - '0'; |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4578 continue; |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4579 } |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4580 |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4581 u->cacheable = 0; |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4582 return NGX_OK; |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4583 } |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4584 |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4585 if (n == 0) { |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4586 u->cacheable = 0; |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4587 return NGX_OK; |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4588 } |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4589 |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4590 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
|
4591 } |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4592 |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4593 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
|
4594 23 - 1); |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4595 |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4596 if (p) { |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4597 n = 0; |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4598 |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4599 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
|
4600 if (*p == ',' || *p == ';' || *p == ' ') { |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4601 break; |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4602 } |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4603 |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4604 if (*p >= '0' && *p <= '9') { |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4605 n = n * 10 + *p - '0'; |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4606 continue; |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4607 } |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4608 |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4609 u->cacheable = 0; |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4610 return NGX_OK; |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4611 } |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4612 |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4613 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
|
4614 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
|
4615 } |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4616 |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4617 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
|
4618 |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4619 if (p) { |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4620 n = 0; |
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 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
|
4623 if (*p == ',' || *p == ';' || *p == ' ') { |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4624 break; |
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 |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4627 if (*p >= '0' && *p <= '9') { |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4628 n = n * 10 + *p - '0'; |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4629 continue; |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4630 } |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4631 |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4632 u->cacheable = 0; |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4633 return NGX_OK; |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4634 } |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4635 |
9a9e13686869
Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents:
6899
diff
changeset
|
4636 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
|
4637 } |
2708
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
4638 } |
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
4639 #endif |
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
4640 |
509 | 4641 return NGX_OK; |
4642 } | |
4643 | |
4644 | |
4645 static ngx_int_t | |
2666 | 4646 ngx_http_upstream_process_expires(ngx_http_request_t *r, ngx_table_elt_t *h, |
4647 ngx_uint_t offset) | |
4648 { | |
2786
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4649 ngx_http_upstream_t *u; |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4650 |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4651 u = r->upstream; |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4652 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
|
4653 |
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
4654 #if (NGX_HTTP_CACHE) |
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
4655 { |
2666 | 4656 time_t expires; |
4657 | |
2786
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4658 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
|
4659 return NGX_OK; |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4660 } |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4661 |
2666 | 4662 if (r->cache == NULL) { |
4663 return NGX_OK; | |
4664 } | |
4665 | |
4666 if (r->cache->valid_sec != 0) { | |
4667 return NGX_OK; | |
4668 } | |
4669 | |
6180
8b6fa4842133
Moved ngx_http_parse_time() to core, renamed accordingly.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6147
diff
changeset
|
4670 expires = ngx_parse_http_time(h->value.data, h->value.len); |
2666 | 4671 |
4672 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
|
4673 u->cacheable = 0; |
2666 | 4674 return NGX_OK; |
4675 } | |
4676 | |
4677 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
|
4678 } |
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
4679 #endif |
2666 | 4680 |
4681 return NGX_OK; | |
4682 } | |
4683 | |
4684 | |
4685 static ngx_int_t | |
2663
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4686 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
|
4687 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
|
4688 { |
2786
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4689 ngx_http_upstream_t *u; |
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 u = r->upstream; |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4692 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
|
4693 |
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
4694 #if (NGX_HTTP_CACHE) |
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
4695 { |
2663
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4696 u_char *p; |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4697 size_t len; |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4698 ngx_int_t n; |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4699 |
2786
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4700 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
|
4701 return NGX_OK; |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4702 } |
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4703 |
2663
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4704 if (r->cache == NULL) { |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4705 return NGX_OK; |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4706 } |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4707 |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4708 len = h->value.len; |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4709 p = h->value.data; |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4710 |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4711 if (p[0] != '@') { |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4712 n = ngx_atoi(p, len); |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4713 |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4714 switch (n) { |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4715 case 0: |
2786
4e002555652d
proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents:
2757
diff
changeset
|
4716 u->cacheable = 0; |
4546
4988fa232629
For the sake of case/switch code readability, 'fall through'
Maxim Konovalov <maxim@nginx.com>
parents:
4499
diff
changeset
|
4717 /* fall through */ |
4988fa232629
For the sake of case/switch code readability, 'fall through'
Maxim Konovalov <maxim@nginx.com>
parents:
4499
diff
changeset
|
4718 |
2663
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4719 case NGX_ERROR: |
2667 | 4720 return NGX_OK; |
2663
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4721 |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4722 default: |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4723 r->cache->valid_sec = ngx_time() + n; |
2667 | 4724 return NGX_OK; |
2663
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4725 } |
2667 | 4726 } |
4727 | |
4728 p++; | |
4729 len--; | |
4730 | |
4731 n = ngx_atoi(p, len); | |
4732 | |
4733 if (n != NGX_ERROR) { | |
4734 r->cache->valid_sec = n; | |
2663
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4735 } |
2708
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
4736 } |
4c658be4ab63
fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents:
2704
diff
changeset
|
4737 #endif |
2663
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4738 |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4739 return NGX_OK; |
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 |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4742 |
09725d69cb25
support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents:
2662
diff
changeset
|
4743 static ngx_int_t |
527 | 4744 ngx_http_upstream_process_limit_rate(ngx_http_request_t *r, ngx_table_elt_t *h, |
4745 ngx_uint_t offset) | |
577 | 4746 { |
4197
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4747 ngx_int_t n; |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4748 ngx_http_upstream_t *u; |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4749 |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4750 u = r->upstream; |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4751 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
|
4752 |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4753 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
|
4754 return NGX_OK; |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4755 } |
527 | 4756 |
4757 n = ngx_atoi(h->value.data, h->value.len); | |
4758 | |
4759 if (n != NGX_ERROR) { | |
4760 r->limit_rate = (size_t) n; | |
4761 } | |
4762 | |
4763 return NGX_OK; | |
4764 } | |
4765 | |
4766 | |
4767 static ngx_int_t | |
649 | 4768 ngx_http_upstream_process_buffering(ngx_http_request_t *r, ngx_table_elt_t *h, |
4769 ngx_uint_t offset) | |
4770 { | |
4197
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4771 u_char c0, c1, c2; |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4772 ngx_http_upstream_t *u; |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4773 |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4774 u = r->upstream; |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4775 |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4776 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
|
4777 return NGX_OK; |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4778 } |
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 if (u->conf->change_buffering) { |
649 | 4781 |
4782 if (h->value.len == 2) { | |
4783 c0 = ngx_tolower(h->value.data[0]); | |
4784 c1 = ngx_tolower(h->value.data[1]); | |
4785 | |
4786 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
|
4787 u->buffering = 0; |
649 | 4788 } |
4789 | |
4790 } else if (h->value.len == 3) { | |
4791 c0 = ngx_tolower(h->value.data[0]); | |
4792 c1 = ngx_tolower(h->value.data[1]); | |
4793 c2 = ngx_tolower(h->value.data[2]); | |
4794 | |
4795 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
|
4796 u->buffering = 1; |
649 | 4797 } |
4798 } | |
4799 } | |
4800 | |
4801 return NGX_OK; | |
4802 } | |
4803 | |
4804 | |
4805 static ngx_int_t | |
657 | 4806 ngx_http_upstream_process_charset(ngx_http_request_t *r, ngx_table_elt_t *h, |
4807 ngx_uint_t offset) | |
4808 { | |
4197
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4809 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
|
4810 return NGX_OK; |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4811 } |
cf6a3467b5db
Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4182
diff
changeset
|
4812 |
657 | 4813 r->headers_out.override_charset = &h->value; |
4814 | |
4815 return NGX_OK; | |
4816 } | |
4817 | |
4818 | |
4819 static ngx_int_t | |
4124
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4820 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
|
4821 ngx_uint_t offset) |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4822 { |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4823 r->upstream->headers_in.connection = h; |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4824 |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4825 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
|
4826 (u_char *) "close", 5 - 1) |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4827 != NULL) |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4828 { |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4829 r->upstream->headers_in.connection_close = 1; |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4830 } |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4831 |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4832 return NGX_OK; |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4833 } |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4834 |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4835 |
0c30976f5bfa
Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4123
diff
changeset
|
4836 static ngx_int_t |
4123
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4837 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
|
4838 ngx_table_elt_t *h, ngx_uint_t offset) |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4839 { |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4840 r->upstream->headers_in.transfer_encoding = h; |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4841 |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4842 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
|
4843 (u_char *) "chunked", 7 - 1) |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4844 != NULL) |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4845 { |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4846 r->upstream->headers_in.chunked = 1; |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4847 } |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4848 |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4849 return NGX_OK; |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4850 } |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4851 |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4852 |
0ee350b5177c
Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4120
diff
changeset
|
4853 static ngx_int_t |
5877
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4854 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
|
4855 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
|
4856 { |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4857 ngx_http_upstream_t *u; |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4858 |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4859 u = r->upstream; |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4860 u->headers_in.vary = h; |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4861 |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4862 #if (NGX_HTTP_CACHE) |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4863 |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4864 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
|
4865 return NGX_OK; |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4866 } |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4867 |
5878
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5877
diff
changeset
|
4868 if (r->cache == NULL) { |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5877
diff
changeset
|
4869 return NGX_OK; |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5877
diff
changeset
|
4870 } |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5877
diff
changeset
|
4871 |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5877
diff
changeset
|
4872 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
|
4873 || (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
|
4874 { |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5877
diff
changeset
|
4875 u->cacheable = 0; |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5877
diff
changeset
|
4876 } |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5877
diff
changeset
|
4877 |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5877
diff
changeset
|
4878 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
|
4879 |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4880 #endif |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4881 |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4882 return NGX_OK; |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4883 } |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4884 |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4885 |
60fde1bc7236
Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5874
diff
changeset
|
4886 static ngx_int_t |
509 | 4887 ngx_http_upstream_copy_header_line(ngx_http_request_t *r, ngx_table_elt_t *h, |
4888 ngx_uint_t offset) | |
4889 { | |
573 | 4890 ngx_table_elt_t *ho, **ph; |
509 | 4891 |
4892 ho = ngx_list_push(&r->headers_out.headers); | |
4893 if (ho == NULL) { | |
4894 return NGX_ERROR; | |
4895 } | |
4896 | |
4897 *ho = *h; | |
4898 | |
573 | 4899 if (offset) { |
4900 ph = (ngx_table_elt_t **) ((char *) &r->headers_out + offset); | |
4901 *ph = ho; | |
4902 } | |
4903 | |
509 | 4904 return NGX_OK; |
4905 } | |
4906 | |
4907 | |
4908 static ngx_int_t | |
4909 ngx_http_upstream_copy_multi_header_lines(ngx_http_request_t *r, | |
4910 ngx_table_elt_t *h, ngx_uint_t offset) | |
4911 { | |
4912 ngx_array_t *pa; | |
4913 ngx_table_elt_t *ho, **ph; | |
4914 | |
4915 pa = (ngx_array_t *) ((char *) &r->headers_out + offset); | |
4916 | |
4917 if (pa->elts == NULL) { | |
4918 if (ngx_array_init(pa, r->pool, 2, sizeof(ngx_table_elt_t *)) != NGX_OK) | |
4919 { | |
4920 return NGX_ERROR; | |
4921 } | |
4922 } | |
4923 | |
4924 ph = ngx_array_push(pa); | |
4925 if (ph == NULL) { | |
4926 return NGX_ERROR; | |
4927 } | |
4928 | |
4929 ho = ngx_list_push(&r->headers_out.headers); | |
4930 if (ho == NULL) { | |
4931 return NGX_ERROR; | |
4932 } | |
4933 | |
4934 *ho = *h; | |
4935 *ph = ho; | |
4936 | |
4937 return NGX_OK; | |
4938 } | |
4939 | |
4940 | |
4941 static ngx_int_t | |
4942 ngx_http_upstream_copy_content_type(ngx_http_request_t *r, ngx_table_elt_t *h, | |
4943 ngx_uint_t offset) | |
4944 { | |
657 | 4945 u_char *p, *last; |
4946 | |
4947 r->headers_out.content_type_len = h->value.len; | |
509 | 4948 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
|
4949 r->headers_out.content_type_lowcase = NULL; |
509 | 4950 |
657 | 4951 for (p = h->value.data; *p; p++) { |
4952 | |
4953 if (*p != ';') { | |
4954 continue; | |
4955 } | |
4956 | |
4957 last = p; | |
4958 | |
4959 while (*++p == ' ') { /* void */ } | |
4960 | |
1968 | 4961 if (*p == '\0') { |
4962 return NGX_OK; | |
4963 } | |
4964 | |
1107
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1098
diff
changeset
|
4965 if (ngx_strncasecmp(p, (u_char *) "charset=", 8) != 0) { |
657 | 4966 continue; |
4967 } | |
4968 | |
4969 p += 8; | |
4970 | |
4971 r->headers_out.content_type_len = last - h->value.data; | |
4972 | |
2244 | 4973 if (*p == '"') { |
4974 p++; | |
4975 } | |
4976 | |
4977 last = h->value.data + h->value.len; | |
4978 | |
4979 if (*(last - 1) == '"') { | |
4980 last--; | |
4981 } | |
4982 | |
4983 r->headers_out.charset.len = last - p; | |
657 | 4984 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
|
4985 |
c6c42497106c
fix segfault if upstream sends trailing ";" in "charset="
Igor Sysoev <igor@sysoev.ru>
parents:
1109
diff
changeset
|
4986 return NGX_OK; |
657 | 4987 } |
4988 | |
509 | 4989 return NGX_OK; |
4990 } | |
4991 | |
4992 | |
4993 static ngx_int_t | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4994 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
|
4995 ngx_uint_t offset) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4996 { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4997 ngx_table_elt_t *ho; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4998 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
4999 ho = ngx_list_push(&r->headers_out.headers); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5000 if (ho == NULL) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5001 return NGX_ERROR; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5002 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5003 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5004 *ho = *h; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5005 |
3004
4121acaf7a04
fix handling "Last-Modified" and "Accept-Ranges" for upstream responses
Igor Sysoev <igor@sysoev.ru>
parents:
3003
diff
changeset
|
5006 r->headers_out.last_modified = ho; |
4121acaf7a04
fix handling "Last-Modified" and "Accept-Ranges" for upstream responses
Igor Sysoev <igor@sysoev.ru>
parents:
3003
diff
changeset
|
5007 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5008 #if (NGX_HTTP_CACHE) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5009 |
2952 | 5010 if (r->upstream->cacheable) { |
5732
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
5011 r->headers_out.last_modified_time = |
d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5731
diff
changeset
|
5012 r->upstream->headers_in.last_modified_time; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5013 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5014 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5015 #endif |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5016 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5017 return NGX_OK; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5018 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5019 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5020 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5021 static ngx_int_t |
509 | 5022 ngx_http_upstream_rewrite_location(ngx_http_request_t *r, ngx_table_elt_t *h, |
5023 ngx_uint_t offset) | |
5024 { | |
5025 ngx_int_t rc; | |
5026 ngx_table_elt_t *ho; | |
5027 | |
5028 ho = ngx_list_push(&r->headers_out.headers); | |
5029 if (ho == NULL) { | |
5030 return NGX_ERROR; | |
5031 } | |
5032 | |
5033 *ho = *h; | |
5034 | |
5035 if (r->upstream->rewrite_redirect) { | |
5036 rc = r->upstream->rewrite_redirect(r, ho, 0); | |
5037 | |
529 | 5038 if (rc == NGX_DECLINED) { |
5039 return NGX_OK; | |
5040 } | |
5041 | |
509 | 5042 if (rc == NGX_OK) { |
5043 r->headers_out.location = ho; | |
5044 | |
5045 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
5046 "rewritten location: \"%V\"", &ho->value); | |
5047 } | |
5048 | |
5049 return rc; | |
5050 } | |
5051 | |
1653
ea681a6a0c61
set r->headers_out.location for non-local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
5052 if (ho->value.data[0] != '/') { |
ea681a6a0c61
set r->headers_out.location for non-local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
5053 r->headers_out.location = ho; |
ea681a6a0c61
set r->headers_out.location for non-local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
5054 } |
ea681a6a0c61
set r->headers_out.location for non-local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
5055 |
509 | 5056 /* |
6853
c85dfd99a2dd
Fixed missing "Location" field with some relative redirects.
Ruslan Ermilov <ru@nginx.com>
parents:
6799
diff
changeset
|
5057 * 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
|
5058 * relative redirects in ngx_http_header_filter() |
509 | 5059 */ |
5060 | |
5061 return NGX_OK; | |
5062 } | |
5063 | |
5064 | |
5065 static ngx_int_t | |
5066 ngx_http_upstream_rewrite_refresh(ngx_http_request_t *r, ngx_table_elt_t *h, | |
5067 ngx_uint_t offset) | |
5068 { | |
5069 u_char *p; | |
5070 ngx_int_t rc; | |
5071 ngx_table_elt_t *ho; | |
5072 | |
5073 ho = ngx_list_push(&r->headers_out.headers); | |
5074 if (ho == NULL) { | |
5075 return NGX_ERROR; | |
5076 } | |
5077 | |
5078 *ho = *h; | |
5079 | |
5080 if (r->upstream->rewrite_redirect) { | |
5081 | |
1549 | 5082 p = ngx_strcasestrn(ho->value.data, "url=", 4 - 1); |
509 | 5083 |
5084 if (p) { | |
5085 rc = r->upstream->rewrite_redirect(r, ho, p + 4 - ho->value.data); | |
5086 | |
5087 } else { | |
5088 return NGX_OK; | |
5089 } | |
5090 | |
529 | 5091 if (rc == NGX_DECLINED) { |
5092 return NGX_OK; | |
5093 } | |
5094 | |
509 | 5095 if (rc == NGX_OK) { |
1654 | 5096 r->headers_out.refresh = ho; |
5097 | |
509 | 5098 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
5099 "rewritten refresh: \"%V\"", &ho->value); | |
5100 } | |
5101 | |
5102 return rc; | |
5103 } | |
5104 | |
1654 | 5105 r->headers_out.refresh = ho; |
5106 | |
509 | 5107 return NGX_OK; |
5108 } | |
5109 | |
5110 | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5111 static ngx_int_t |
4464
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
5112 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
|
5113 ngx_uint_t offset) |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
5114 { |
4650
b38fea6f9a15
Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents:
4572
diff
changeset
|
5115 ngx_int_t rc; |
4464
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
5116 ngx_table_elt_t *ho; |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
5117 |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
5118 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
|
5119 if (ho == NULL) { |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
5120 return NGX_ERROR; |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
5121 } |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
5122 |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
5123 *ho = *h; |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
5124 |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
5125 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
|
5126 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
|
5127 |
b38fea6f9a15
Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents:
4572
diff
changeset
|
5128 if (rc == NGX_DECLINED) { |
b38fea6f9a15
Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents:
4572
diff
changeset
|
5129 return NGX_OK; |
b38fea6f9a15
Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents:
4572
diff
changeset
|
5130 } |
b38fea6f9a15
Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents:
4572
diff
changeset
|
5131 |
b38fea6f9a15
Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents:
4572
diff
changeset
|
5132 #if (NGX_DEBUG) |
b38fea6f9a15
Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents:
4572
diff
changeset
|
5133 if (rc == NGX_OK) { |
b38fea6f9a15
Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents:
4572
diff
changeset
|
5134 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
|
5135 "rewritten cookie: \"%V\"", &ho->value); |
b38fea6f9a15
Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents:
4572
diff
changeset
|
5136 } |
b38fea6f9a15
Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents:
4572
diff
changeset
|
5137 #endif |
b38fea6f9a15
Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents:
4572
diff
changeset
|
5138 |
b38fea6f9a15
Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents:
4572
diff
changeset
|
5139 return rc; |
4464
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
5140 } |
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 return NGX_OK; |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
5143 } |
7bf3b68239a3
Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents:
4460
diff
changeset
|
5144 |
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 static ngx_int_t |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5147 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
|
5148 ngx_table_elt_t *h, ngx_uint_t offset) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5149 { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5150 ngx_table_elt_t *ho; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5151 |
5874
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
5152 if (r->upstream->conf->force_ranges) { |
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
5153 return NGX_OK; |
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
5154 } |
2aff40b3dea2
Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5869
diff
changeset
|
5155 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5156 #if (NGX_HTTP_CACHE) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5157 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5158 if (r->cached) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5159 r->allow_ranges = 1; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5160 return NGX_OK; |
5621
345e4fd4bb64
Range filter: single_range flag in request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5581
diff
changeset
|
5161 } |
345e4fd4bb64
Range filter: single_range flag in request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5581
diff
changeset
|
5162 |
345e4fd4bb64
Range filter: single_range flag in request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5581
diff
changeset
|
5163 if (r->upstream->cacheable) { |
345e4fd4bb64
Range filter: single_range flag in request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5581
diff
changeset
|
5164 r->allow_ranges = 1; |
345e4fd4bb64
Range filter: single_range flag in request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5581
diff
changeset
|
5165 r->single_range = 1; |
345e4fd4bb64
Range filter: single_range flag in request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5581
diff
changeset
|
5166 return NGX_OK; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5167 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5168 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5169 #endif |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5170 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5171 ho = ngx_list_push(&r->headers_out.headers); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5172 if (ho == NULL) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5173 return NGX_ERROR; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5174 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5175 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5176 *ho = *h; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5177 |
3004
4121acaf7a04
fix handling "Last-Modified" and "Accept-Ranges" for upstream responses
Igor Sysoev <igor@sysoev.ru>
parents:
3003
diff
changeset
|
5178 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
|
5179 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5180 return NGX_OK; |
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 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
5183 |
509 | 5184 #if (NGX_HTTP_GZIP) |
5185 | |
5186 static ngx_int_t | |
5187 ngx_http_upstream_copy_content_encoding(ngx_http_request_t *r, | |
5188 ngx_table_elt_t *h, ngx_uint_t offset) | |
5189 { | |
5190 ngx_table_elt_t *ho; | |
5191 | |
5192 ho = ngx_list_push(&r->headers_out.headers); | |
5193 if (ho == NULL) { | |
5194 return NGX_ERROR; | |
5195 } | |
5196 | |
5197 *ho = *h; | |
5198 | |
5199 r->headers_out.content_encoding = ho; | |
5200 | |
5201 return NGX_OK; | |
5202 } | |
5203 | |
5204 #endif | |
5205 | |
5206 | |
487 | 5207 static ngx_int_t |
573 | 5208 ngx_http_upstream_add_variables(ngx_conf_t *cf) |
479 | 5209 { |
880 | 5210 ngx_http_variable_t *var, *v; |
479 | 5211 |
573 | 5212 for (v = ngx_http_upstream_vars; v->name.len; v++) { |
5213 var = ngx_http_add_variable(cf, &v->name, v->flags); | |
5214 if (var == NULL) { | |
5215 return NGX_ERROR; | |
5216 } | |
5217 | |
637 | 5218 var->get_handler = v->get_handler; |
573 | 5219 var->data = v->data; |
5220 } | |
5221 | |
479 | 5222 return NGX_OK; |
5223 } | |
509 | 5224 |
5225 | |
573 | 5226 static ngx_int_t |
1181 | 5227 ngx_http_upstream_addr_variable(ngx_http_request_t *r, |
5228 ngx_http_variable_value_t *v, uintptr_t data) | |
5229 { | |
5230 u_char *p; | |
5231 size_t len; | |
5232 ngx_uint_t i; | |
5233 ngx_http_upstream_state_t *state; | |
5234 | |
5235 v->valid = 1; | |
1565 | 5236 v->no_cacheable = 0; |
1181 | 5237 v->not_found = 0; |
5238 | |
5239 if (r->upstream_states == NULL || r->upstream_states->nelts == 0) { | |
5240 v->not_found = 1; | |
5241 return NGX_OK; | |
5242 } | |
5243 | |
5244 len = 0; | |
5245 state = r->upstream_states->elts; | |
5246 | |
5247 for (i = 0; i < r->upstream_states->nelts; i++) { | |
5248 if (state[i].peer) { | |
5249 len += state[i].peer->len + 2; | |
5250 | |
5251 } else { | |
5252 len += 3; | |
5253 } | |
5254 } | |
5255 | |
2049 | 5256 p = ngx_pnalloc(r->pool, len); |
1181 | 5257 if (p == NULL) { |
5258 return NGX_ERROR; | |
5259 } | |
5260 | |
5261 v->data = p; | |
5262 | |
5263 i = 0; | |
5264 | |
5265 for ( ;; ) { | |
5266 if (state[i].peer) { | |
5267 p = ngx_cpymem(p, state[i].peer->data, state[i].peer->len); | |
5268 } | |
5269 | |
5270 if (++i == r->upstream_states->nelts) { | |
5271 break; | |
5272 } | |
5273 | |
5274 if (state[i].peer) { | |
5275 *p++ = ','; | |
5276 *p++ = ' '; | |
5277 | |
5278 } else { | |
5279 *p++ = ' '; | |
5280 *p++ = ':'; | |
5281 *p++ = ' '; | |
5282 | |
5283 if (++i == r->upstream_states->nelts) { | |
5284 break; | |
5285 } | |
5286 | |
5287 continue; | |
5288 } | |
5289 } | |
5290 | |
5291 v->len = p - v->data; | |
5292 | |
5293 return NGX_OK; | |
5294 } | |
5295 | |
5296 | |
5297 static ngx_int_t | |
573 | 5298 ngx_http_upstream_status_variable(ngx_http_request_t *r, |
5299 ngx_http_variable_value_t *v, uintptr_t data) | |
5300 { | |
5301 u_char *p; | |
5302 size_t len; | |
5303 ngx_uint_t i; | |
5304 ngx_http_upstream_state_t *state; | |
5305 | |
5306 v->valid = 1; | |
1565 | 5307 v->no_cacheable = 0; |
573 | 5308 v->not_found = 0; |
5309 | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5310 if (r->upstream_states == NULL || r->upstream_states->nelts == 0) { |
573 | 5311 v->not_found = 1; |
5312 return NGX_OK; | |
5313 } | |
5314 | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5315 len = r->upstream_states->nelts * (3 + 2); |
573 | 5316 |
2049 | 5317 p = ngx_pnalloc(r->pool, len); |
573 | 5318 if (p == NULL) { |
5319 return NGX_ERROR; | |
5320 } | |
5321 | |
5322 v->data = p; | |
5323 | |
5324 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
|
5325 state = r->upstream_states->elts; |
573 | 5326 |
5327 for ( ;; ) { | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5328 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
|
5329 p = ngx_sprintf(p, "%ui", state[i].status); |
573 | 5330 |
5331 } else { | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5332 *p++ = '-'; |
573 | 5333 } |
5334 | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5335 if (++i == r->upstream_states->nelts) { |
573 | 5336 break; |
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 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
|
5340 *p++ = ','; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5341 *p++ = ' '; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5342 |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5343 } else { |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5344 *p++ = ' '; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5345 *p++ = ':'; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5346 *p++ = ' '; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5347 |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5348 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
|
5349 break; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5350 } |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5351 |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5352 continue; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5353 } |
573 | 5354 } |
5355 | |
5356 v->len = p - v->data; | |
5357 | |
5358 return NGX_OK; | |
5359 } | |
5360 | |
5361 | |
5362 static ngx_int_t | |
5363 ngx_http_upstream_response_time_variable(ngx_http_request_t *r, | |
5364 ngx_http_variable_value_t *v, uintptr_t data) | |
5365 { | |
5366 u_char *p; | |
5367 size_t len; | |
5368 ngx_uint_t i; | |
889
a9a7e4b1a72b
the previous fix does not actually fix overflow
Igor Sysoev <igor@sysoev.ru>
parents:
888
diff
changeset
|
5369 ngx_msec_int_t ms; |
573 | 5370 ngx_http_upstream_state_t *state; |
5371 | |
5372 v->valid = 1; | |
1565 | 5373 v->no_cacheable = 0; |
573 | 5374 v->not_found = 0; |
5375 | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5376 if (r->upstream_states == NULL || r->upstream_states->nelts == 0) { |
573 | 5377 v->not_found = 1; |
5378 return NGX_OK; | |
5379 } | |
5380 | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5381 len = r->upstream_states->nelts * (NGX_TIME_T_LEN + 4 + 2); |
573 | 5382 |
2049 | 5383 p = ngx_pnalloc(r->pool, len); |
573 | 5384 if (p == NULL) { |
5385 return NGX_ERROR; | |
5386 } | |
5387 | |
5388 v->data = p; | |
5389 | |
5390 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
|
5391 state = r->upstream_states->elts; |
573 | 5392 |
5393 for ( ;; ) { | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5394 if (state[i].status) { |
5964
0a198a517eaf
Upstream: $upstream_header_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
5960
diff
changeset
|
5395 |
6147
74b6ef56ea56
Upstream: $upstream_connect_time.
Ruslan Ermilov <ru@nginx.com>
parents:
6146
diff
changeset
|
5396 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
|
5397 ms = state[i].header_time; |
5964
0a198a517eaf
Upstream: $upstream_header_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
5960
diff
changeset
|
5398 |
6147
74b6ef56ea56
Upstream: $upstream_connect_time.
Ruslan Ermilov <ru@nginx.com>
parents:
6146
diff
changeset
|
5399 } 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
|
5400 ms = state[i].connect_time; |
74b6ef56ea56
Upstream: $upstream_connect_time.
Ruslan Ermilov <ru@nginx.com>
parents:
6146
diff
changeset
|
5401 |
5964
0a198a517eaf
Upstream: $upstream_header_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
5960
diff
changeset
|
5402 } else { |
6146
59fc60585f1e
Upstream: times to obtain header/response are stored as ngx_msec_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6125
diff
changeset
|
5403 ms = state[i].response_time; |
5964
0a198a517eaf
Upstream: $upstream_header_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
5960
diff
changeset
|
5404 } |
0a198a517eaf
Upstream: $upstream_header_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
5960
diff
changeset
|
5405 |
3515 | 5406 ms = ngx_max(ms, 0); |
5368
cd46297325bd
Upstream: fixed $upstream_response_time format specifiers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5353
diff
changeset
|
5407 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
|
5408 |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5409 } else { |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5410 *p++ = '-'; |
573 | 5411 } |
5412 | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5413 if (++i == r->upstream_states->nelts) { |
573 | 5414 break; |
5415 } | |
5416 | |
1168
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5417 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
|
5418 *p++ = ','; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5419 *p++ = ' '; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5420 |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5421 } else { |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5422 *p++ = ' '; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5423 *p++ = ':'; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5424 *p++ = ' '; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5425 |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5426 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
|
5427 break; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5428 } |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5429 |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5430 continue; |
4d0d12446c3b
store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
5431 } |
573 | 5432 } |
5433 | |
5434 v->len = p - v->data; | |
5435 | |
5436 return NGX_OK; | |
5437 } | |
5438 | |
5439 | |
2402 | 5440 static ngx_int_t |
5441 ngx_http_upstream_response_length_variable(ngx_http_request_t *r, | |
5442 ngx_http_variable_value_t *v, uintptr_t data) | |
5443 { | |
5444 u_char *p; | |
5445 size_t len; | |
5446 ngx_uint_t i; | |
5447 ngx_http_upstream_state_t *state; | |
5448 | |
5449 v->valid = 1; | |
5450 v->no_cacheable = 0; | |
5451 v->not_found = 0; | |
5452 | |
5453 if (r->upstream_states == NULL || r->upstream_states->nelts == 0) { | |
5454 v->not_found = 1; | |
5455 return NGX_OK; | |
5456 } | |
5457 | |
5458 len = r->upstream_states->nelts * (NGX_OFF_T_LEN + 2); | |
5459 | |
5460 p = ngx_pnalloc(r->pool, len); | |
5461 if (p == NULL) { | |
5462 return NGX_ERROR; | |
5463 } | |
5464 | |
5465 v->data = p; | |
5466 | |
5467 i = 0; | |
5468 state = r->upstream_states->elts; | |
5469 | |
5470 for ( ;; ) { | |
6654
c131f20c9562
Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6594
diff
changeset
|
5471 |
c131f20c9562
Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6594
diff
changeset
|
5472 if (data == 1) { |
c131f20c9562
Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6594
diff
changeset
|
5473 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
|
5474 |
c131f20c9562
Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6594
diff
changeset
|
5475 } else { |
c131f20c9562
Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents:
6594
diff
changeset
|
5476 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
|
5477 } |
2402 | 5478 |
5479 if (++i == r->upstream_states->nelts) { | |
5480 break; | |
5481 } | |
5482 | |
5483 if (state[i].peer) { | |
5484 *p++ = ','; | |
5485 *p++ = ' '; | |
5486 | |
5487 } else { | |
5488 *p++ = ' '; | |
5489 *p++ = ':'; | |
5490 *p++ = ' '; | |
5491 | |
5492 if (++i == r->upstream_states->nelts) { | |
5493 break; | |
5494 } | |
5495 | |
5496 continue; | |
5497 } | |
5498 } | |
5499 | |
5500 v->len = p - v->data; | |
5501 | |
5502 return NGX_OK; | |
5503 } | |
5504 | |
5505 | |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6876
diff
changeset
|
5506 static ngx_int_t |
1162 | 5507 ngx_http_upstream_header_variable(ngx_http_request_t *r, |
5508 ngx_http_variable_value_t *v, uintptr_t data) | |
5509 { | |
5510 if (r->upstream == NULL) { | |
5511 v->not_found = 1; | |
5512 return NGX_OK; | |
5513 } | |
5514 | |
5515 return ngx_http_variable_unknown_header(v, (ngx_str_t *) data, | |
5516 &r->upstream->headers_in.headers.part, | |
5517 sizeof("upstream_http_") - 1); | |
5518 } | |
5519 | |
5520 | |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6876
diff
changeset
|
5521 static ngx_int_t |
5677
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5522 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
|
5523 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
|
5524 { |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5525 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
|
5526 |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5527 ngx_str_t cookie, s; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5528 |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5529 if (r->upstream == NULL) { |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5530 v->not_found = 1; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5531 return NGX_OK; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5532 } |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5533 |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5534 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
|
5535 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
|
5536 |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5537 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
|
5538 &s, &cookie) |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5539 == NGX_DECLINED) |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5540 { |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5541 v->not_found = 1; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5542 return NGX_OK; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5543 } |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5544 |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5545 v->len = cookie.len; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5546 v->valid = 1; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5547 v->no_cacheable = 0; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5548 v->not_found = 0; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5549 v->data = cookie.data; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5550 |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5551 return NGX_OK; |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5552 } |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5553 |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5667
diff
changeset
|
5554 |
2952 | 5555 #if (NGX_HTTP_CACHE) |
5556 | |
6923
fbdaad9b0e7b
Added missing "static" specifiers found by gcc -Wtraditional.
Ruslan Ermilov <ru@nginx.com>
parents:
6922
diff
changeset
|
5557 static ngx_int_t |
2952 | 5558 ngx_http_upstream_cache_status(ngx_http_request_t *r, |
5559 ngx_http_variable_value_t *v, uintptr_t data) | |
5560 { | |
5561 ngx_uint_t n; | |
5562 | |
5563 if (r->upstream == NULL || r->upstream->cache_status == 0) { | |
5564 v->not_found = 1; | |
5565 return NGX_OK; | |
5566 } | |
5567 | |
5568 n = r->upstream->cache_status - 1; | |
5569 | |
5570 v->valid = 1; | |
5571 v->no_cacheable = 0; | |
5572 v->not_found = 0; | |
5573 v->len = ngx_http_cache_status[n].len; | |
5574 v->data = ngx_http_cache_status[n].data; | |
5575 | |
5576 return NGX_OK; | |
5577 } | |
5578 | |
5441
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5579 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5580 static ngx_int_t |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5581 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
|
5582 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
|
5583 { |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5584 u_char *p; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5585 |
5453
b7b8e2fa7ebd
Fixed null pointer dereference with $upstream_cache_last_modified.
Ruslan Ermilov <ru@nginx.com>
parents:
5441
diff
changeset
|
5586 if (r->upstream == NULL |
b7b8e2fa7ebd
Fixed null pointer dereference with $upstream_cache_last_modified.
Ruslan Ermilov <ru@nginx.com>
parents:
5441
diff
changeset
|
5587 || !r->upstream->conf->cache_revalidate |
5441
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5588 || r->upstream->cache_status != NGX_HTTP_CACHE_EXPIRED |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5589 || r->cache->last_modified == -1) |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5590 { |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5591 v->not_found = 1; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5592 return NGX_OK; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5593 } |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5594 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5595 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
|
5596 if (p == NULL) { |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5597 return NGX_ERROR; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5598 } |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5599 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5600 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
|
5601 v->valid = 1; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5602 v->no_cacheable = 0; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5603 v->not_found = 0; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5604 v->data = p; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5605 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5606 return NGX_OK; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5607 } |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5410
diff
changeset
|
5608 |
5738
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5609 |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5610 static ngx_int_t |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5611 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
|
5612 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
|
5613 { |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5614 if (r->upstream == NULL |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5615 || !r->upstream->conf->cache_revalidate |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5616 || 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
|
5617 || r->cache->etag.len == 0) |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5618 { |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5619 v->not_found = 1; |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5620 return NGX_OK; |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5621 } |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5622 |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5623 v->valid = 1; |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5624 v->no_cacheable = 0; |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5625 v->not_found = 0; |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5626 v->len = r->cache->etag.len; |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5627 v->data = r->cache->etag.data; |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5628 |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5629 return NGX_OK; |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5630 } |
c95d7882dfc9
Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5737
diff
changeset
|
5631 |
2952 | 5632 #endif |
5633 | |
5634 | |
651 | 5635 static char * |
5636 ngx_http_upstream(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy) | |
5637 { | |
884 | 5638 char *rv; |
5639 void *mconf; | |
5640 ngx_str_t *value; | |
5641 ngx_url_t u; | |
5642 ngx_uint_t m; | |
5643 ngx_conf_t pcf; | |
5644 ngx_http_module_t *module; | |
5645 ngx_http_conf_ctx_t *ctx, *http_ctx; | |
5646 ngx_http_upstream_srv_conf_t *uscf; | |
5647 | |
5648 ngx_memzero(&u, sizeof(ngx_url_t)); | |
5649 | |
5650 value = cf->args->elts; | |
5651 u.host = value[1]; | |
5652 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
|
5653 u.no_port = 1; |
884 | 5654 |
5655 uscf = ngx_http_upstream_add(cf, &u, NGX_HTTP_UPSTREAM_CREATE | |
5656 |NGX_HTTP_UPSTREAM_WEIGHT | |
6705 | 5657 |NGX_HTTP_UPSTREAM_MAX_CONNS |
884 | 5658 |NGX_HTTP_UPSTREAM_MAX_FAILS |
5659 |NGX_HTTP_UPSTREAM_FAIL_TIMEOUT | |
5660 |NGX_HTTP_UPSTREAM_DOWN | |
5661 |NGX_HTTP_UPSTREAM_BACKUP); | |
5662 if (uscf == NULL) { | |
5663 return NGX_CONF_ERROR; | |
5664 } | |
5665 | |
651 | 5666 |
5667 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)); | |
5668 if (ctx == NULL) { | |
5669 return NGX_CONF_ERROR; | |
5670 } | |
5671 | |
884 | 5672 http_ctx = cf->ctx; |
5673 ctx->main_conf = http_ctx->main_conf; | |
651 | 5674 |
5675 /* the upstream{}'s srv_conf */ | |
5676 | |
5677 ctx->srv_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module); | |
5678 if (ctx->srv_conf == NULL) { | |
5679 return NGX_CONF_ERROR; | |
5680 } | |
5681 | |
5682 ctx->srv_conf[ngx_http_upstream_module.ctx_index] = uscf; | |
5683 | |
884 | 5684 uscf->srv_conf = ctx->srv_conf; |
5685 | |
651 | 5686 |
5687 /* the upstream{}'s loc_conf */ | |
5688 | |
5689 ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module); | |
5690 if (ctx->loc_conf == NULL) { | |
5691 return NGX_CONF_ERROR; | |
5692 } | |
5693 | |
6379
cf5e822cf470
Dynamic modules: changed ngx_modules to cycle->modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6334
diff
changeset
|
5694 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
|
5695 if (cf->cycle->modules[m]->type != NGX_HTTP_MODULE) { |
651 | 5696 continue; |
5697 } | |
5698 | |
6379
cf5e822cf470
Dynamic modules: changed ngx_modules to cycle->modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6334
diff
changeset
|
5699 module = cf->cycle->modules[m]->ctx; |
651 | 5700 |
884 | 5701 if (module->create_srv_conf) { |
5702 mconf = module->create_srv_conf(cf); | |
5703 if (mconf == NULL) { | |
5704 return NGX_CONF_ERROR; | |
5705 } | |
5706 | |
6379
cf5e822cf470
Dynamic modules: changed ngx_modules to cycle->modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6334
diff
changeset
|
5707 ctx->srv_conf[cf->cycle->modules[m]->ctx_index] = mconf; |
884 | 5708 } |
5709 | |
651 | 5710 if (module->create_loc_conf) { |
5711 mconf = module->create_loc_conf(cf); | |
5712 if (mconf == NULL) { | |
5713 return NGX_CONF_ERROR; | |
5714 } | |
5715 | |
6379
cf5e822cf470
Dynamic modules: changed ngx_modules to cycle->modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6334
diff
changeset
|
5716 ctx->loc_conf[cf->cycle->modules[m]->ctx_index] = mconf; |
651 | 5717 } |
5718 } | |
5719 | |
5728
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5720 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
|
5721 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
|
5722 if (uscf->servers == NULL) { |
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5723 return NGX_CONF_ERROR; |
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5724 } |
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5725 |
651 | 5726 |
5727 /* parse inside upstream{} */ | |
5728 | |
5729 pcf = *cf; | |
5730 cf->ctx = ctx; | |
5731 cf->cmd_type = NGX_HTTP_UPS_CONF; | |
5732 | |
5733 rv = ngx_conf_parse(cf, NULL); | |
5734 | |
5735 *cf = pcf; | |
5736 | |
5737 if (rv != NGX_CONF_OK) { | |
5738 return rv; | |
5739 } | |
5740 | |
5728
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5741 if (uscf->servers->nelts == 0) { |
651 | 5742 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
5743 "no servers are inside upstream"); | |
5744 return NGX_CONF_ERROR; | |
5745 } | |
5746 | |
5747 return rv; | |
5748 } | |
5749 | |
5750 | |
5751 static char * | |
5752 ngx_http_upstream_server(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
5753 { | |
5754 ngx_http_upstream_srv_conf_t *uscf = conf; | |
5755 | |
884 | 5756 time_t fail_timeout; |
5757 ngx_str_t *value, s; | |
5758 ngx_url_t u; | |
6705 | 5759 ngx_int_t weight, max_conns, max_fails; |
884 | 5760 ngx_uint_t i; |
5761 ngx_http_upstream_server_t *us; | |
651 | 5762 |
884 | 5763 us = ngx_array_push(uscf->servers); |
5764 if (us == NULL) { | |
651 | 5765 return NGX_CONF_ERROR; |
5766 } | |
5767 | |
884 | 5768 ngx_memzero(us, sizeof(ngx_http_upstream_server_t)); |
5769 | |
651 | 5770 value = cf->args->elts; |
5771 | |
663 | 5772 weight = 1; |
6705 | 5773 max_conns = 0; |
884 | 5774 max_fails = 1; |
5775 fail_timeout = 10; | |
5776 | |
5777 for (i = 2; i < cf->args->nelts; i++) { | |
5778 | |
5779 if (ngx_strncmp(value[i].data, "weight=", 7) == 0) { | |
5780 | |
5781 if (!(uscf->flags & NGX_HTTP_UPSTREAM_WEIGHT)) { | |
5818
fe8bafab5b49
Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents:
5774
diff
changeset
|
5782 goto not_supported; |
884 | 5783 } |
5784 | |
5785 weight = ngx_atoi(&value[i].data[7], value[i].len - 7); | |
663 | 5786 |
5787 if (weight == NGX_ERROR || weight == 0) { | |
5788 goto invalid; | |
5789 } | |
5790 | |
884 | 5791 continue; |
5792 } | |
5793 | |
6705 | 5794 if (ngx_strncmp(value[i].data, "max_conns=", 10) == 0) { |
5795 | |
5796 if (!(uscf->flags & NGX_HTTP_UPSTREAM_MAX_CONNS)) { | |
5797 goto not_supported; | |
5798 } | |
5799 | |
5800 max_conns = ngx_atoi(&value[i].data[10], value[i].len - 10); | |
5801 | |
5802 if (max_conns == NGX_ERROR) { | |
5803 goto invalid; | |
5804 } | |
5805 | |
5806 continue; | |
5807 } | |
5808 | |
884 | 5809 if (ngx_strncmp(value[i].data, "max_fails=", 10) == 0) { |
5810 | |
5811 if (!(uscf->flags & NGX_HTTP_UPSTREAM_MAX_FAILS)) { | |
5818
fe8bafab5b49
Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents:
5774
diff
changeset
|
5812 goto not_supported; |
884 | 5813 } |
5814 | |
5815 max_fails = ngx_atoi(&value[i].data[10], value[i].len - 10); | |
5816 | |
5817 if (max_fails == NGX_ERROR) { | |
5818 goto invalid; | |
5819 } | |
5820 | |
5821 continue; | |
663 | 5822 } |
884 | 5823 |
5824 if (ngx_strncmp(value[i].data, "fail_timeout=", 13) == 0) { | |
5825 | |
5826 if (!(uscf->flags & NGX_HTTP_UPSTREAM_FAIL_TIMEOUT)) { | |
5818
fe8bafab5b49
Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents:
5774
diff
changeset
|
5827 goto not_supported; |
884 | 5828 } |
5829 | |
5830 s.len = value[i].len - 13; | |
5831 s.data = &value[i].data[13]; | |
5832 | |
5833 fail_timeout = ngx_parse_time(&s, 1); | |
5834 | |
4474 | 5835 if (fail_timeout == (time_t) NGX_ERROR) { |
884 | 5836 goto invalid; |
5837 } | |
5838 | |
5839 continue; | |
5840 } | |
5841 | |
5410
16b68c724438
Upstream: fixed "down" and "backup" parsing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5392
diff
changeset
|
5842 if (ngx_strcmp(value[i].data, "backup") == 0) { |
1378 | 5843 |
5844 if (!(uscf->flags & NGX_HTTP_UPSTREAM_BACKUP)) { | |
5818
fe8bafab5b49
Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents:
5774
diff
changeset
|
5845 goto not_supported; |
1378 | 5846 } |
5847 | |
5848 us->backup = 1; | |
5849 | |
5850 continue; | |
5851 } | |
5852 | |
5410
16b68c724438
Upstream: fixed "down" and "backup" parsing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5392
diff
changeset
|
5853 if (ngx_strcmp(value[i].data, "down") == 0) { |
884 | 5854 |
5855 if (!(uscf->flags & NGX_HTTP_UPSTREAM_DOWN)) { | |
5818
fe8bafab5b49
Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents:
5774
diff
changeset
|
5856 goto not_supported; |
884 | 5857 } |
5858 | |
5859 us->down = 1; | |
5860 | |
5861 continue; | |
5862 } | |
5863 | |
5864 goto invalid; | |
663 | 5865 } |
5866 | |
5728
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5867 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
|
5868 |
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5869 u.url = value[1]; |
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5870 u.default_port = 80; |
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5871 |
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5872 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
|
5873 if (u.err) { |
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5874 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
|
5875 "%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
|
5876 } |
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5877 |
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5878 return NGX_CONF_ERROR; |
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5879 } |
63d7d69d0fe4
Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
5880 |
5717
efc84a5723b3
Upstream: generic hash module.
Roman Arutyunyan <arut@nginx.com>
parents:
5682
diff
changeset
|
5881 us->name = u.url; |
884 | 5882 us->addrs = u.addrs; |
5883 us->naddrs = u.naddrs; | |
5884 us->weight = weight; | |
6705 | 5885 us->max_conns = max_conns; |
884 | 5886 us->max_fails = max_fails; |
5887 us->fail_timeout = fail_timeout; | |
651 | 5888 |
5889 return NGX_CONF_OK; | |
663 | 5890 |
5891 invalid: | |
5892 | |
884 | 5893 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
5894 "invalid parameter \"%V\"", &value[i]); | |
663 | 5895 |
5896 return NGX_CONF_ERROR; | |
5818
fe8bafab5b49
Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents:
5774
diff
changeset
|
5897 |
fe8bafab5b49
Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents:
5774
diff
changeset
|
5898 not_supported: |
fe8bafab5b49
Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents:
5774
diff
changeset
|
5899 |
fe8bafab5b49
Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents:
5774
diff
changeset
|
5900 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
fe8bafab5b49
Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents:
5774
diff
changeset
|
5901 "balancing method does not support parameter \"%V\"", |
fe8bafab5b49
Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents:
5774
diff
changeset
|
5902 &value[i]); |
fe8bafab5b49
Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents:
5774
diff
changeset
|
5903 |
fe8bafab5b49
Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents:
5774
diff
changeset
|
5904 return NGX_CONF_ERROR; |
651 | 5905 } |
5906 | |
5907 | |
5908 ngx_http_upstream_srv_conf_t * | |
884 | 5909 ngx_http_upstream_add(ngx_conf_t *cf, ngx_url_t *u, ngx_uint_t flags) |
651 | 5910 { |
5911 ngx_uint_t i; | |
884 | 5912 ngx_http_upstream_server_t *us; |
651 | 5913 ngx_http_upstream_srv_conf_t *uscf, **uscfp; |
5914 ngx_http_upstream_main_conf_t *umcf; | |
5915 | |
884 | 5916 if (!(flags & NGX_HTTP_UPSTREAM_CREATE)) { |
5917 | |
1559
fe11e2a3946d
use pool instead of ngx_conf_t
Igor Sysoev <igor@sysoev.ru>
parents:
1558
diff
changeset
|
5918 if (ngx_parse_url(cf->pool, u) != NGX_OK) { |
651 | 5919 if (u->err) { |
5920 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
5921 "%s in upstream \"%V\"", u->err, &u->url); | |
5922 } | |
5923 | |
5924 return NULL; | |
5925 } | |
5926 } | |
5927 | |
5928 umcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_upstream_module); | |
5929 | |
5930 uscfp = umcf->upstreams.elts; | |
5931 | |
5932 for (i = 0; i < umcf->upstreams.nelts; i++) { | |
906 | 5933 |
5934 if (uscfp[i]->host.len != u->host.len | |
884 | 5935 || ngx_strncasecmp(uscfp[i]->host.data, u->host.data, u->host.len) |
5936 != 0) | |
5937 { | |
651 | 5938 continue; |
5939 } | |
5940 | |
884 | 5941 if ((flags & NGX_HTTP_UPSTREAM_CREATE) |
5942 && (uscfp[i]->flags & NGX_HTTP_UPSTREAM_CREATE)) | |
651 | 5943 { |
884 | 5944 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
5945 "duplicate upstream \"%V\"", &u->host); | |
5946 return NULL; | |
651 | 5947 } |
884 | 5948 |
5005
c9059bd5445b
Fixed "proxy_pass" with IP address and no port (ticket #276).
Ruslan Ermilov <ru@nginx.com>
parents:
4990
diff
changeset
|
5949 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
|
5950 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
906 | 5951 "upstream \"%V\" may not have port %d", |
5952 &u->host, u->port); | |
5953 return NULL; | |
5954 } | |
5955 | |
5005
c9059bd5445b
Fixed "proxy_pass" with IP address and no port (ticket #276).
Ruslan Ermilov <ru@nginx.com>
parents:
4990
diff
changeset
|
5956 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
|
5957 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, |
906 | 5958 "upstream \"%V\" may not have port %d in %s:%ui", |
5959 &u->host, uscfp[i]->port, | |
1489
56f1ea5baabb
u_char* is enough to keep file name
Igor Sysoev <igor@sysoev.ru>
parents:
1469
diff
changeset
|
5960 uscfp[i]->file_name, uscfp[i]->line); |
906 | 5961 return NULL; |
5962 } | |
5963 | |
5005
c9059bd5445b
Fixed "proxy_pass" with IP address and no port (ticket #276).
Ruslan Ermilov <ru@nginx.com>
parents:
4990
diff
changeset
|
5964 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
|
5965 && 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
|
5966 { |
906 | 5967 continue; |
884 | 5968 } |
5969 | |
4152
65c1c241d70e
Better handling of late upstream creation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4151
diff
changeset
|
5970 if (flags & NGX_HTTP_UPSTREAM_CREATE) { |
65c1c241d70e
Better handling of late upstream creation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4151
diff
changeset
|
5971 uscfp[i]->flags = flags; |
6787
640e1e778de6
Upstream: consistently initialize explicit upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
6786
diff
changeset
|
5972 uscfp[i]->port = 0; |
4152
65c1c241d70e
Better handling of late upstream creation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4151
diff
changeset
|
5973 } |
65c1c241d70e
Better handling of late upstream creation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4151
diff
changeset
|
5974 |
884 | 5975 return uscfp[i]; |
651 | 5976 } |
5977 | |
5978 uscf = ngx_pcalloc(cf->pool, sizeof(ngx_http_upstream_srv_conf_t)); | |
5979 if (uscf == NULL) { | |
5980 return NULL; | |
5981 } | |
5982 | |
884 | 5983 uscf->flags = flags; |
651 | 5984 uscf->host = u->host; |
1489
56f1ea5baabb
u_char* is enough to keep file name
Igor Sysoev <igor@sysoev.ru>
parents:
1469
diff
changeset
|
5985 uscf->file_name = cf->conf_file->file.name.data; |
651 | 5986 uscf->line = cf->conf_file->line; |
906 | 5987 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
|
5988 uscf->no_port = u->no_port; |
884 | 5989 |
5977
26c127bab5ef
Upstream: detect port absence in fastcgi_pass with IP literal.
Ruslan Ermilov <ru@nginx.com>
parents:
5968
diff
changeset
|
5990 if (u->naddrs == 1 && (u->port || u->family == AF_UNIX)) { |
884 | 5991 uscf->servers = ngx_array_create(cf->pool, 1, |
5992 sizeof(ngx_http_upstream_server_t)); | |
5993 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
|
5994 return NULL; |
884 | 5995 } |
5996 | |
5997 us = ngx_array_push(uscf->servers); | |
5998 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
|
5999 return NULL; |
884 | 6000 } |
6001 | |
6002 ngx_memzero(us, sizeof(ngx_http_upstream_server_t)); | |
6003 | |
6004 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
|
6005 us->naddrs = 1; |
884 | 6006 } |
651 | 6007 |
6008 uscfp = ngx_array_push(&umcf->upstreams); | |
6009 if (uscfp == NULL) { | |
6010 return NULL; | |
6011 } | |
6012 | |
6013 *uscfp = uscf; | |
6014 | |
6015 return uscf; | |
6016 } | |
6017 | |
6018 | |
3271
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3198
diff
changeset
|
6019 char * |
3399 | 6020 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
|
6021 void *conf) |
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3198
diff
changeset
|
6022 { |
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3198
diff
changeset
|
6023 char *p = conf; |
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3198
diff
changeset
|
6024 |
5008
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6025 ngx_int_t rc; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6026 ngx_str_t *value; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6027 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
|
6028 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
|
6029 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
|
6030 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6031 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
|
6032 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6033 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
|
6034 return "is duplicate"; |
3271
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3198
diff
changeset
|
6035 } |
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3198
diff
changeset
|
6036 |
3272
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3271
diff
changeset
|
6037 value = cf->args->elts; |
98f49b2bcae8
change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents:
3271
diff
changeset
|
6038 |
6530
1d0e03db9f8e
Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6528
diff
changeset
|
6039 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
|
6040 *plocal = NULL; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6041 return NGX_CONF_OK; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6042 } |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6043 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6044 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
|
6045 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6046 ccv.cf = cf; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6047 ccv.value = &value[1]; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6048 ccv.complex_value = &cv; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6049 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6050 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
|
6051 return NGX_CONF_ERROR; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6052 } |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6053 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6054 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
|
6055 if (local == NULL) { |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6056 return NGX_CONF_ERROR; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6057 } |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6058 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6059 *plocal = local; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6060 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6061 if (cv.lengths) { |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6062 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
|
6063 if (local->value == NULL) { |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6064 return NGX_CONF_ERROR; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6065 } |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6066 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6067 *local->value = cv; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6068 |
6528
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6069 } else { |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6070 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
|
6071 if (local->addr == NULL) { |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6072 return NGX_CONF_ERROR; |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6073 } |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6074 |
6594
3c87b82b17d4
Upstream: support for port in proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6536
diff
changeset
|
6075 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
|
6076 value[1].len); |
6528
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6077 |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6078 switch (rc) { |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6079 case NGX_OK: |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6080 local->addr->name = value[1]; |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6081 break; |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6082 |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6083 case NGX_DECLINED: |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6084 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
|
6085 "invalid address \"%V\"", &value[1]); |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6086 /* fall through */ |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6087 |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6088 default: |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6089 return NGX_CONF_ERROR; |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6090 } |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6091 } |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6092 |
6530
1d0e03db9f8e
Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6528
diff
changeset
|
6093 if (cf->args->nelts > 2) { |
1d0e03db9f8e
Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6528
diff
changeset
|
6094 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
|
6095 #if (NGX_HAVE_TRANSPARENT_PROXY) |
1d0e03db9f8e
Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6528
diff
changeset
|
6096 local->transparent = 1; |
1d0e03db9f8e
Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6528
diff
changeset
|
6097 #else |
1d0e03db9f8e
Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6528
diff
changeset
|
6098 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
|
6099 "transparent proxying is not supported " |
1d0e03db9f8e
Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6528
diff
changeset
|
6100 "on this platform, ignored"); |
1d0e03db9f8e
Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6528
diff
changeset
|
6101 #endif |
1d0e03db9f8e
Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6528
diff
changeset
|
6102 } else { |
1d0e03db9f8e
Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6528
diff
changeset
|
6103 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
|
6104 "invalid parameter \"%V\"", &value[2]); |
1d0e03db9f8e
Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6528
diff
changeset
|
6105 return NGX_CONF_ERROR; |
1d0e03db9f8e
Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6528
diff
changeset
|
6106 } |
1d0e03db9f8e
Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6528
diff
changeset
|
6107 } |
1d0e03db9f8e
Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6528
diff
changeset
|
6108 |
6528
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6109 return NGX_CONF_OK; |
3271
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3198
diff
changeset
|
6110 } |
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3198
diff
changeset
|
6111 |
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3198
diff
changeset
|
6112 |
6528
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6113 static ngx_int_t |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6114 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
|
6115 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
|
6116 { |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6117 ngx_int_t rc; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6118 ngx_str_t val; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6119 ngx_addr_t *addr; |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6120 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6121 if (local == NULL) { |
6528
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6122 u->peer.local = NULL; |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6123 return NGX_OK; |
5008
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6124 } |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6125 |
6530
1d0e03db9f8e
Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6528
diff
changeset
|
6126 #if (NGX_HAVE_TRANSPARENT_PROXY) |
1d0e03db9f8e
Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6528
diff
changeset
|
6127 u->peer.transparent = local->transparent; |
1d0e03db9f8e
Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6528
diff
changeset
|
6128 #endif |
1d0e03db9f8e
Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6528
diff
changeset
|
6129 |
5008
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6130 if (local->value == NULL) { |
6528
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6131 u->peer.local = local->addr; |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6132 return NGX_OK; |
5008
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6133 } |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6134 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6135 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
|
6136 return NGX_ERROR; |
5008
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6137 } |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6138 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6139 if (val.len == 0) { |
6528
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6140 return NGX_OK; |
5008
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6141 } |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6142 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6143 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
|
6144 if (addr == NULL) { |
6528
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6145 return NGX_ERROR; |
5008
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6146 } |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6147 |
6594
3c87b82b17d4
Upstream: support for port in proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
6536
diff
changeset
|
6148 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
|
6149 if (rc == NGX_ERROR) { |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6150 return NGX_ERROR; |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6151 } |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6152 |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6153 if (rc != NGX_OK) { |
5008
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6154 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
|
6155 "invalid local address \"%V\"", &val); |
6528
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6156 return NGX_OK; |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6157 } |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6158 |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6159 addr->name = val; |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6160 u->peer.local = addr; |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6161 |
88f012eee7d8
Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
6162 return NGX_OK; |
5008
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6163 } |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6164 |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
5005
diff
changeset
|
6165 |
4328
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6166 char * |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6167 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
|
6168 void *conf) |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6169 { |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6170 char *p = conf; |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6171 |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6172 ngx_str_t *value; |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6173 ngx_array_t **a; |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6174 ngx_http_upstream_param_t *param; |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6175 |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6176 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
|
6177 |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6178 if (*a == NULL) { |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6179 *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
|
6180 if (*a == NULL) { |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6181 return NGX_CONF_ERROR; |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6182 } |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6183 } |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6184 |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6185 param = ngx_array_push(*a); |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6186 if (param == NULL) { |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6187 return NGX_CONF_ERROR; |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6188 } |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6189 |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6190 value = cf->args->elts; |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6191 |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6192 param->key = value[1]; |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6193 param->value = value[2]; |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6194 param->skip_empty = 0; |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6195 |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6196 if (cf->args->nelts == 4) { |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6197 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
|
6198 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
|
6199 "invalid parameter \"%V\"", &value[3]); |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6200 return NGX_CONF_ERROR; |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6201 } |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6202 |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6203 param->skip_empty = 1; |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6204 } |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6205 |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6206 return NGX_CONF_OK; |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6207 } |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6208 |
d15a00e6d9e6
Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents:
4298
diff
changeset
|
6209 |
1701
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6210 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
|
6211 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
|
6212 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
|
6213 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
|
6214 { |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6215 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
|
6216 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
|
6217 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
|
6218 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
|
6219 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6220 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
|
6221 && 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
|
6222 { |
4769
f88555d76886
Upstream: hide_headers/pass_headers inheritance fix.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4766
diff
changeset
|
6223 conf->hide_headers = prev->hide_headers; |
f88555d76886
Upstream: hide_headers/pass_headers inheritance fix.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4766
diff
changeset
|
6224 conf->pass_headers = prev->pass_headers; |
f88555d76886
Upstream: hide_headers/pass_headers inheritance fix.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4766
diff
changeset
|
6225 |
1701
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6226 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
|
6227 |
6744
7e5199f172fb
Upstream: hide_headers_hash inherited regardless of cache settings.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6705
diff
changeset
|
6228 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
|
6229 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
|
6230 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6231 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6232 } else { |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6233 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
|
6234 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
|
6235 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6236 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6237 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
|
6238 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
|
6239 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6240 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6241 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6242 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
|
6243 != NGX_OK) |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6244 { |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6245 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
|
6246 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6247 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6248 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
|
6249 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
|
6250 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
|
6251 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
|
6252 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6253 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6254 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
|
6255 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
|
6256 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
|
6257 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6258 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6259 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
|
6260 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6261 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
|
6262 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6263 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
|
6264 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6265 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
|
6266 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6267 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
|
6268 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
|
6269 goto exist; |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6270 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6271 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6272 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6273 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
|
6274 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
|
6275 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
|
6276 } |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6277 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6278 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
|
6279 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
|
6280 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
|
6281 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6282 exist: |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6283 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6284 continue; |
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 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6288 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
|
6289 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6290 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
|
6291 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
|
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 (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
|
6294 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
|
6295 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6296 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
|
6297 continue; |
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 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
6300 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
|
6301 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
|
6302 break; |
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 } |
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 } |
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 hash->hash = &conf->hide_headers_hash; |
1706
9242e21d2f8d
style fix: remove trailing spaces
Igor Sysoev <igor@sysoev.ru>
parents:
1705
diff
changeset
|
6309 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
|
6310 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
|
6311 hash->temp_pool = NULL; |
1706
9242e21d2f8d
style fix: remove trailing spaces
Igor Sysoev <igor@sysoev.ru>
parents:
1705
diff
changeset
|
6312 |
6745
93121485c39b
Upstream: hide_headers_hash handling at http level.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6744
diff
changeset
|
6313 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
|
6314 return NGX_ERROR; |
93121485c39b
Upstream: hide_headers_hash handling at http level.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6744
diff
changeset
|
6315 } |
93121485c39b
Upstream: hide_headers_hash handling at http level.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6744
diff
changeset
|
6316 |
93121485c39b
Upstream: hide_headers_hash handling at http level.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6744
diff
changeset
|
6317 /* |
93121485c39b
Upstream: hide_headers_hash handling at http level.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6744
diff
changeset
|
6318 * 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
|
6319 * 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
|
6320 */ |
93121485c39b
Upstream: hide_headers_hash handling at http level.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6744
diff
changeset
|
6321 |
93121485c39b
Upstream: hide_headers_hash handling at http level.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6744
diff
changeset
|
6322 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
|
6323 && conf->hide_headers == prev->hide_headers |
93121485c39b
Upstream: hide_headers_hash handling at http level.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6744
diff
changeset
|
6324 && conf->pass_headers == prev->pass_headers) |
93121485c39b
Upstream: hide_headers_hash handling at http level.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6744
diff
changeset
|
6325 { |
93121485c39b
Upstream: hide_headers_hash handling at http level.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6744
diff
changeset
|
6326 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
|
6327 } |
93121485c39b
Upstream: hide_headers_hash handling at http level.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6744
diff
changeset
|
6328 |
93121485c39b
Upstream: hide_headers_hash handling at http level.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6744
diff
changeset
|
6329 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
|
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 |
509 | 6333 static void * |
6334 ngx_http_upstream_create_main_conf(ngx_conf_t *cf) | |
6335 { | |
6336 ngx_http_upstream_main_conf_t *umcf; | |
6337 | |
6338 umcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_upstream_main_conf_t)); | |
6339 if (umcf == NULL) { | |
6340 return NULL; | |
6341 } | |
6342 | |
651 | 6343 if (ngx_array_init(&umcf->upstreams, cf->pool, 4, |
6344 sizeof(ngx_http_upstream_srv_conf_t *)) | |
6345 != NGX_OK) | |
6346 { | |
2912
c7d57b539248
return NULL instead of NGX_CONF_ERROR on a create conf failure
Igor Sysoev <igor@sysoev.ru>
parents:
2882
diff
changeset
|
6347 return NULL; |
651 | 6348 } |
6349 | |
509 | 6350 return umcf; |
6351 } | |
6352 | |
6353 | |
6354 static char * | |
651 | 6355 ngx_http_upstream_init_main_conf(ngx_conf_t *cf, void *conf) |
509 | 6356 { |
6357 ngx_http_upstream_main_conf_t *umcf = conf; | |
6358 | |
651 | 6359 ngx_uint_t i; |
6360 ngx_array_t headers_in; | |
6361 ngx_hash_key_t *hk; | |
6362 ngx_hash_init_t hash; | |
884 | 6363 ngx_http_upstream_init_pt init; |
651 | 6364 ngx_http_upstream_header_t *header; |
6365 ngx_http_upstream_srv_conf_t **uscfp; | |
6366 | |
6367 uscfp = umcf->upstreams.elts; | |
6368 | |
6369 for (i = 0; i < umcf->upstreams.nelts; i++) { | |
884 | 6370 |
6371 init = uscfp[i]->peer.init_upstream ? uscfp[i]->peer.init_upstream: | |
6372 ngx_http_upstream_init_round_robin; | |
6373 | |
6374 if (init(cf, uscfp[i]) != NGX_OK) { | |
651 | 6375 return NGX_CONF_ERROR; |
6376 } | |
6377 } | |
649 | 6378 |
663 | 6379 |
884 | 6380 /* upstream_headers_in_hash */ |
6381 | |
649 | 6382 if (ngx_array_init(&headers_in, cf->temp_pool, 32, sizeof(ngx_hash_key_t)) |
6383 != NGX_OK) | |
509 | 6384 { |
6385 return NGX_CONF_ERROR; | |
6386 } | |
6387 | |
649 | 6388 for (header = ngx_http_upstream_headers_in; header->name.len; header++) { |
6389 hk = ngx_array_push(&headers_in); | |
6390 if (hk == NULL) { | |
6391 return NGX_CONF_ERROR; | |
6392 } | |
6393 | |
6394 hk->key = header->name; | |
6395 hk->key_hash = ngx_hash_key_lc(header->name.data, header->name.len); | |
6396 hk->value = header; | |
6397 } | |
6398 | |
6399 hash.hash = &umcf->headers_in_hash; | |
6400 hash.key = ngx_hash_key_lc; | |
6401 hash.max_size = 512; | |
751
bae59a740c40
align hash bucket size to cache line
Igor Sysoev <igor@sysoev.ru>
parents:
750
diff
changeset
|
6402 hash.bucket_size = ngx_align(64, ngx_cacheline_size); |
649 | 6403 hash.name = "upstream_headers_in_hash"; |
6404 hash.pool = cf->pool; | |
6405 hash.temp_pool = NULL; | |
6406 | |
6407 if (ngx_hash_init(&hash, headers_in.elts, headers_in.nelts) != NGX_OK) { | |
6408 return NGX_CONF_ERROR; | |
6409 } | |
509 | 6410 |
6411 return NGX_CONF_OK; | |
6412 } |