annotate src/http/ngx_http_upstream.c @ 9270:3d455e37abf8 default tip

Core: PID file writing synchronization. Now, ngx_daemon() does not call exit() in the parent process immediately, but instead waits for the child process to signal it actually started (and wrote the PID file if configured to). This ensures that the PID file already exists when the parent process exits. To make sure that signal handlers won't cause unexpected logging in the parent process if the child process dies (for example, due to errors when writing the PID file), ngx_init_signals() is moved to the child process. This resolves "PID file ... not readable (yet?) after start" and "Failed to parse PID from file..." errors as observed with systemd. Note that the errors observed are considered to be a bug in systemd, which isn't able to work properly with traditional Unix daemons. Still, the workaround is implemented to make sure there will be no OS vendor patches trying to address this.
author Maxim Dounin <mdounin@mdounin.ru>
date Mon, 13 May 2024 06:13:22 +0300
parents 208a4adb82ef
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2 /*
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3 * Copyright (C) Igor Sysoev
4412
d620f497c50f Copyright updated.
Maxim Konovalov <maxim@nginx.com>
parents: 4385
diff changeset
4 * Copyright (C) Nginx, Inc.
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
5 */
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
6
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
7
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
8 #include <ngx_config.h>
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
9 #include <ngx_core.h>
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
10 #include <ngx_http.h>
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
11
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
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
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2949
diff changeset
24 static ngx_int_t ngx_http_upstream_cache_status(ngx_http_request_t *r,
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2949
diff changeset
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
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
33 static void ngx_http_upstream_resolve_handler(ngx_resolver_ctx_t *ctx);
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
34 static void ngx_http_upstream_rd_check_broken_connection(ngx_http_request_t *r);
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
35 static void ngx_http_upstream_wr_check_broken_connection(ngx_http_request_t *r);
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
36 static void ngx_http_upstream_check_broken_connection(ngx_http_request_t *r,
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
37 ngx_event_t *ev);
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
38 static void ngx_http_upstream_connect(ngx_http_request_t *r,
487
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 485
diff changeset
39 ngx_http_upstream_t *u);
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
40 static ngx_int_t ngx_http_upstream_reinit(ngx_http_request_t *r,
487
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 485
diff changeset
41 ngx_http_upstream_t *u);
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
42 static void ngx_http_upstream_send_request(ngx_http_request_t *r,
6050
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
43 ngx_http_upstream_t *u, ngx_uint_t do_write);
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
44 static ngx_int_t ngx_http_upstream_send_request_body(ngx_http_request_t *r,
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
45 ngx_http_upstream_t *u, ngx_uint_t do_write);
2386
4ccaa42de633 use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents: 2381
diff changeset
46 static void ngx_http_upstream_send_request_handler(ngx_http_request_t *r,
4ccaa42de633 use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents: 2381
diff changeset
47 ngx_http_upstream_t *u);
6050
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
48 static void ngx_http_upstream_read_request_handler(ngx_http_request_t *r);
2386
4ccaa42de633 use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents: 2381
diff changeset
49 static void ngx_http_upstream_process_header(ngx_http_request_t *r,
4ccaa42de633 use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents: 2381
diff changeset
50 ngx_http_upstream_t *u);
2268
33556140681a *) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents: 2267
diff changeset
51 static ngx_int_t ngx_http_upstream_test_next(ngx_http_request_t *r,
33556140681a *) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents: 2267
diff changeset
52 ngx_http_upstream_t *u);
2267
920be89a3d2d ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents: 2244
diff changeset
53 static ngx_int_t ngx_http_upstream_intercept_errors(ngx_http_request_t *r,
920be89a3d2d ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents: 2244
diff changeset
54 ngx_http_upstream_t *u);
1153
c843f3df3b85 separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents: 1143
diff changeset
55 static ngx_int_t ngx_http_upstream_test_connect(ngx_connection_t *c);
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
56 static ngx_int_t ngx_http_upstream_process_headers(ngx_http_request_t *r,
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
57 ngx_http_upstream_t *u);
7230
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
58 static ngx_int_t ngx_http_upstream_process_trailers(ngx_http_request_t *r,
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
59 ngx_http_upstream_t *u);
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
60 static void ngx_http_upstream_send_response(ngx_http_request_t *r,
487
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 485
diff changeset
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
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
72 static void
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
73 ngx_http_upstream_process_non_buffered_downstream(ngx_http_request_t *r);
2386
4ccaa42de633 use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents: 2381
diff changeset
74 static void
4ccaa42de633 use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents: 2381
diff changeset
75 ngx_http_upstream_process_non_buffered_upstream(ngx_http_request_t *r,
4ccaa42de633 use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents: 2381
diff changeset
76 ngx_http_upstream_t *u);
2381
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
77 static void
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
78 ngx_http_upstream_process_non_buffered_request(ngx_http_request_t *r,
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
79 ngx_uint_t do_write);
6443
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
80 #if (NGX_THREADS)
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
81 static ngx_int_t ngx_http_upstream_thread_handler(ngx_thread_task_t *task,
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
82 ngx_file_t *file);
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
83 static void ngx_http_upstream_thread_event_handler(ngx_event_t *ev);
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
84 #endif
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
85 static ngx_int_t ngx_http_upstream_output_filter(void *data,
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
86 ngx_chain_t *chain);
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
87 static void ngx_http_upstream_process_downstream(ngx_http_request_t *r);
2386
4ccaa42de633 use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents: 2381
diff changeset
88 static void ngx_http_upstream_process_upstream(ngx_http_request_t *r,
4ccaa42de633 use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents: 2381
diff changeset
89 ngx_http_upstream_t *u);
5995
5f179f344096 Upstream: upstream argument in ngx_http_upstream_process_request().
Maxim Dounin <mdounin@mdounin.ru>
parents: 5994
diff changeset
90 static void ngx_http_upstream_process_request(ngx_http_request_t *r,
5f179f344096 Upstream: upstream argument in ngx_http_upstream_process_request().
Maxim Dounin <mdounin@mdounin.ru>
parents: 5994
diff changeset
91 ngx_http_upstream_t *u);
1291
13a4ce6e7f1e proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents: 1284
diff changeset
92 static void ngx_http_upstream_store(ngx_http_request_t *r,
13a4ce6e7f1e proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents: 1284
diff changeset
93 ngx_http_upstream_t *u);
2386
4ccaa42de633 use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents: 2381
diff changeset
94 static void ngx_http_upstream_dummy_handler(ngx_http_request_t *r,
4ccaa42de633 use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents: 2381
diff changeset
95 ngx_http_upstream_t *u);
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
96 static void ngx_http_upstream_next(ngx_http_request_t *r,
487
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 485
diff changeset
97 ngx_http_upstream_t *u, ngx_uint_t ft_type);
569
174f1e853e1e nginx-0.3.6-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 563
diff changeset
98 static void ngx_http_upstream_cleanup(void *data);
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
99 static void ngx_http_upstream_finalize_request(ngx_http_request_t *r,
487
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 485
diff changeset
100 ngx_http_upstream_t *u, ngx_int_t rc);
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
101
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
102 static ngx_int_t ngx_http_upstream_process_header_line(ngx_http_request_t *r,
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
103 ngx_table_elt_t *h, ngx_uint_t offset);
8034
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
104 static ngx_int_t
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
105 ngx_http_upstream_process_multi_header_lines(ngx_http_request_t *r,
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
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
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
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
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
115 ngx_table_elt_t *h, ngx_uint_t offset);
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
116 static ngx_int_t ngx_http_upstream_ignore_header_line(ngx_http_request_t *r,
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
117 ngx_table_elt_t *h, ngx_uint_t offset);
2666
81556a9b6488 support Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2665
diff changeset
118 static ngx_int_t ngx_http_upstream_process_expires(ngx_http_request_t *r,
81556a9b6488 support Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2665
diff changeset
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
7fa11e5c6e96 nginx-0.1.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 525
diff changeset
122 static ngx_int_t ngx_http_upstream_process_limit_rate(ngx_http_request_t *r,
7fa11e5c6e96 nginx-0.1.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 525
diff changeset
123 ngx_table_elt_t *h, ngx_uint_t offset);
649
1e720b0be7ec nginx-0.3.46-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 641
diff changeset
124 static ngx_int_t ngx_http_upstream_process_buffering(ngx_http_request_t *r,
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
125 ngx_table_elt_t *h, ngx_uint_t offset);
657
400711951595 nginx-0.3.50-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 653
diff changeset
126 static ngx_int_t ngx_http_upstream_process_charset(ngx_http_request_t *r,
400711951595 nginx-0.3.50-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 653
diff changeset
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
1e720b0be7ec nginx-0.3.46-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 641
diff changeset
135 static ngx_int_t ngx_http_upstream_copy_header_line(ngx_http_request_t *r,
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
136 ngx_table_elt_t *h, ngx_uint_t offset);
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
137 static ngx_int_t
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
138 ngx_http_upstream_copy_multi_header_lines(ngx_http_request_t *r,
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
139 ngx_table_elt_t *h, ngx_uint_t offset);
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
140 static ngx_int_t ngx_http_upstream_copy_content_type(ngx_http_request_t *r,
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
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
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
144 static ngx_int_t ngx_http_upstream_rewrite_location(ngx_http_request_t *r,
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
145 ngx_table_elt_t *h, ngx_uint_t offset);
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
146 static ngx_int_t ngx_http_upstream_rewrite_refresh(ngx_http_request_t *r,
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
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
573
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
153 static ngx_int_t ngx_http_upstream_add_variables(ngx_conf_t *cf);
1181
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
154 static ngx_int_t ngx_http_upstream_addr_variable(ngx_http_request_t *r,
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
155 ngx_http_variable_value_t *v, uintptr_t data);
573
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
156 static ngx_int_t ngx_http_upstream_status_variable(ngx_http_request_t *r,
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
157 ngx_http_variable_value_t *v, uintptr_t data);
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
158 static ngx_int_t ngx_http_upstream_response_time_variable(ngx_http_request_t *r,
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
159 ngx_http_variable_value_t *v, uintptr_t data);
2402
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
160 static ngx_int_t ngx_http_upstream_response_length_variable(
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
161 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
162 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
163 ngx_http_variable_value_t *v, uintptr_t data);
7230
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
164 static ngx_int_t ngx_http_upstream_trailer_variable(ngx_http_request_t *r,
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
165 ngx_http_variable_value_t *v, uintptr_t data);
6899
d2b2ff157da5 Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6876
diff changeset
166 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
167 ngx_http_variable_value_t *v, uintptr_t data);
573
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
168
651
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
169 static char *ngx_http_upstream(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy);
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
170 static char *ngx_http_upstream_server(ngx_conf_t *cf, ngx_command_t *cmd,
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
171 void *conf);
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
172
6528
88f012eee7d8 Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents: 6474
diff changeset
173 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
174 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
175
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
176 static void *ngx_http_upstream_create_main_conf(ngx_conf_t *cf);
651
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
177 static char *ngx_http_upstream_init_main_conf(ngx_conf_t *cf, void *conf);
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
178
577
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
179 #if (NGX_HTTP_SSL)
591
8c0cdd81580e nginx-0.3.17-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 589
diff changeset
180 static void ngx_http_upstream_ssl_init_connection(ngx_http_request_t *,
8c0cdd81580e nginx-0.3.17-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 589
diff changeset
181 ngx_http_upstream_t *u, ngx_connection_t *c);
7042
bd2f97a3aecc Upstream: introduced ngx_http_upstream_ssl_handshake_handler().
Maxim Dounin <mdounin@mdounin.ru>
parents: 7041
diff changeset
182 static void ngx_http_upstream_ssl_handshake_handler(ngx_connection_t *c);
bd2f97a3aecc Upstream: introduced ngx_http_upstream_ssl_handshake_handler().
Maxim Dounin <mdounin@mdounin.ru>
parents: 7041
diff changeset
183 static void ngx_http_upstream_ssl_handshake(ngx_http_request_t *,
bd2f97a3aecc Upstream: introduced ngx_http_upstream_ssl_handshake_handler().
Maxim Dounin <mdounin@mdounin.ru>
parents: 7041
diff changeset
184 ngx_http_upstream_t *u, ngx_connection_t *c);
7320
696df3ac27ac SSL: save sessions for upstream peers using a callback function.
Sergey Kandaurov <pluknet@nginx.com>
parents: 7307
diff changeset
185 static void ngx_http_upstream_ssl_save_session(ngx_connection_t *c);
5660
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
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);
7833
3ab8e1e2f0f7 Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7811
diff changeset
188 static ngx_int_t ngx_http_upstream_ssl_certificate(ngx_http_request_t *r,
3ab8e1e2f0f7 Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7811
diff changeset
189 ngx_http_upstream_t *u, ngx_connection_t *c);
577
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
190 #endif
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
191
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
192
6922
a72886067bbb Added missing static specifiers.
Eran Kornblau <erankor@gmail.com>
parents: 6909
diff changeset
193 static ngx_http_upstream_header_t ngx_http_upstream_headers_in[] = {
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
194
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
195 { ngx_string("Status"),
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
196 ngx_http_upstream_process_header_line,
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
197 offsetof(ngx_http_upstream_headers_in_t, status),
649
1e720b0be7ec nginx-0.3.46-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 641
diff changeset
198 ngx_http_upstream_copy_header_line, 0, 0 },
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
199
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
200 { ngx_string("Content-Type"),
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
201 ngx_http_upstream_process_header_line,
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
202 offsetof(ngx_http_upstream_headers_in_t, content_type),
673
b80f94fa2197 nginx-0.3.58-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 671
diff changeset
203 ngx_http_upstream_copy_content_type, 0, 1 },
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
204
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
205 { ngx_string("Content-Length"),
5731
02674312be45 Upstream: removed unused offset to content_length.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5730
diff changeset
206 ngx_http_upstream_process_content_length, 0,
4117
103b0d9afe07 Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4116
diff changeset
207 ngx_http_upstream_ignore_header_line, 0, 0 },
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
208
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
209 { ngx_string("Date"),
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
210 ngx_http_upstream_process_header_line,
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
211 offsetof(ngx_http_upstream_headers_in_t, date),
649
1e720b0be7ec nginx-0.3.46-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 641
diff changeset
212 ngx_http_upstream_copy_header_line,
1e720b0be7ec nginx-0.3.46-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 641
diff changeset
213 offsetof(ngx_http_headers_out_t, date), 0 },
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
214
1291
13a4ce6e7f1e proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents: 1284
diff changeset
215 { ngx_string("Last-Modified"),
5732
d0ce06cb9be1 Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5731
diff changeset
216 ngx_http_upstream_process_last_modified, 0,
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
217 ngx_http_upstream_copy_last_modified, 0, 0 },
1291
13a4ce6e7f1e proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents: 1284
diff changeset
218
3037
0278f13b04c5 process upstream ETag header
Igor Sysoev <igor@sysoev.ru>
parents: 3032
diff changeset
219 { ngx_string("ETag"),
0278f13b04c5 process upstream ETag header
Igor Sysoev <igor@sysoev.ru>
parents: 3032
diff changeset
220 ngx_http_upstream_process_header_line,
0278f13b04c5 process upstream ETag header
Igor Sysoev <igor@sysoev.ru>
parents: 3032
diff changeset
221 offsetof(ngx_http_upstream_headers_in_t, etag),
0278f13b04c5 process upstream ETag header
Igor Sysoev <igor@sysoev.ru>
parents: 3032
diff changeset
222 ngx_http_upstream_copy_header_line,
0278f13b04c5 process upstream ETag header
Igor Sysoev <igor@sysoev.ru>
parents: 3032
diff changeset
223 offsetof(ngx_http_headers_out_t, etag), 0 },
0278f13b04c5 process upstream ETag header
Igor Sysoev <igor@sysoev.ru>
parents: 3032
diff changeset
224
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
225 { ngx_string("Server"),
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
226 ngx_http_upstream_process_header_line,
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
227 offsetof(ngx_http_upstream_headers_in_t, server),
649
1e720b0be7ec nginx-0.3.46-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 641
diff changeset
228 ngx_http_upstream_copy_header_line,
1e720b0be7ec nginx-0.3.46-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 641
diff changeset
229 offsetof(ngx_http_headers_out_t, server), 0 },
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
230
529
e5d7d0334fdb nginx-0.1.39-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 527
diff changeset
231 { ngx_string("WWW-Authenticate"),
8034
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
232 ngx_http_upstream_process_multi_header_lines,
529
e5d7d0334fdb nginx-0.1.39-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 527
diff changeset
233 offsetof(ngx_http_upstream_headers_in_t, www_authenticate),
e5d7d0334fdb nginx-0.1.39-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 527
diff changeset
234 ngx_http_upstream_copy_header_line, 0, 0 },
e5d7d0334fdb nginx-0.1.39-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 527
diff changeset
235
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
236 { ngx_string("Location"),
2140
dce5ddef5af9 if upstream sent a location header without status use 302
Igor Sysoev <igor@sysoev.ru>
parents: 2049
diff changeset
237 ngx_http_upstream_process_header_line,
dce5ddef5af9 if upstream sent a location header without status use 302
Igor Sysoev <igor@sysoev.ru>
parents: 2049
diff changeset
238 offsetof(ngx_http_upstream_headers_in_t, location),
515
417a087c9c4d nginx-0.1.32-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 511
diff changeset
239 ngx_http_upstream_rewrite_location, 0, 0 },
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
240
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
241 { ngx_string("Refresh"),
8034
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
242 ngx_http_upstream_process_header_line,
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
243 offsetof(ngx_http_upstream_headers_in_t, refresh),
515
417a087c9c4d nginx-0.1.32-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 511
diff changeset
244 ngx_http_upstream_rewrite_refresh, 0, 0 },
417a087c9c4d nginx-0.1.32-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 511
diff changeset
245
417a087c9c4d nginx-0.1.32-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 511
diff changeset
246 { ngx_string("Set-Cookie"),
5677
3a48775f1535 Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents: 5667
diff changeset
247 ngx_http_upstream_process_set_cookie,
8024
ef6a3a99a81a Reworked multi headers to use linked lists.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8023
diff changeset
248 offsetof(ngx_http_upstream_headers_in_t, set_cookie),
4464
7bf3b68239a3 Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents: 4460
diff changeset
249 ngx_http_upstream_rewrite_set_cookie, 0, 1 },
531
c3bd8cdabb8f nginx-0.1.40-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
250
c3bd8cdabb8f nginx-0.1.40-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
251 { ngx_string("Content-Disposition"),
c3bd8cdabb8f nginx-0.1.40-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
252 ngx_http_upstream_ignore_header_line, 0,
c3bd8cdabb8f nginx-0.1.40-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
253 ngx_http_upstream_copy_header_line, 0, 1 },
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
254
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
255 { 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
256 ngx_http_upstream_process_cache_control, 0,
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
257 ngx_http_upstream_copy_multi_header_lines,
515
417a087c9c4d nginx-0.1.32-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 511
diff changeset
258 offsetof(ngx_http_headers_out_t, cache_control), 1 },
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
259
573
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
260 { ngx_string("Expires"),
2666
81556a9b6488 support Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2665
diff changeset
261 ngx_http_upstream_process_expires, 0,
573
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
262 ngx_http_upstream_copy_header_line,
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
263 offsetof(ngx_http_headers_out_t, expires), 1 },
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
264
577
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
265 { ngx_string("Accept-Ranges"),
8030
cdc2724858ca Upstream: simplified Accept-Ranges handling.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8029
diff changeset
266 ngx_http_upstream_ignore_header_line, 0,
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
267 ngx_http_upstream_copy_allow_ranges,
577
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
268 offsetof(ngx_http_headers_out_t, accept_ranges), 1 },
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
269
6316
f44de0d12143 Upstream: fill r->headers_out.content_range from upstream response.
Roman Arutyunyan <arut@nginx.com>
parents: 6313
diff changeset
270 { ngx_string("Content-Range"),
f44de0d12143 Upstream: fill r->headers_out.content_range from upstream response.
Roman Arutyunyan <arut@nginx.com>
parents: 6313
diff changeset
271 ngx_http_upstream_ignore_header_line, 0,
f44de0d12143 Upstream: fill r->headers_out.content_range from upstream response.
Roman Arutyunyan <arut@nginx.com>
parents: 6313
diff changeset
272 ngx_http_upstream_copy_header_line,
f44de0d12143 Upstream: fill r->headers_out.content_range from upstream response.
Roman Arutyunyan <arut@nginx.com>
parents: 6313
diff changeset
273 offsetof(ngx_http_headers_out_t, content_range), 0 },
f44de0d12143 Upstream: fill r->headers_out.content_range from upstream response.
Roman Arutyunyan <arut@nginx.com>
parents: 6313
diff changeset
274
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
275 { ngx_string("Connection"),
4124
0c30976f5bfa Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4123
diff changeset
276 ngx_http_upstream_process_connection, 0,
515
417a087c9c4d nginx-0.1.32-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 511
diff changeset
277 ngx_http_upstream_ignore_header_line, 0, 0 },
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
278
641
5e8fb59c18c1 nginx-0.3.42-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 637
diff changeset
279 { ngx_string("Keep-Alive"),
5e8fb59c18c1 nginx-0.3.42-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 637
diff changeset
280 ngx_http_upstream_ignore_header_line, 0,
5e8fb59c18c1 nginx-0.3.42-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 637
diff changeset
281 ngx_http_upstream_ignore_header_line, 0, 0 },
5e8fb59c18c1 nginx-0.3.42-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 637
diff changeset
282
5877
60fde1bc7236 Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5874
diff changeset
283 { ngx_string("Vary"),
60fde1bc7236 Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5874
diff changeset
284 ngx_http_upstream_process_vary, 0,
60fde1bc7236 Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5874
diff changeset
285 ngx_http_upstream_copy_header_line, 0, 0 },
60fde1bc7236 Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5874
diff changeset
286
7199
6ba68ad8b24c Basic support of the Link response header.
Ruslan Ermilov <ru@nginx.com>
parents: 7194
diff changeset
287 { ngx_string("Link"),
6ba68ad8b24c Basic support of the Link response header.
Ruslan Ermilov <ru@nginx.com>
parents: 7194
diff changeset
288 ngx_http_upstream_ignore_header_line, 0,
6ba68ad8b24c Basic support of the Link response header.
Ruslan Ermilov <ru@nginx.com>
parents: 7194
diff changeset
289 ngx_http_upstream_copy_multi_header_lines,
6ba68ad8b24c Basic support of the Link response header.
Ruslan Ermilov <ru@nginx.com>
parents: 7194
diff changeset
290 offsetof(ngx_http_headers_out_t, link), 0 },
6ba68ad8b24c Basic support of the Link response header.
Ruslan Ermilov <ru@nginx.com>
parents: 7194
diff changeset
291
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
292 { ngx_string("X-Accel-Expires"),
2664
f903114355d4 zero field
Igor Sysoev <igor@sysoev.ru>
parents: 2663
diff changeset
293 ngx_http_upstream_process_accel_expires, 0,
649
1e720b0be7ec nginx-0.3.46-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 641
diff changeset
294 ngx_http_upstream_copy_header_line, 0, 0 },
515
417a087c9c4d nginx-0.1.32-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 511
diff changeset
295
417a087c9c4d nginx-0.1.32-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 511
diff changeset
296 { ngx_string("X-Accel-Redirect"),
417a087c9c4d nginx-0.1.32-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 511
diff changeset
297 ngx_http_upstream_process_header_line,
417a087c9c4d nginx-0.1.32-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 511
diff changeset
298 offsetof(ngx_http_upstream_headers_in_t, x_accel_redirect),
3003
b630e7d095b3 allow to proxy_pass_header/fastcgi_pass_header "X-Accel-Redirect",
Igor Sysoev <igor@sysoev.ru>
parents: 2971
diff changeset
299 ngx_http_upstream_copy_header_line, 0, 0 },
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
300
527
7fa11e5c6e96 nginx-0.1.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 525
diff changeset
301 { ngx_string("X-Accel-Limit-Rate"),
7fa11e5c6e96 nginx-0.1.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 525
diff changeset
302 ngx_http_upstream_process_limit_rate, 0,
3003
b630e7d095b3 allow to proxy_pass_header/fastcgi_pass_header "X-Accel-Redirect",
Igor Sysoev <igor@sysoev.ru>
parents: 2971
diff changeset
303 ngx_http_upstream_copy_header_line, 0, 0 },
527
7fa11e5c6e96 nginx-0.1.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 525
diff changeset
304
649
1e720b0be7ec nginx-0.3.46-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 641
diff changeset
305 { ngx_string("X-Accel-Buffering"),
1e720b0be7ec nginx-0.3.46-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 641
diff changeset
306 ngx_http_upstream_process_buffering, 0,
3003
b630e7d095b3 allow to proxy_pass_header/fastcgi_pass_header "X-Accel-Redirect",
Igor Sysoev <igor@sysoev.ru>
parents: 2971
diff changeset
307 ngx_http_upstream_copy_header_line, 0, 0 },
649
1e720b0be7ec nginx-0.3.46-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 641
diff changeset
308
657
400711951595 nginx-0.3.50-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 653
diff changeset
309 { ngx_string("X-Accel-Charset"),
400711951595 nginx-0.3.50-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 653
diff changeset
310 ngx_http_upstream_process_charset, 0,
3003
b630e7d095b3 allow to proxy_pass_header/fastcgi_pass_header "X-Accel-Redirect",
Igor Sysoev <igor@sysoev.ru>
parents: 2971
diff changeset
311 ngx_http_upstream_copy_header_line, 0, 0 },
657
400711951595 nginx-0.3.50-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 653
diff changeset
312
4123
0ee350b5177c Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4120
diff changeset
313 { ngx_string("Transfer-Encoding"),
0ee350b5177c Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4120
diff changeset
314 ngx_http_upstream_process_transfer_encoding, 0,
0ee350b5177c Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4120
diff changeset
315 ngx_http_upstream_ignore_header_line, 0, 0 },
0ee350b5177c Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4120
diff changeset
316
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
317 { ngx_string("Content-Encoding"),
8029
e0027c8438b0 Upstream: simplified Content-Encoding handling.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8028
diff changeset
318 ngx_http_upstream_ignore_header_line, 0,
e0027c8438b0 Upstream: simplified Content-Encoding handling.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8028
diff changeset
319 ngx_http_upstream_copy_header_line,
e0027c8438b0 Upstream: simplified Content-Encoding handling.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8028
diff changeset
320 offsetof(ngx_http_headers_out_t, content_encoding), 0 },
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
321
515
417a087c9c4d nginx-0.1.32-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 511
diff changeset
322 { ngx_null_string, NULL, 0, NULL, 0, 0 }
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
323 };
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
324
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
325
651
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
326 static ngx_command_t ngx_http_upstream_commands[] = {
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
327
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
328 { ngx_string("upstream"),
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
329 NGX_HTTP_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_TAKE1,
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
330 ngx_http_upstream,
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
331 0,
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
332 0,
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
333 NULL },
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
334
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
335 { ngx_string("server"),
884
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
336 NGX_HTTP_UPS_CONF|NGX_CONF_1MORE,
651
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
337 ngx_http_upstream_server,
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
338 NGX_HTTP_SRV_CONF_OFFSET,
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
339 0,
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
340 NULL },
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
341
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
342 ngx_null_command
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
343 };
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
344
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
345
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
346 static ngx_http_module_t ngx_http_upstream_module_ctx = {
573
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
347 ngx_http_upstream_add_variables, /* preconfiguration */
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
348 NULL, /* postconfiguration */
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
349
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
350 ngx_http_upstream_create_main_conf, /* create main configuration */
651
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
351 ngx_http_upstream_init_main_conf, /* init main configuration */
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
352
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
353 NULL, /* create server configuration */
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
354 NULL, /* merge server configuration */
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
355
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
356 NULL, /* create location configuration */
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
357 NULL /* merge location configuration */
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
358 };
577
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
359
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
360
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
361 ngx_module_t ngx_http_upstream_module = {
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
362 NGX_MODULE_V1,
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
363 &ngx_http_upstream_module_ctx, /* module context */
651
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
364 ngx_http_upstream_commands, /* module directives */
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
365 NGX_HTTP_MODULE, /* module type */
541
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 537
diff changeset
366 NULL, /* init master */
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
367 NULL, /* init module */
541
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 537
diff changeset
368 NULL, /* init process */
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 537
diff changeset
369 NULL, /* init thread */
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 537
diff changeset
370 NULL, /* exit thread */
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 537
diff changeset
371 NULL, /* exit process */
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 537
diff changeset
372 NULL, /* exit master */
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 537
diff changeset
373 NGX_MODULE_V1_PADDING
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
374 };
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
375
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
376
573
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
377 static ngx_http_variable_t ngx_http_upstream_vars[] = {
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
378
1181
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
379 { 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
380 ngx_http_upstream_addr_variable, 0,
3898
bd1222fb0192 allow to use $upstream_... variables in SSI
Igor Sysoev <igor@sysoev.ru>
parents: 3879
diff changeset
381 NGX_HTTP_VAR_NOCACHEABLE, 0 },
1181
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
382
637
e60fe4cf1d4e nginx-0.3.40-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 629
diff changeset
383 { 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
384 ngx_http_upstream_status_variable, 0,
3898
bd1222fb0192 allow to use $upstream_... variables in SSI
Igor Sysoev <igor@sysoev.ru>
parents: 3879
diff changeset
385 NGX_HTTP_VAR_NOCACHEABLE, 0 },
573
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
386
6147
74b6ef56ea56 Upstream: $upstream_connect_time.
Ruslan Ermilov <ru@nginx.com>
parents: 6146
diff changeset
387 { ngx_string("upstream_connect_time"), NULL,
74b6ef56ea56 Upstream: $upstream_connect_time.
Ruslan Ermilov <ru@nginx.com>
parents: 6146
diff changeset
388 ngx_http_upstream_response_time_variable, 2,
74b6ef56ea56 Upstream: $upstream_connect_time.
Ruslan Ermilov <ru@nginx.com>
parents: 6146
diff changeset
389 NGX_HTTP_VAR_NOCACHEABLE, 0 },
74b6ef56ea56 Upstream: $upstream_connect_time.
Ruslan Ermilov <ru@nginx.com>
parents: 6146
diff changeset
390
5964
0a198a517eaf Upstream: $upstream_header_time variable.
Vladimir Homutov <vl@nginx.com>
parents: 5960
diff changeset
391 { ngx_string("upstream_header_time"), NULL,
0a198a517eaf Upstream: $upstream_header_time variable.
Vladimir Homutov <vl@nginx.com>
parents: 5960
diff changeset
392 ngx_http_upstream_response_time_variable, 1,
0a198a517eaf Upstream: $upstream_header_time variable.
Vladimir Homutov <vl@nginx.com>
parents: 5960
diff changeset
393 NGX_HTTP_VAR_NOCACHEABLE, 0 },
0a198a517eaf Upstream: $upstream_header_time variable.
Vladimir Homutov <vl@nginx.com>
parents: 5960
diff changeset
394
637
e60fe4cf1d4e nginx-0.3.40-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 629
diff changeset
395 { 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
396 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
397 NGX_HTTP_VAR_NOCACHEABLE, 0 },
573
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
398
2402
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
399 { ngx_string("upstream_response_length"), NULL,
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
400 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
401 NGX_HTTP_VAR_NOCACHEABLE, 0 },
2402
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
402
6654
c131f20c9562 Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents: 6594
diff changeset
403 { ngx_string("upstream_bytes_received"), NULL,
c131f20c9562 Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents: 6594
diff changeset
404 ngx_http_upstream_response_length_variable, 1,
c131f20c9562 Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents: 6594
diff changeset
405 NGX_HTTP_VAR_NOCACHEABLE, 0 },
c131f20c9562 Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents: 6594
diff changeset
406
7429
e573d74299a0 Upstream: implemented $upstream_bytes_sent.
Ruslan Ermilov <ru@nginx.com>
parents: 7397
diff changeset
407 { ngx_string("upstream_bytes_sent"), NULL,
e573d74299a0 Upstream: implemented $upstream_bytes_sent.
Ruslan Ermilov <ru@nginx.com>
parents: 7397
diff changeset
408 ngx_http_upstream_response_length_variable, 2,
e573d74299a0 Upstream: implemented $upstream_bytes_sent.
Ruslan Ermilov <ru@nginx.com>
parents: 7397
diff changeset
409 NGX_HTTP_VAR_NOCACHEABLE, 0 },
e573d74299a0 Upstream: implemented $upstream_bytes_sent.
Ruslan Ermilov <ru@nginx.com>
parents: 7397
diff changeset
410
2957
b4f39842523b fix building --without-http-cache, broken in r2953
Igor Sysoev <igor@sysoev.ru>
parents: 2953
diff changeset
411 #if (NGX_HTTP_CACHE)
b4f39842523b fix building --without-http-cache, broken in r2953
Igor Sysoev <igor@sysoev.ru>
parents: 2953
diff changeset
412
2952
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2949
diff changeset
413 { ngx_string("upstream_cache_status"), NULL,
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2949
diff changeset
414 ngx_http_upstream_cache_status, 0,
3898
bd1222fb0192 allow to use $upstream_... variables in SSI
Igor Sysoev <igor@sysoev.ru>
parents: 3879
diff changeset
415 NGX_HTTP_VAR_NOCACHEABLE, 0 },
2952
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2949
diff changeset
416
5441
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
417 { ngx_string("upstream_cache_last_modified"), NULL,
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
418 ngx_http_upstream_cache_last_modified, 0,
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
419 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
420
5738
c95d7882dfc9 Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5737
diff changeset
421 { ngx_string("upstream_cache_etag"), NULL,
c95d7882dfc9 Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5737
diff changeset
422 ngx_http_upstream_cache_etag, 0,
c95d7882dfc9 Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5737
diff changeset
423 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
424
2957
b4f39842523b fix building --without-http-cache, broken in r2953
Igor Sysoev <igor@sysoev.ru>
parents: 2953
diff changeset
425 #endif
b4f39842523b fix building --without-http-cache, broken in r2953
Igor Sysoev <igor@sysoev.ru>
parents: 2953
diff changeset
426
6899
d2b2ff157da5 Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6876
diff changeset
427 { ngx_string("upstream_http_"), NULL, ngx_http_upstream_header_variable,
d2b2ff157da5 Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6876
diff changeset
428 0, NGX_HTTP_VAR_NOCACHEABLE|NGX_HTTP_VAR_PREFIX, 0 },
d2b2ff157da5 Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6876
diff changeset
429
7230
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
430 { ngx_string("upstream_trailer_"), NULL, ngx_http_upstream_trailer_variable,
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
431 0, NGX_HTTP_VAR_NOCACHEABLE|NGX_HTTP_VAR_PREFIX, 0 },
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
432
6899
d2b2ff157da5 Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6876
diff changeset
433 { ngx_string("upstream_cookie_"), NULL, ngx_http_upstream_cookie_variable,
d2b2ff157da5 Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6876
diff changeset
434 0, NGX_HTTP_VAR_NOCACHEABLE|NGX_HTTP_VAR_PREFIX, 0 },
d2b2ff157da5 Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6876
diff changeset
435
7077
2a288909abc6 Variables: macros for null variables.
Ruslan Ermilov <ru@nginx.com>
parents: 7070
diff changeset
436 ngx_http_null_variable
573
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
437 };
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
438
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
439
2268
33556140681a *) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents: 2267
diff changeset
440 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
441 { 500, NGX_HTTP_UPSTREAM_FT_HTTP_500 },
33556140681a *) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents: 2267
diff changeset
442 { 502, NGX_HTTP_UPSTREAM_FT_HTTP_502 },
33556140681a *) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents: 2267
diff changeset
443 { 503, NGX_HTTP_UPSTREAM_FT_HTTP_503 },
33556140681a *) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents: 2267
diff changeset
444 { 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
445 { 403, NGX_HTTP_UPSTREAM_FT_HTTP_403 },
2268
33556140681a *) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents: 2267
diff changeset
446 { 404, NGX_HTTP_UPSTREAM_FT_HTTP_404 },
6966
fa56ab75cffc Upstream: allow recovery from "429 Too Many Requests" response.
Piotr Sikora <piotrsikora@google.com>
parents: 6961
diff changeset
447 { 429, NGX_HTTP_UPSTREAM_FT_HTTP_429 },
2268
33556140681a *) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents: 2267
diff changeset
448 { 0, 0 }
33556140681a *) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents: 2267
diff changeset
449 };
33556140681a *) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents: 2267
diff changeset
450
2875
6e1941b321b7 proxy_cache_methods and fastcgi_cache_methods
Igor Sysoev <igor@sysoev.ru>
parents: 2874
diff changeset
451
6e1941b321b7 proxy_cache_methods and fastcgi_cache_methods
Igor Sysoev <igor@sysoev.ru>
parents: 2874
diff changeset
452 ngx_conf_bitmask_t ngx_http_upstream_cache_method_mask[] = {
6439
Ruslan Ermilov <ru@nginx.com>
parents: 6428
diff changeset
453 { ngx_string("GET"), NGX_HTTP_GET },
Ruslan Ermilov <ru@nginx.com>
parents: 6428
diff changeset
454 { ngx_string("HEAD"), NGX_HTTP_HEAD },
Ruslan Ermilov <ru@nginx.com>
parents: 6428
diff changeset
455 { ngx_string("POST"), NGX_HTTP_POST },
Ruslan Ermilov <ru@nginx.com>
parents: 6428
diff changeset
456 { ngx_null_string, 0 }
2875
6e1941b321b7 proxy_cache_methods and fastcgi_cache_methods
Igor Sysoev <igor@sysoev.ru>
parents: 2874
diff changeset
457 };
6e1941b321b7 proxy_cache_methods and fastcgi_cache_methods
Igor Sysoev <igor@sysoev.ru>
parents: 2874
diff changeset
458
6e1941b321b7 proxy_cache_methods and fastcgi_cache_methods
Igor Sysoev <igor@sysoev.ru>
parents: 2874
diff changeset
459
3667
12bd9e26fadb use shared ngx_http_upstream_ignore_headers_masks[]
Igor Sysoev <igor@sysoev.ru>
parents: 3527
diff changeset
460 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
461 { 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
462 { 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
463 { 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
464 { 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
465 { 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
466 { 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
467 { 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
468 { 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
469 { 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
470 { ngx_null_string, 0 }
12bd9e26fadb use shared ngx_http_upstream_ignore_headers_masks[]
Igor Sysoev <igor@sysoev.ru>
parents: 3527
diff changeset
471 };
12bd9e26fadb use shared ngx_http_upstream_ignore_headers_masks[]
Igor Sysoev <igor@sysoev.ru>
parents: 3527
diff changeset
472
12bd9e26fadb use shared ngx_http_upstream_ignore_headers_masks[]
Igor Sysoev <igor@sysoev.ru>
parents: 3527
diff changeset
473
3006
95972b9e790b ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents: 3004
diff changeset
474 ngx_int_t
95972b9e790b ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents: 3004
diff changeset
475 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
476 {
95972b9e790b ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents: 3004
diff changeset
477 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
478
95972b9e790b ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents: 3004
diff changeset
479 u = r->upstream;
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 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
482 r->main->count++;
3006
95972b9e790b ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents: 3004
diff changeset
483 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
484 }
95972b9e790b ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents: 3004
diff changeset
485
95972b9e790b ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents: 3004
diff changeset
486 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
487 if (u == NULL) {
95972b9e790b ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents: 3004
diff changeset
488 return NGX_ERROR;
95972b9e790b ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents: 3004
diff changeset
489 }
95972b9e790b ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents: 3004
diff changeset
490
95972b9e790b ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents: 3004
diff changeset
491 r->upstream = u;
95972b9e790b ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents: 3004
diff changeset
492
95972b9e790b ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents: 3004
diff changeset
493 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
494 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
495
3056
d22afd261e72 do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents: 3055
diff changeset
496 #if (NGX_HTTP_CACHE)
d22afd261e72 do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents: 3055
diff changeset
497 r->cache = NULL;
d22afd261e72 do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents: 3055
diff changeset
498 #endif
d22afd261e72 do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents: 3055
diff changeset
499
4117
103b0d9afe07 Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4116
diff changeset
500 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
501 u->headers_in.last_modified_time = -1;
4117
103b0d9afe07 Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4116
diff changeset
502
3006
95972b9e790b ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents: 3004
diff changeset
503 return NGX_OK;
95972b9e790b ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents: 3004
diff changeset
504 }
95972b9e790b ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents: 3004
diff changeset
505
95972b9e790b ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents: 3004
diff changeset
506
487
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 485
diff changeset
507 void
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 485
diff changeset
508 ngx_http_upstream_init(ngx_http_request_t *r)
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
509 {
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3050
diff changeset
510 ngx_connection_t *c;
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
511
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
512 c = r->connection;
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
513
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
514 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
515 "http init upstream, client timer: %d", c->read->timer_set);
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
516
6246
257b51c37c5a The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents: 6242
diff changeset
517 #if (NGX_HTTP_V2)
257b51c37c5a The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents: 6242
diff changeset
518 if (r->stream) {
5121
c0f7b94e88ba Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents: 5113
diff changeset
519 ngx_http_upstream_init_request(r);
c0f7b94e88ba Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents: 5113
diff changeset
520 return;
c0f7b94e88ba Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents: 5113
diff changeset
521 }
c0f7b94e88ba Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents: 5113
diff changeset
522 #endif
c0f7b94e88ba Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents: 5113
diff changeset
523
8921
33226ac61076 HTTP/3: merged ngx_http_quic_module into ngx_http_v3_module.
Roman Arutyunyan <arut@nginx.com>
parents: 8889
diff changeset
524 #if (NGX_HTTP_V3)
8630
279ad36f2f4b QUIC: renamed c->qs to c->quic.
Roman Arutyunyan <arut@nginx.com>
parents: 8584
diff changeset
525 if (c->quic) {
8584
474706351c09 QUIC: fixed ngx_http_upstream_init() much like HTTP/2 connections.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8568
diff changeset
526 ngx_http_upstream_init_request(r);
474706351c09 QUIC: fixed ngx_http_upstream_init() much like HTTP/2 connections.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8568
diff changeset
527 return;
474706351c09 QUIC: fixed ngx_http_upstream_init() much like HTTP/2 connections.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8568
diff changeset
528 }
474706351c09 QUIC: fixed ngx_http_upstream_init() much like HTTP/2 connections.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8568
diff changeset
529 #endif
474706351c09 QUIC: fixed ngx_http_upstream_init() much like HTTP/2 connections.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8568
diff changeset
530
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
531 if (c->read->timer_set) {
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
532 ngx_del_timer(c->read);
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
533 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
534
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
535 if (ngx_event_flags & NGX_USE_CLEAR_EVENT) {
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
536
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
537 if (!c->write->active) {
531
c3bd8cdabb8f nginx-0.1.40-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
538 if (ngx_add_event(c->write, NGX_WRITE_EVENT, NGX_CLEAR_EVENT)
c3bd8cdabb8f nginx-0.1.40-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
539 == NGX_ERROR)
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
540 {
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
541 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
542 return;
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
543 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
544 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
545 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
546
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3050
diff changeset
547 ngx_http_upstream_init_request(r);
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3050
diff changeset
548 }
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3050
diff changeset
549
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3050
diff changeset
550
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3050
diff changeset
551 static void
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3050
diff changeset
552 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
553 {
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3050
diff changeset
554 ngx_str_t *host;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3050
diff changeset
555 ngx_uint_t i;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3050
diff changeset
556 ngx_resolver_ctx_t *ctx, temp;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3050
diff changeset
557 ngx_http_cleanup_t *cln;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3050
diff changeset
558 ngx_http_upstream_t *u;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3050
diff changeset
559 ngx_http_core_loc_conf_t *clcf;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3050
diff changeset
560 ngx_http_upstream_srv_conf_t *uscf, **uscfp;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3050
diff changeset
561 ngx_http_upstream_main_conf_t *umcf;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3050
diff changeset
562
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3050
diff changeset
563 if (r->aio) {
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3050
diff changeset
564 return;
537
c9ad0d9c7d59 nginx-0.1.43-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 531
diff changeset
565 }
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
566
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3050
diff changeset
567 u = r->upstream;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3050
diff changeset
568
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
569 #if (NGX_HTTP_CACHE)
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
570
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
571 if (u->conf->cache) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
572 ngx_int_t rc;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
573
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
574 rc = ngx_http_upstream_cache(r, u);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
575
3055
92b6cfaa3c27 fix sending a cached file using AIO
Igor Sysoev <igor@sysoev.ru>
parents: 3053
diff changeset
576 if (rc == NGX_BUSY) {
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3050
diff changeset
577 r->write_event_handler = ngx_http_upstream_init_request;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3050
diff changeset
578 return;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3050
diff changeset
579 }
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3050
diff changeset
580
3055
92b6cfaa3c27 fix sending a cached file using AIO
Igor Sysoev <igor@sysoev.ru>
parents: 3053
diff changeset
581 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
582
5827
54e9b83d00f0 Upstream: avoided directly terminating the connection.
FengGu <flygoast@126.com>
parents: 5818
diff changeset
583 if (rc == NGX_ERROR) {
54e9b83d00f0 Upstream: avoided directly terminating the connection.
FengGu <flygoast@126.com>
parents: 5818
diff changeset
584 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
585 return;
54e9b83d00f0 Upstream: avoided directly terminating the connection.
FengGu <flygoast@126.com>
parents: 5818
diff changeset
586 }
54e9b83d00f0 Upstream: avoided directly terminating the connection.
FengGu <flygoast@126.com>
parents: 5818
diff changeset
587
6242
0e3a45ec2a3a Upstream: fixed cache send error handling.
Roman Arutyunyan <arut@nginx.com>
parents: 6180
diff changeset
588 if (rc == NGX_OK) {
0e3a45ec2a3a Upstream: fixed cache send error handling.
Roman Arutyunyan <arut@nginx.com>
parents: 6180
diff changeset
589 rc = ngx_http_upstream_cache_send(r, u);
0e3a45ec2a3a Upstream: fixed cache send error handling.
Roman Arutyunyan <arut@nginx.com>
parents: 6180
diff changeset
590
0e3a45ec2a3a Upstream: fixed cache send error handling.
Roman Arutyunyan <arut@nginx.com>
parents: 6180
diff changeset
591 if (rc == NGX_DONE) {
0e3a45ec2a3a Upstream: fixed cache send error handling.
Roman Arutyunyan <arut@nginx.com>
parents: 6180
diff changeset
592 return;
0e3a45ec2a3a Upstream: fixed cache send error handling.
Roman Arutyunyan <arut@nginx.com>
parents: 6180
diff changeset
593 }
0e3a45ec2a3a Upstream: fixed cache send error handling.
Roman Arutyunyan <arut@nginx.com>
parents: 6180
diff changeset
594
0e3a45ec2a3a Upstream: fixed cache send error handling.
Roman Arutyunyan <arut@nginx.com>
parents: 6180
diff changeset
595 if (rc == NGX_HTTP_UPSTREAM_INVALID_HEADER) {
0e3a45ec2a3a Upstream: fixed cache send error handling.
Roman Arutyunyan <arut@nginx.com>
parents: 6180
diff changeset
596 rc = NGX_DECLINED;
0e3a45ec2a3a Upstream: fixed cache send error handling.
Roman Arutyunyan <arut@nginx.com>
parents: 6180
diff changeset
597 r->cached = 0;
7116
46ddff109e72 Upstream: better handling of invalid headers in cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7093
diff changeset
598 u->buffer.start = NULL;
46ddff109e72 Upstream: better handling of invalid headers in cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7093
diff changeset
599 u->cache_status = NGX_HTTP_CACHE_MISS;
7125
b8fc701daf8e Upstream: even better handling of invalid headers in cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7117
diff changeset
600 u->request_sent = 1;
6242
0e3a45ec2a3a Upstream: fixed cache send error handling.
Roman Arutyunyan <arut@nginx.com>
parents: 6180
diff changeset
601 }
0e3a45ec2a3a Upstream: fixed cache send error handling.
Roman Arutyunyan <arut@nginx.com>
parents: 6180
diff changeset
602 }
0e3a45ec2a3a Upstream: fixed cache send error handling.
Roman Arutyunyan <arut@nginx.com>
parents: 6180
diff changeset
603
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
604 if (rc != NGX_DECLINED) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
605 ngx_http_finalize_request(r, rc);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
606 return;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
607 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
608 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
609
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
610 #endif
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
611
5947
d9025ea1f5a5 Upstream: simplified proxy_store and friends configuration code.
Valentin Bartenev <vbart@nginx.com>
parents: 5935
diff changeset
612 u->store = u->conf->store;
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3050
diff changeset
613
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3050
diff changeset
614 if (!u->store && !r->post_action && !u->conf->ignore_client_abort) {
7810
1bf8ab7063de Upstream: fixed broken connection check with eventport.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7809
diff changeset
615
7811
1ebd78df4ce7 Fixed handling of already closed connections.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7810
diff changeset
616 if (r->connection->read->ready) {
1ebd78df4ce7 Fixed handling of already closed connections.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7810
diff changeset
617 ngx_post_event(r->connection->read, &ngx_posted_events);
1ebd78df4ce7 Fixed handling of already closed connections.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7810
diff changeset
618
1ebd78df4ce7 Fixed handling of already closed connections.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7810
diff changeset
619 } else {
1ebd78df4ce7 Fixed handling of already closed connections.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7810
diff changeset
620 if (ngx_handle_read_event(r->connection->read, 0) != NGX_OK) {
1ebd78df4ce7 Fixed handling of already closed connections.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7810
diff changeset
621 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
1ebd78df4ce7 Fixed handling of already closed connections.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7810
diff changeset
622 return;
1ebd78df4ce7 Fixed handling of already closed connections.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7810
diff changeset
623 }
7810
1bf8ab7063de Upstream: fixed broken connection check with eventport.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7809
diff changeset
624 }
1bf8ab7063de Upstream: fixed broken connection check with eventport.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7809
diff changeset
625
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3050
diff changeset
626 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
627 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
628 }
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3050
diff changeset
629
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3050
diff changeset
630 if (r->request_body) {
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3050
diff changeset
631 u->request_bufs = r->request_body->bufs;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3050
diff changeset
632 }
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3050
diff changeset
633
537
c9ad0d9c7d59 nginx-0.1.43-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 531
diff changeset
634 if (u->create_request(r) != NGX_OK) {
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
635 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
636 return;
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
637 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
638
6528
88f012eee7d8 Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents: 6474
diff changeset
639 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
640 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
641 return;
88f012eee7d8 Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents: 6474
diff changeset
642 }
3271
fcd98af88df3 proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents: 3198
diff changeset
643
7371
8b68d50090e4 Upstream: proxy_socket_keepalive and friends.
Vladimir Homutov <vl@nginx.com>
parents: 7341
diff changeset
644 if (u->conf->socket_keepalive) {
8b68d50090e4 Upstream: proxy_socket_keepalive and friends.
Vladimir Homutov <vl@nginx.com>
parents: 7341
diff changeset
645 u->peer.so_keepalive = 1;
8b68d50090e4 Upstream: proxy_socket_keepalive and friends.
Vladimir Homutov <vl@nginx.com>
parents: 7341
diff changeset
646 }
8b68d50090e4 Upstream: proxy_socket_keepalive and friends.
Vladimir Homutov <vl@nginx.com>
parents: 7341
diff changeset
647
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
648 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
649
3053
0d253659da12 directio_alignment
Igor Sysoev <igor@sysoev.ru>
parents: 3052
diff changeset
650 u->output.alignment = clcf->directio_alignment;
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
651 u->output.pool = r->pool;
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
652 u->output.bufs.num = 1;
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
653 u->output.bufs.size = clcf->client_body_buffer_size;
6050
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
654
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
655 if (u->output.output_filter == NULL) {
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
656 u->output.output_filter = ngx_chain_writer;
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
657 u->output.filter_ctx = &u->writer;
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
658 }
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
659
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
660 u->writer.pool = r->pool;
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
661
1168
4d0d12446c3b store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents: 1166
diff changeset
662 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
663
4d0d12446c3b store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents: 1166
diff changeset
664 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
665 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
666 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
667 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
668 return;
4d0d12446c3b store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents: 1166
diff changeset
669 }
4d0d12446c3b store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents: 1166
diff changeset
670
4d0d12446c3b store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents: 1166
diff changeset
671 } else {
4d0d12446c3b store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents: 1166
diff changeset
672
4d0d12446c3b store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents: 1166
diff changeset
673 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
674 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
675 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
676 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
677 return;
4d0d12446c3b store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents: 1166
diff changeset
678 }
4d0d12446c3b store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents: 1166
diff changeset
679
4d0d12446c3b store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents: 1166
diff changeset
680 ngx_memzero(u->state, sizeof(ngx_http_upstream_state_t));
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
681 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
682
593
425af804d968 nginx-0.3.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 591
diff changeset
683 cln = ngx_http_cleanup_add(r, 0);
569
174f1e853e1e nginx-0.3.6-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 563
diff changeset
684 if (cln == NULL) {
174f1e853e1e nginx-0.3.6-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 563
diff changeset
685 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
174f1e853e1e nginx-0.3.6-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 563
diff changeset
686 return;
174f1e853e1e nginx-0.3.6-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 563
diff changeset
687 }
174f1e853e1e nginx-0.3.6-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 563
diff changeset
688
174f1e853e1e nginx-0.3.6-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 563
diff changeset
689 cln->handler = ngx_http_upstream_cleanup;
174f1e853e1e nginx-0.3.6-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 563
diff changeset
690 cln->data = r;
174f1e853e1e nginx-0.3.6-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 563
diff changeset
691 u->cleanup = &cln->handler;
174f1e853e1e nginx-0.3.6-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 563
diff changeset
692
1658
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
693 if (u->resolved == NULL) {
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
694
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
695 uscf = u->conf->upstream;
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
696
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
697 } else {
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
698
5660
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
699 #if (NGX_HTTP_SSL)
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
700 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
701 #endif
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
702
6303
a93345ee8f52 Upstream: fixed "no port" detection in evaluated upstreams.
Ruslan Ermilov <ru@nginx.com>
parents: 6290
diff changeset
703 host = &u->resolved->host;
a93345ee8f52 Upstream: fixed "no port" detection in evaluated upstreams.
Ruslan Ermilov <ru@nginx.com>
parents: 6290
diff changeset
704
6786
906ac20234ed Upstream: do not unnecessarily create per-request upstreams.
Ruslan Ermilov <ru@nginx.com>
parents: 6777
diff changeset
705 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
706
906ac20234ed Upstream: do not unnecessarily create per-request upstreams.
Ruslan Ermilov <ru@nginx.com>
parents: 6777
diff changeset
707 uscfp = umcf->upstreams.elts;
906ac20234ed Upstream: do not unnecessarily create per-request upstreams.
Ruslan Ermilov <ru@nginx.com>
parents: 6777
diff changeset
708
906ac20234ed Upstream: do not unnecessarily create per-request upstreams.
Ruslan Ermilov <ru@nginx.com>
parents: 6777
diff changeset
709 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
710
906ac20234ed Upstream: do not unnecessarily create per-request upstreams.
Ruslan Ermilov <ru@nginx.com>
parents: 6777
diff changeset
711 uscf = uscfp[i];
906ac20234ed Upstream: do not unnecessarily create per-request upstreams.
Ruslan Ermilov <ru@nginx.com>
parents: 6777
diff changeset
712
906ac20234ed Upstream: do not unnecessarily create per-request upstreams.
Ruslan Ermilov <ru@nginx.com>
parents: 6777
diff changeset
713 if (uscf->host.len == host->len
906ac20234ed Upstream: do not unnecessarily create per-request upstreams.
Ruslan Ermilov <ru@nginx.com>
parents: 6777
diff changeset
714 && ((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
715 || uscf->port == u->resolved->port)
906ac20234ed Upstream: do not unnecessarily create per-request upstreams.
Ruslan Ermilov <ru@nginx.com>
parents: 6777
diff changeset
716 && 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
717 {
906ac20234ed Upstream: do not unnecessarily create per-request upstreams.
Ruslan Ermilov <ru@nginx.com>
parents: 6777
diff changeset
718 goto found;
906ac20234ed Upstream: do not unnecessarily create per-request upstreams.
Ruslan Ermilov <ru@nginx.com>
parents: 6777
diff changeset
719 }
906ac20234ed Upstream: do not unnecessarily create per-request upstreams.
Ruslan Ermilov <ru@nginx.com>
parents: 6777
diff changeset
720 }
906ac20234ed Upstream: do not unnecessarily create per-request upstreams.
Ruslan Ermilov <ru@nginx.com>
parents: 6777
diff changeset
721
2422
7af1e5fe102c variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents: 2413
diff changeset
722 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
723
6326
705c356ce664 Fixed fastcgi_pass with UNIX socket and variables (ticket #855).
Ruslan Ermilov <ru@nginx.com>
parents: 6316
diff changeset
724 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
725 && 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
726 {
6303
a93345ee8f52 Upstream: fixed "no port" detection in evaluated upstreams.
Ruslan Ermilov <ru@nginx.com>
parents: 6290
diff changeset
727 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
728 "no port in upstream \"%V\"", host);
a93345ee8f52 Upstream: fixed "no port" detection in evaluated upstreams.
Ruslan Ermilov <ru@nginx.com>
parents: 6290
diff changeset
729 ngx_http_upstream_finalize_request(r, u,
6313
Maxim Dounin <mdounin@mdounin.ru>
parents: 6306
diff changeset
730 NGX_HTTP_INTERNAL_SERVER_ERROR);
6303
a93345ee8f52 Upstream: fixed "no port" detection in evaluated upstreams.
Ruslan Ermilov <ru@nginx.com>
parents: 6290
diff changeset
731 return;
a93345ee8f52 Upstream: fixed "no port" detection in evaluated upstreams.
Ruslan Ermilov <ru@nginx.com>
parents: 6290
diff changeset
732 }
a93345ee8f52 Upstream: fixed "no port" detection in evaluated upstreams.
Ruslan Ermilov <ru@nginx.com>
parents: 6290
diff changeset
733
2422
7af1e5fe102c variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents: 2413
diff changeset
734 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
735 != NGX_OK)
7af1e5fe102c variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents: 2413
diff changeset
736 {
3169
b1013d768911 fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents: 3161
diff changeset
737 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
738 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
739 return;
7af1e5fe102c variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents: 2413
diff changeset
740 }
7af1e5fe102c variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents: 2413
diff changeset
741
7af1e5fe102c variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents: 2413
diff changeset
742 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
743
7af1e5fe102c variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents: 2413
diff changeset
744 return;
7af1e5fe102c variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents: 2413
diff changeset
745 }
7af1e5fe102c variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents: 2413
diff changeset
746
3879
502a6b0acf3f fix case when a host in fastcgi_pass, scgi_pass, and uwsgi_pass
Igor Sysoev <igor@sysoev.ru>
parents: 3713
diff changeset
747 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
748 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
749 "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
750 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
751 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
752 return;
502a6b0acf3f fix case when a host in fastcgi_pass, scgi_pass, and uwsgi_pass
Igor Sysoev <igor@sysoev.ru>
parents: 3713
diff changeset
753 }
502a6b0acf3f fix case when a host in fastcgi_pass, scgi_pass, and uwsgi_pass
Igor Sysoev <igor@sysoev.ru>
parents: 3713
diff changeset
754
1658
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
755 temp.name = *host;
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
756
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
757 ctx = ngx_resolve_start(clcf->resolver, &temp);
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
758 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
759 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
760 NGX_HTTP_INTERNAL_SERVER_ERROR);
1658
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
761 return;
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
762 }
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
763
1683
1e0b028055ec allow to use IP addresses without defined resolver
Igor Sysoev <igor@sysoev.ru>
parents: 1658
diff changeset
764 if (ctx == NGX_NO_RESOLVER) {
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3050
diff changeset
765 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
766 "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
767
3169
b1013d768911 fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents: 3161
diff changeset
768 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
769 return;
1e0b028055ec allow to use IP addresses without defined resolver
Igor Sysoev <igor@sysoev.ru>
parents: 1658
diff changeset
770 }
1e0b028055ec allow to use IP addresses without defined resolver
Igor Sysoev <igor@sysoev.ru>
parents: 1658
diff changeset
771
1658
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
772 ctx->name = *host;
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
773 ctx->handler = ngx_http_upstream_resolve_handler;
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
774 ctx->data = r;
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
775 ctx->timeout = clcf->resolver_timeout;
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
776
1959
4f16186f5603 quick resolving handles u->resolved->ctx by itself
Igor Sysoev <igor@sysoev.ru>
parents: 1958
diff changeset
777 u->resolved->ctx = ctx;
4f16186f5603 quick resolving handles u->resolved->ctx by itself
Igor Sysoev <igor@sysoev.ru>
parents: 1958
diff changeset
778
1658
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
779 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
780 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
781 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
782 NGX_HTTP_INTERNAL_SERVER_ERROR);
1658
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
783 return;
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
784 }
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
785
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
786 return;
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
787 }
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
788
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
789 found:
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
790
4964
2464ccebdb52 Upstream: fixed SIGSEGV with the "if" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4916
diff changeset
791 if (uscf == NULL) {
2464ccebdb52 Upstream: fixed SIGSEGV with the "if" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4916
diff changeset
792 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
793 "no upstream configuration");
2464ccebdb52 Upstream: fixed SIGSEGV with the "if" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4916
diff changeset
794 ngx_http_upstream_finalize_request(r, u,
2464ccebdb52 Upstream: fixed SIGSEGV with the "if" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4916
diff changeset
795 NGX_HTTP_INTERNAL_SERVER_ERROR);
2464ccebdb52 Upstream: fixed SIGSEGV with the "if" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4916
diff changeset
796 return;
2464ccebdb52 Upstream: fixed SIGSEGV with the "if" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4916
diff changeset
797 }
2464ccebdb52 Upstream: fixed SIGSEGV with the "if" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4916
diff changeset
798
6703
edcd9303a4d3 Upstream: introduced u->upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6699
diff changeset
799 u->upstream = uscf;
edcd9303a4d3 Upstream: introduced u->upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6699
diff changeset
800
5682
110b50657d77 Upstream: restored workaround for "if".
Maxim Dounin <mdounin@mdounin.ru>
parents: 5677
diff changeset
801 #if (NGX_HTTP_SSL)
110b50657d77 Upstream: restored workaround for "if".
Maxim Dounin <mdounin@mdounin.ru>
parents: 5677
diff changeset
802 u->ssl_name = uscf->host;
110b50657d77 Upstream: restored workaround for "if".
Maxim Dounin <mdounin@mdounin.ru>
parents: 5677
diff changeset
803 #endif
110b50657d77 Upstream: restored workaround for "if".
Maxim Dounin <mdounin@mdounin.ru>
parents: 5677
diff changeset
804
1658
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
805 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
806 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
807 NGX_HTTP_INTERNAL_SERVER_ERROR);
1658
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
808 return;
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
809 }
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
810
5832
d09b689911ac Upstream: limited next_upstream time and tries (ticket #544).
Roman Arutyunyan <arut@nginx.com>
parents: 5827
diff changeset
811 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
812
d09b689911ac Upstream: limited next_upstream time and tries (ticket #544).
Roman Arutyunyan <arut@nginx.com>
parents: 5827
diff changeset
813 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
814 && 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
815 {
d09b689911ac Upstream: limited next_upstream time and tries (ticket #544).
Roman Arutyunyan <arut@nginx.com>
parents: 5827
diff changeset
816 u->peer.tries = u->conf->next_upstream_tries;
d09b689911ac Upstream: limited next_upstream time and tries (ticket #544).
Roman Arutyunyan <arut@nginx.com>
parents: 5827
diff changeset
817 }
d09b689911ac Upstream: limited next_upstream time and tries (ticket #544).
Roman Arutyunyan <arut@nginx.com>
parents: 5827
diff changeset
818
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
819 ngx_http_upstream_connect(r, u);
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
820 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
821
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
822
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
823 #if (NGX_HTTP_CACHE)
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
824
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
825 static ngx_int_t
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
826 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
827 {
5951
610832763648 Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5950
diff changeset
828 ngx_int_t rc;
610832763648 Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5950
diff changeset
829 ngx_http_cache_t *c;
610832763648 Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5950
diff changeset
830 ngx_http_file_cache_t *cache;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
831
3056
d22afd261e72 do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents: 3055
diff changeset
832 c = r->cache;
d22afd261e72 do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents: 3055
diff changeset
833
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
834 if (c == NULL) {
3056
d22afd261e72 do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents: 3055
diff changeset
835
d22afd261e72 do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents: 3055
diff changeset
836 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
837 return NGX_DECLINED;
d22afd261e72 do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents: 3055
diff changeset
838 }
d22afd261e72 do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents: 3055
diff changeset
839
5951
610832763648 Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5950
diff changeset
840 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
841
610832763648 Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5950
diff changeset
842 if (rc != NGX_OK) {
610832763648 Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5950
diff changeset
843 return rc;
610832763648 Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5950
diff changeset
844 }
610832763648 Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5950
diff changeset
845
6306
b1858fc47e3b Style: unified request method checks.
Ruslan Ermilov <ru@nginx.com>
parents: 6303
diff changeset
846 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
847 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
848 }
d22afd261e72 do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents: 3055
diff changeset
849
3698
d11227f0107f rename ngx_http_file_cache_create() to ngx_http_file_cache_new()
Igor Sysoev <igor@sysoev.ru>
parents: 3697
diff changeset
850 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
851 return NGX_ERROR;
d22afd261e72 do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents: 3055
diff changeset
852 }
d22afd261e72 do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents: 3055
diff changeset
853
d22afd261e72 do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents: 3055
diff changeset
854 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
855 return NGX_ERROR;
d22afd261e72 do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents: 3055
diff changeset
856 }
d22afd261e72 do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents: 3055
diff changeset
857
d22afd261e72 do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents: 3055
diff changeset
858 /* TODO: add keys */
d22afd261e72 do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents: 3055
diff changeset
859
d22afd261e72 do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents: 3055
diff changeset
860 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
861
7456
608810849b6d Upstream: fixed logging of required buffer size (ticket #1722).
Chanhun Jeong <chanhun.jeong@navercorp.com>
parents: 7429
diff changeset
862 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
863 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
864 "%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
865 "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
866 &u->conf->module, u->conf->buffer_size,
215fe9223419 update r3945 with more descriptive error message
Igor Sysoev <igor@sysoev.ru>
parents: 3963
diff changeset
867 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
868
f1f194ceab16 fix segfault if cache key is larger than upstream buffer size
Igor Sysoev <igor@sysoev.ru>
parents: 3940
diff changeset
869 r->cache = NULL;
f1f194ceab16 fix segfault if cache key is larger than upstream buffer size
Igor Sysoev <igor@sysoev.ru>
parents: 3940
diff changeset
870 return NGX_DECLINED;
f1f194ceab16 fix segfault if cache key is larger than upstream buffer size
Igor Sysoev <igor@sysoev.ru>
parents: 3940
diff changeset
871 }
f1f194ceab16 fix segfault if cache key is larger than upstream buffer size
Igor Sysoev <igor@sysoev.ru>
parents: 3940
diff changeset
872
4176
2b5151a2300b Fixed cache bypass caching of non-cacheable replies (ticket #21).
Maxim Dounin <mdounin@mdounin.ru>
parents: 4152
diff changeset
873 u->cacheable = 1;
2b5151a2300b Fixed cache bypass caching of non-cacheable replies (ticket #21).
Maxim Dounin <mdounin@mdounin.ru>
parents: 4152
diff changeset
874
5950
eaeecf00d5d7 Upstream: preset some cache configuration when bypassing.
Valentin Bartenev <vbart@nginx.com>
parents: 5949
diff changeset
875 c = r->cache;
eaeecf00d5d7 Upstream: preset some cache configuration when bypassing.
Valentin Bartenev <vbart@nginx.com>
parents: 5949
diff changeset
876
eaeecf00d5d7 Upstream: preset some cache configuration when bypassing.
Valentin Bartenev <vbart@nginx.com>
parents: 5949
diff changeset
877 c->body_start = u->conf->buffer_size;
eaeecf00d5d7 Upstream: preset some cache configuration when bypassing.
Valentin Bartenev <vbart@nginx.com>
parents: 5949
diff changeset
878 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
879 c->file_cache = cache;
5950
eaeecf00d5d7 Upstream: preset some cache configuration when bypassing.
Valentin Bartenev <vbart@nginx.com>
parents: 5949
diff changeset
880
3917
2a70484a6580 fix a broken cached response if bypass/no_cache directive values are different,
Igor Sysoev <igor@sysoev.ru>
parents: 3898
diff changeset
881 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
882
2a70484a6580 fix a broken cached response if bypass/no_cache directive values are different,
Igor Sysoev <igor@sysoev.ru>
parents: 3898
diff changeset
883 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
884 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
885
2a70484a6580 fix a broken cached response if bypass/no_cache directive values are different,
Igor Sysoev <igor@sysoev.ru>
parents: 3898
diff changeset
886 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
887 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
888 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
889
2a70484a6580 fix a broken cached response if bypass/no_cache directive values are different,
Igor Sysoev <igor@sysoev.ru>
parents: 3898
diff changeset
890 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
891 break;
2a70484a6580 fix a broken cached response if bypass/no_cache directive values are different,
Igor Sysoev <igor@sysoev.ru>
parents: 3898
diff changeset
892 }
2a70484a6580 fix a broken cached response if bypass/no_cache directive values are different,
Igor Sysoev <igor@sysoev.ru>
parents: 3898
diff changeset
893
4385
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4375
diff changeset
894 c->lock = u->conf->cache_lock;
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4375
diff changeset
895 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
896 c->lock_age = u->conf->cache_lock_age;
4385
70ba81827472 Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4375
diff changeset
897
3056
d22afd261e72 do not create cache key in AIO invocation
Igor Sysoev <igor@sysoev.ru>
parents: 3055
diff changeset
898 u->cache_status = NGX_HTTP_CACHE_MISS;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
899 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
900
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
901 rc = ngx_http_file_cache_open(r);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
902
2926
80a314b63c56 delete useless r->cache->uses
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
903 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
904 "http upstream cache: %i", rc);
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
905
2952
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2949
diff changeset
906 switch (rc) {
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2949
diff changeset
907
6906
1aeaae6e9446 Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 6905
diff changeset
908 case NGX_HTTP_CACHE_STALE:
1aeaae6e9446 Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 6905
diff changeset
909
1aeaae6e9446 Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 6905
diff changeset
910 if (((u->conf->cache_use_stale & NGX_HTTP_UPSTREAM_FT_UPDATING)
7006
9552758a786e Background subrequests for cache updates.
Roman Arutyunyan <arut@nginx.com>
parents: 6986
diff changeset
911 || c->stale_updating) && !r->background
6906
1aeaae6e9446 Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 6905
diff changeset
912 && u->conf->cache_background_update)
1aeaae6e9446 Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 6905
diff changeset
913 {
7514
319242d2ddc9 Upstream: background cache update before cache send (ticket #1782).
Roman Arutyunyan <arut@nginx.com>
parents: 7504
diff changeset
914 if (ngx_http_upstream_cache_background_update(r, u) == NGX_OK) {
319242d2ddc9 Upstream: background cache update before cache send (ticket #1782).
Roman Arutyunyan <arut@nginx.com>
parents: 7504
diff changeset
915 r->cache->background = 1;
319242d2ddc9 Upstream: background cache update before cache send (ticket #1782).
Roman Arutyunyan <arut@nginx.com>
parents: 7504
diff changeset
916 u->cache_status = rc;
319242d2ddc9 Upstream: background cache update before cache send (ticket #1782).
Roman Arutyunyan <arut@nginx.com>
parents: 7504
diff changeset
917 rc = NGX_OK;
319242d2ddc9 Upstream: background cache update before cache send (ticket #1782).
Roman Arutyunyan <arut@nginx.com>
parents: 7504
diff changeset
918
319242d2ddc9 Upstream: background cache update before cache send (ticket #1782).
Roman Arutyunyan <arut@nginx.com>
parents: 7504
diff changeset
919 } else {
319242d2ddc9 Upstream: background cache update before cache send (ticket #1782).
Roman Arutyunyan <arut@nginx.com>
parents: 7504
diff changeset
920 rc = NGX_ERROR;
319242d2ddc9 Upstream: background cache update before cache send (ticket #1782).
Roman Arutyunyan <arut@nginx.com>
parents: 7504
diff changeset
921 }
6906
1aeaae6e9446 Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 6905
diff changeset
922 }
1aeaae6e9446 Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 6905
diff changeset
923
1aeaae6e9446 Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 6905
diff changeset
924 break;
1aeaae6e9446 Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 6905
diff changeset
925
2952
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2949
diff changeset
926 case NGX_HTTP_CACHE_UPDATING:
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2949
diff changeset
927
6906
1aeaae6e9446 Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 6905
diff changeset
928 if (((u->conf->cache_use_stale & NGX_HTTP_UPSTREAM_FT_UPDATING)
7006
9552758a786e Background subrequests for cache updates.
Roman Arutyunyan <arut@nginx.com>
parents: 6986
diff changeset
929 || c->stale_updating) && !r->background)
6905
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6899
diff changeset
930 {
2952
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2949
diff changeset
931 u->cache_status = rc;
2927
55ceaef03d34 proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents: 2926
diff changeset
932 rc = NGX_OK;
55ceaef03d34 proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents: 2926
diff changeset
933
55ceaef03d34 proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents: 2926
diff changeset
934 } else {
55ceaef03d34 proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents: 2926
diff changeset
935 rc = NGX_HTTP_CACHE_STALE;
55ceaef03d34 proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents: 2926
diff changeset
936 }
2952
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2949
diff changeset
937
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2949
diff changeset
938 break;
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2949
diff changeset
939
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2949
diff changeset
940 case NGX_OK:
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2949
diff changeset
941 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
942 }
55ceaef03d34 proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents: 2926
diff changeset
943
2952
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2949
diff changeset
944 switch (rc) {
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2949
diff changeset
945
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2949
diff changeset
946 case NGX_OK:
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
947
6242
0e3a45ec2a3a Upstream: fixed cache send error handling.
Roman Arutyunyan <arut@nginx.com>
parents: 6180
diff changeset
948 return NGX_OK;
2952
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2949
diff changeset
949
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2949
diff changeset
950 case NGX_HTTP_CACHE_STALE:
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
951
2665
4d627567c324 fix r2664: ..._cache_valid did not work for stale responses
Igor Sysoev <igor@sysoev.ru>
parents: 2664
diff changeset
952 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
953 c->updating_sec = 0;
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6899
diff changeset
954 c->error_sec = 0;
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6899
diff changeset
955
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
956 u->buffer.start = NULL;
2952
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2949
diff changeset
957 u->cache_status = NGX_HTTP_CACHE_EXPIRED;
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2949
diff changeset
958
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2949
diff changeset
959 break;
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2949
diff changeset
960
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2949
diff changeset
961 case NGX_DECLINED:
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
962
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
963 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
964 u->buffer.start = NULL;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
965
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
966 } else {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
967 u->buffer.pos = u->buffer.start + c->header_start;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
968 u->buffer.last = u->buffer.pos;
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
2952
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2949
diff changeset
971 break;
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2949
diff changeset
972
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3050
diff changeset
973 case NGX_HTTP_CACHE_SCARCE:
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
974
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
975 u->cacheable = 0;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
976
2952
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2949
diff changeset
977 break;
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2949
diff changeset
978
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3050
diff changeset
979 case NGX_AGAIN:
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3050
diff changeset
980
3055
92b6cfaa3c27 fix sending a cached file using AIO
Igor Sysoev <igor@sysoev.ru>
parents: 3053
diff changeset
981 return NGX_BUSY;
3052
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3050
diff changeset
982
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3050
diff changeset
983 case NGX_ERROR:
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3050
diff changeset
984
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3050
diff changeset
985 return NGX_ERROR;
6060225e9261 FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents: 3050
diff changeset
986
2952
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2949
diff changeset
987 default:
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
988
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
989 /* 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
990
2952
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2949
diff changeset
991 u->cache_status = NGX_HTTP_CACHE_HIT;
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2949
diff changeset
992
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
993 return rc;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
994 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
995
6793
0fba3ed4e7eb Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6789
diff changeset
996 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
997 u->cacheable = 0;
0fba3ed4e7eb Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6789
diff changeset
998 }
0fba3ed4e7eb Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6789
diff changeset
999
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
1000 r->cached = 0;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
1001
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
1002 return NGX_DECLINED;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
1003 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
1004
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
1005
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
1006 static ngx_int_t
5951
610832763648 Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5950
diff changeset
1007 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
1008 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
1009 {
610832763648 Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5950
diff changeset
1010 ngx_str_t *name, val;
610832763648 Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5950
diff changeset
1011 ngx_uint_t i;
610832763648 Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5950
diff changeset
1012 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
1013
610832763648 Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5950
diff changeset
1014 if (u->conf->cache_zone) {
610832763648 Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5950
diff changeset
1015 *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
1016 return NGX_OK;
610832763648 Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5950
diff changeset
1017 }
610832763648 Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5950
diff changeset
1018
610832763648 Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5950
diff changeset
1019 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
1020 return NGX_ERROR;
610832763648 Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5950
diff changeset
1021 }
610832763648 Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5950
diff changeset
1022
610832763648 Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5950
diff changeset
1023 if (val.len == 0
610832763648 Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5950
diff changeset
1024 || (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
1025 {
610832763648 Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5950
diff changeset
1026 return NGX_DECLINED;
610832763648 Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5950
diff changeset
1027 }
610832763648 Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5950
diff changeset
1028
610832763648 Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5950
diff changeset
1029 caches = u->caches->elts;
610832763648 Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5950
diff changeset
1030
610832763648 Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5950
diff changeset
1031 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
1032 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
1033
610832763648 Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5950
diff changeset
1034 if (name->len == val.len
610832763648 Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5950
diff changeset
1035 && 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
1036 {
610832763648 Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5950
diff changeset
1037 *cache = caches[i];
610832763648 Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5950
diff changeset
1038 return NGX_OK;
610832763648 Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5950
diff changeset
1039 }
610832763648 Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5950
diff changeset
1040 }
610832763648 Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5950
diff changeset
1041
610832763648 Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5950
diff changeset
1042 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
1043 "cache \"%V\" not found", &val);
610832763648 Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5950
diff changeset
1044
610832763648 Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5950
diff changeset
1045 return NGX_ERROR;
610832763648 Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5950
diff changeset
1046 }
610832763648 Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5950
diff changeset
1047
610832763648 Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5950
diff changeset
1048
610832763648 Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5950
diff changeset
1049 static ngx_int_t
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
1050 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
1051 {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
1052 ngx_int_t rc;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
1053 ngx_http_cache_t *c;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
1054
2952
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2949
diff changeset
1055 r->cached = 1;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
1056 c = r->cache;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
1057
3369
479468a7d982 fix handling cached HTTP/0.9 response
Igor Sysoev <igor@sysoev.ru>
parents: 3272
diff changeset
1058 if (c->header_start == c->body_start) {
479468a7d982 fix handling cached HTTP/0.9 response
Igor Sysoev <igor@sysoev.ru>
parents: 3272
diff changeset
1059 r->http_version = NGX_HTTP_VERSION_9;
479468a7d982 fix handling cached HTTP/0.9 response
Igor Sysoev <igor@sysoev.ru>
parents: 3272
diff changeset
1060 return ngx_http_cache_send(r);
479468a7d982 fix handling cached HTTP/0.9 response
Igor Sysoev <igor@sysoev.ru>
parents: 3272
diff changeset
1061 }
479468a7d982 fix handling cached HTTP/0.9 response
Igor Sysoev <igor@sysoev.ru>
parents: 3272
diff changeset
1062
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
1063 /* TODO: cache stack */
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 u->buffer = *c->buf;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
1066 u->buffer.pos += c->header_start;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
1067
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
1068 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
1069 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
1070 u->headers_in.last_modified_time = -1;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
1071
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
1072 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
1073 sizeof(ngx_table_elt_t))
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
1074 != NGX_OK)
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
1075 {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
1076 return NGX_ERROR;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
1077 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
1078
7230
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
1079 if (ngx_list_init(&u->headers_in.trailers, r->pool, 2,
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
1080 sizeof(ngx_table_elt_t))
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
1081 != NGX_OK)
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
1082 {
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
1083 return NGX_ERROR;
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
1084 }
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
1085
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
1086 rc = u->process_header(r);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
1087
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
1088 if (rc == NGX_OK) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
1089
9217
6765e5f6d991 Upstream: fixed X-Accel-Redirect handling from cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9204
diff changeset
1090 rc = ngx_http_upstream_process_headers(r, u);
6765e5f6d991 Upstream: fixed X-Accel-Redirect handling from cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9204
diff changeset
1091
6765e5f6d991 Upstream: fixed X-Accel-Redirect handling from cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9204
diff changeset
1092 if (rc != NGX_OK) {
6765e5f6d991 Upstream: fixed X-Accel-Redirect handling from cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9204
diff changeset
1093 return rc;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
1094 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
1095
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
1096 return ngx_http_cache_send(r);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
1097 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
1098
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
1099 if (rc == NGX_ERROR) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
1100 return NGX_ERROR;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
1101 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
1102
7116
46ddff109e72 Upstream: better handling of invalid headers in cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7093
diff changeset
1103 if (rc == NGX_AGAIN) {
46ddff109e72 Upstream: better handling of invalid headers in cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7093
diff changeset
1104 rc = NGX_HTTP_UPSTREAM_INVALID_HEADER;
46ddff109e72 Upstream: better handling of invalid headers in cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7093
diff changeset
1105 }
46ddff109e72 Upstream: better handling of invalid headers in cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7093
diff changeset
1106
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
1107 /* rc == NGX_HTTP_UPSTREAM_INVALID_HEADER */
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
1108
7116
46ddff109e72 Upstream: better handling of invalid headers in cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7093
diff changeset
1109 ngx_log_error(NGX_LOG_CRIT, r->connection->log, 0,
46ddff109e72 Upstream: better handling of invalid headers in cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7093
diff changeset
1110 "cache file \"%s\" contains invalid header",
46ddff109e72 Upstream: better handling of invalid headers in cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7093
diff changeset
1111 c->file.name.data);
46ddff109e72 Upstream: better handling of invalid headers in cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7093
diff changeset
1112
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
1113 /* TODO: delete file */
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
1114
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
1115 return rc;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
1116 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
1117
6793
0fba3ed4e7eb Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6789
diff changeset
1118
0fba3ed4e7eb Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6789
diff changeset
1119 static ngx_int_t
6906
1aeaae6e9446 Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 6905
diff changeset
1120 ngx_http_upstream_cache_background_update(ngx_http_request_t *r,
1aeaae6e9446 Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 6905
diff changeset
1121 ngx_http_upstream_t *u)
1aeaae6e9446 Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 6905
diff changeset
1122 {
1aeaae6e9446 Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 6905
diff changeset
1123 ngx_http_request_t *sr;
1aeaae6e9446 Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 6905
diff changeset
1124
7070
f583559aadc7 Upstream: keep request body file from removal if requested.
Roman Arutyunyan <arut@nginx.com>
parents: 7067
diff changeset
1125 if (r == r->main) {
f583559aadc7 Upstream: keep request body file from removal if requested.
Roman Arutyunyan <arut@nginx.com>
parents: 7067
diff changeset
1126 r->preserve_body = 1;
f583559aadc7 Upstream: keep request body file from removal if requested.
Roman Arutyunyan <arut@nginx.com>
parents: 7067
diff changeset
1127 }
f583559aadc7 Upstream: keep request body file from removal if requested.
Roman Arutyunyan <arut@nginx.com>
parents: 7067
diff changeset
1128
6906
1aeaae6e9446 Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 6905
diff changeset
1129 if (ngx_http_subrequest(r, &r->uri, &r->args, &sr, NULL,
7006
9552758a786e Background subrequests for cache updates.
Roman Arutyunyan <arut@nginx.com>
parents: 6986
diff changeset
1130 NGX_HTTP_SUBREQUEST_CLONE
9552758a786e Background subrequests for cache updates.
Roman Arutyunyan <arut@nginx.com>
parents: 6986
diff changeset
1131 |NGX_HTTP_SUBREQUEST_BACKGROUND)
6906
1aeaae6e9446 Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 6905
diff changeset
1132 != NGX_OK)
1aeaae6e9446 Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 6905
diff changeset
1133 {
1aeaae6e9446 Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 6905
diff changeset
1134 return NGX_ERROR;
1aeaae6e9446 Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 6905
diff changeset
1135 }
1aeaae6e9446 Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 6905
diff changeset
1136
1aeaae6e9446 Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 6905
diff changeset
1137 sr->header_only = 1;
1aeaae6e9446 Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 6905
diff changeset
1138
1aeaae6e9446 Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 6905
diff changeset
1139 return NGX_OK;
1aeaae6e9446 Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 6905
diff changeset
1140 }
1aeaae6e9446 Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 6905
diff changeset
1141
1aeaae6e9446 Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 6905
diff changeset
1142
1aeaae6e9446 Upstream: proxy_cache_background_update and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 6905
diff changeset
1143 static ngx_int_t
6793
0fba3ed4e7eb Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6789
diff changeset
1144 ngx_http_upstream_cache_check_range(ngx_http_request_t *r,
0fba3ed4e7eb Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6789
diff changeset
1145 ngx_http_upstream_t *u)
0fba3ed4e7eb Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6789
diff changeset
1146 {
0fba3ed4e7eb Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6789
diff changeset
1147 off_t offset;
0fba3ed4e7eb Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6789
diff changeset
1148 u_char *p, *start;
0fba3ed4e7eb Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6789
diff changeset
1149 ngx_table_elt_t *h;
0fba3ed4e7eb Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6789
diff changeset
1150
0fba3ed4e7eb Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6789
diff changeset
1151 h = r->headers_in.range;
0fba3ed4e7eb Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6789
diff changeset
1152
0fba3ed4e7eb Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6789
diff changeset
1153 if (h == NULL
0fba3ed4e7eb Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6789
diff changeset
1154 || !u->cacheable
0fba3ed4e7eb Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6789
diff changeset
1155 || u->conf->cache_max_range_offset == NGX_MAX_OFF_T_VALUE)
0fba3ed4e7eb Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6789
diff changeset
1156 {
0fba3ed4e7eb Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6789
diff changeset
1157 return NGX_OK;
0fba3ed4e7eb Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6789
diff changeset
1158 }
0fba3ed4e7eb Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6789
diff changeset
1159
0fba3ed4e7eb Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6789
diff changeset
1160 if (u->conf->cache_max_range_offset == 0) {
0fba3ed4e7eb Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6789
diff changeset
1161 return NGX_DECLINED;
0fba3ed4e7eb Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6789
diff changeset
1162 }
0fba3ed4e7eb Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6789
diff changeset
1163
0fba3ed4e7eb Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6789
diff changeset
1164 if (h->value.len < 7
0fba3ed4e7eb Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6789
diff changeset
1165 || ngx_strncasecmp(h->value.data, (u_char *) "bytes=", 6) != 0)
0fba3ed4e7eb Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6789
diff changeset
1166 {
0fba3ed4e7eb Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6789
diff changeset
1167 return NGX_OK;
0fba3ed4e7eb Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6789
diff changeset
1168 }
0fba3ed4e7eb Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6789
diff changeset
1169
0fba3ed4e7eb Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6789
diff changeset
1170 p = h->value.data + 6;
0fba3ed4e7eb Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6789
diff changeset
1171
0fba3ed4e7eb Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6789
diff changeset
1172 while (*p == ' ') { p++; }
0fba3ed4e7eb Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6789
diff changeset
1173
0fba3ed4e7eb Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6789
diff changeset
1174 if (*p == '-') {
0fba3ed4e7eb Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6789
diff changeset
1175 return NGX_DECLINED;
0fba3ed4e7eb Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6789
diff changeset
1176 }
0fba3ed4e7eb Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6789
diff changeset
1177
0fba3ed4e7eb Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6789
diff changeset
1178 start = p;
0fba3ed4e7eb Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6789
diff changeset
1179
0fba3ed4e7eb Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6789
diff changeset
1180 while (*p >= '0' && *p <= '9') { p++; }
0fba3ed4e7eb Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6789
diff changeset
1181
0fba3ed4e7eb Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6789
diff changeset
1182 offset = ngx_atoof(start, p - start);
0fba3ed4e7eb Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6789
diff changeset
1183
0fba3ed4e7eb Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6789
diff changeset
1184 if (offset >= u->conf->cache_max_range_offset) {
0fba3ed4e7eb Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6789
diff changeset
1185 return NGX_DECLINED;
0fba3ed4e7eb Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6789
diff changeset
1186 }
0fba3ed4e7eb Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6789
diff changeset
1187
0fba3ed4e7eb Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6789
diff changeset
1188 return NGX_OK;
0fba3ed4e7eb Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6789
diff changeset
1189 }
0fba3ed4e7eb Cache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6789
diff changeset
1190
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
1191 #endif
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
1192
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
1193
487
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 485
diff changeset
1194 static void
1658
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
1195 ngx_http_upstream_resolve_handler(ngx_resolver_ctx_t *ctx)
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
1196 {
7041
6169dbad37d8 Upstream: fixed running posted requests (ticket #788).
Roman Arutyunyan <arut@nginx.com>
parents: 7018
diff changeset
1197 ngx_uint_t run_posted;
5113
08b36f2afc3f Upstream: fixed previous commit.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5112
diff changeset
1198 ngx_connection_t *c;
1658
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
1199 ngx_http_request_t *r;
3169
b1013d768911 fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents: 3161
diff changeset
1200 ngx_http_upstream_t *u;
1658
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
1201 ngx_http_upstream_resolved_t *ur;
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
1202
7041
6169dbad37d8 Upstream: fixed running posted requests (ticket #788).
Roman Arutyunyan <arut@nginx.com>
parents: 7018
diff changeset
1203 run_posted = ctx->async;
6169dbad37d8 Upstream: fixed running posted requests (ticket #788).
Roman Arutyunyan <arut@nginx.com>
parents: 7018
diff changeset
1204
1658
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
1205 r = ctx->data;
5113
08b36f2afc3f Upstream: fixed previous commit.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5112
diff changeset
1206 c = r->connection;
1658
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
1207
3169
b1013d768911 fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents: 3161
diff changeset
1208 u = r->upstream;
b1013d768911 fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents: 3161
diff changeset
1209 ur = u->resolved;
1658
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
1210
5928
8dfee01ff0bd Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5911
diff changeset
1211 ngx_http_set_log_request(c->log, r);
8dfee01ff0bd Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5911
diff changeset
1212
8dfee01ff0bd Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5911
diff changeset
1213 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
8dfee01ff0bd Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5911
diff changeset
1214 "http upstream resolve: \"%V?%V\"", &r->uri, &r->args);
8dfee01ff0bd Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5911
diff changeset
1215
1658
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
1216 if (ctx->state) {
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
1217 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
1218 "%V could not be resolved (%i: %s)",
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
1219 &ctx->name, ctx->state,
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
1220 ngx_resolver_strerror(ctx->state));
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
1221
3169
b1013d768911 fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents: 3161
diff changeset
1222 ngx_http_upstream_finalize_request(r, u, NGX_HTTP_BAD_GATEWAY);
5112
d3c15c7831eb Upstream: call ngx_http_run_posted_requests() on resolve errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5104
diff changeset
1223 goto failed;
1658
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
1224 }
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
1225
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
1226 ur->naddrs = ctx->naddrs;
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
1227 ur->addrs = ctx->addrs;
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
1228
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
1229 #if (NGX_DEBUG)
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
1230 {
5475
07dd5bd222ac Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents: 5453
diff changeset
1231 u_char text[NGX_SOCKADDR_STRLEN];
07dd5bd222ac Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents: 5453
diff changeset
1232 ngx_str_t addr;
1658
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
1233 ngx_uint_t i;
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
1234
5475
07dd5bd222ac Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents: 5453
diff changeset
1235 addr.data = text;
07dd5bd222ac Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents: 5453
diff changeset
1236
1658
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
1237 for (i = 0; i < ctx->naddrs; i++) {
5475
07dd5bd222ac Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents: 5453
diff changeset
1238 addr.len = ngx_sock_ntop(ur->addrs[i].sockaddr, ur->addrs[i].socklen,
07dd5bd222ac Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents: 5453
diff changeset
1239 text, NGX_SOCKADDR_STRLEN, 0);
07dd5bd222ac Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents: 5453
diff changeset
1240
07dd5bd222ac Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents: 5453
diff changeset
1241 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
07dd5bd222ac Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents: 5453
diff changeset
1242 "name was resolved to %V", &addr);
1658
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
1243 }
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
1244 }
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
1245 #endif
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
1246
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
1247 if (ngx_http_upstream_create_round_robin_peer(r, ur) != NGX_OK) {
3169
b1013d768911 fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents: 3161
diff changeset
1248 ngx_http_upstream_finalize_request(r, u,
b1013d768911 fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents: 3161
diff changeset
1249 NGX_HTTP_INTERNAL_SERVER_ERROR);
5112
d3c15c7831eb Upstream: call ngx_http_run_posted_requests() on resolve errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5104
diff changeset
1250 goto failed;
1658
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
1251 }
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
1252
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
1253 ngx_resolve_name_done(ctx);
3169
b1013d768911 fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents: 3161
diff changeset
1254 ur->ctx = NULL;
b1013d768911 fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents: 3161
diff changeset
1255
5885
5a042519bfe7 Upstream: limited next_upstream time and tries when resolving DNS.
Gu Feng <flygoast@126.com>
parents: 5883
diff changeset
1256 u->peer.start_time = ngx_current_msec;
5a042519bfe7 Upstream: limited next_upstream time and tries when resolving DNS.
Gu Feng <flygoast@126.com>
parents: 5883
diff changeset
1257
5a042519bfe7 Upstream: limited next_upstream time and tries when resolving DNS.
Gu Feng <flygoast@126.com>
parents: 5883
diff changeset
1258 if (u->conf->next_upstream_tries
5a042519bfe7 Upstream: limited next_upstream time and tries when resolving DNS.
Gu Feng <flygoast@126.com>
parents: 5883
diff changeset
1259 && u->peer.tries > u->conf->next_upstream_tries)
5a042519bfe7 Upstream: limited next_upstream time and tries when resolving DNS.
Gu Feng <flygoast@126.com>
parents: 5883
diff changeset
1260 {
5a042519bfe7 Upstream: limited next_upstream time and tries when resolving DNS.
Gu Feng <flygoast@126.com>
parents: 5883
diff changeset
1261 u->peer.tries = u->conf->next_upstream_tries;
5a042519bfe7 Upstream: limited next_upstream time and tries when resolving DNS.
Gu Feng <flygoast@126.com>
parents: 5883
diff changeset
1262 }
5a042519bfe7 Upstream: limited next_upstream time and tries when resolving DNS.
Gu Feng <flygoast@126.com>
parents: 5883
diff changeset
1263
3169
b1013d768911 fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents: 3161
diff changeset
1264 ngx_http_upstream_connect(r, u);
5112
d3c15c7831eb Upstream: call ngx_http_run_posted_requests() on resolve errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5104
diff changeset
1265
d3c15c7831eb Upstream: call ngx_http_run_posted_requests() on resolve errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5104
diff changeset
1266 failed:
d3c15c7831eb Upstream: call ngx_http_run_posted_requests() on resolve errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5104
diff changeset
1267
7041
6169dbad37d8 Upstream: fixed running posted requests (ticket #788).
Roman Arutyunyan <arut@nginx.com>
parents: 7018
diff changeset
1268 if (run_posted) {
6169dbad37d8 Upstream: fixed running posted requests (ticket #788).
Roman Arutyunyan <arut@nginx.com>
parents: 7018
diff changeset
1269 ngx_http_run_posted_requests(c);
6169dbad37d8 Upstream: fixed running posted requests (ticket #788).
Roman Arutyunyan <arut@nginx.com>
parents: 7018
diff changeset
1270 }
1658
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
1271 }
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
1272
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
1273
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
1274 static void
2377
87b8c44906b5 *) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents: 2360
diff changeset
1275 ngx_http_upstream_handler(ngx_event_t *ev)
87b8c44906b5 *) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents: 2360
diff changeset
1276 {
87b8c44906b5 *) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents: 2360
diff changeset
1277 ngx_connection_t *c;
87b8c44906b5 *) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents: 2360
diff changeset
1278 ngx_http_request_t *r;
87b8c44906b5 *) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents: 2360
diff changeset
1279 ngx_http_upstream_t *u;
87b8c44906b5 *) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents: 2360
diff changeset
1280
87b8c44906b5 *) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents: 2360
diff changeset
1281 c = ev->data;
87b8c44906b5 *) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents: 2360
diff changeset
1282 r = c->data;
87b8c44906b5 *) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents: 2360
diff changeset
1283
87b8c44906b5 *) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents: 2360
diff changeset
1284 u = r->upstream;
87b8c44906b5 *) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents: 2360
diff changeset
1285 c = r->connection;
87b8c44906b5 *) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents: 2360
diff changeset
1286
5928
8dfee01ff0bd Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5911
diff changeset
1287 ngx_http_set_log_request(c->log, r);
2377
87b8c44906b5 *) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents: 2360
diff changeset
1288
87b8c44906b5 *) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents: 2360
diff changeset
1289 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
87b8c44906b5 *) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents: 2360
diff changeset
1290 "http upstream request: \"%V?%V\"", &r->uri, &r->args);
87b8c44906b5 *) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents: 2360
diff changeset
1291
6961
903fb1ddc07f Moved handling of wev->delayed to the connection event handler.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6950
diff changeset
1292 if (ev->delayed && ev->timedout) {
903fb1ddc07f Moved handling of wev->delayed to the connection event handler.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6950
diff changeset
1293 ev->delayed = 0;
903fb1ddc07f Moved handling of wev->delayed to the connection event handler.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6950
diff changeset
1294 ev->timedout = 0;
903fb1ddc07f Moved handling of wev->delayed to the connection event handler.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6950
diff changeset
1295 }
903fb1ddc07f Moved handling of wev->delayed to the connection event handler.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6950
diff changeset
1296
2377
87b8c44906b5 *) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents: 2360
diff changeset
1297 if (ev->write) {
2386
4ccaa42de633 use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents: 2381
diff changeset
1298 u->write_event_handler(r, u);
2377
87b8c44906b5 *) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents: 2360
diff changeset
1299
87b8c44906b5 *) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents: 2360
diff changeset
1300 } else {
2386
4ccaa42de633 use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents: 2381
diff changeset
1301 u->read_event_handler(r, u);
2377
87b8c44906b5 *) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents: 2360
diff changeset
1302 }
87b8c44906b5 *) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents: 2360
diff changeset
1303
87b8c44906b5 *) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents: 2360
diff changeset
1304 ngx_http_run_posted_requests(c);
87b8c44906b5 *) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents: 2360
diff changeset
1305 }
87b8c44906b5 *) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents: 2360
diff changeset
1306
87b8c44906b5 *) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents: 2360
diff changeset
1307
87b8c44906b5 *) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents: 2360
diff changeset
1308 static void
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
1309 ngx_http_upstream_rd_check_broken_connection(ngx_http_request_t *r)
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
1310 {
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
1311 ngx_http_upstream_check_broken_connection(r, r->connection->read);
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
1312 }
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
1313
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
1314
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
1315 static void
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
1316 ngx_http_upstream_wr_check_broken_connection(ngx_http_request_t *r)
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
1317 {
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
1318 ngx_http_upstream_check_broken_connection(r, r->connection->write);
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
1319 }
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
1320
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
1321
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
1322 static void
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
1323 ngx_http_upstream_check_broken_connection(ngx_http_request_t *r,
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
1324 ngx_event_t *ev)
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1325 {
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1326 int n;
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1327 char buf[1];
577
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
1328 ngx_err_t err;
2807
6ad4bba6313e delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents: 2805
diff changeset
1329 ngx_int_t event;
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1330 ngx_connection_t *c;
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1331 ngx_http_upstream_t *u;
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1332
527
7fa11e5c6e96 nginx-0.1.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 525
diff changeset
1333 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, ev->log, 0,
7fa11e5c6e96 nginx-0.1.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 525
diff changeset
1334 "http upstream check client, write event:%d, \"%V\"",
7fa11e5c6e96 nginx-0.1.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 525
diff changeset
1335 ev->write, &r->uri);
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1336
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
1337 c = r->connection;
483
621229427cba nginx-0.1.16-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 481
diff changeset
1338 u = r->upstream;
621229427cba nginx-0.1.16-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 481
diff changeset
1339
583
4e296b7d25bf nginx-0.3.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 581
diff changeset
1340 if (c->error) {
2807
6ad4bba6313e delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents: 2805
diff changeset
1341 if ((ngx_event_flags & NGX_USE_LEVEL_EVENT) && ev->active) {
6ad4bba6313e delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents: 2805
diff changeset
1342
6ad4bba6313e delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents: 2805
diff changeset
1343 event = ev->write ? NGX_WRITE_EVENT : NGX_READ_EVENT;
6ad4bba6313e delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents: 2805
diff changeset
1344
6ad4bba6313e delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents: 2805
diff changeset
1345 if (ngx_del_event(ev, event, 0) != NGX_OK) {
6ad4bba6313e delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents: 2805
diff changeset
1346 ngx_http_upstream_finalize_request(r, u,
6ad4bba6313e delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents: 2805
diff changeset
1347 NGX_HTTP_INTERNAL_SERVER_ERROR);
6ad4bba6313e delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents: 2805
diff changeset
1348 return;
6ad4bba6313e delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents: 2805
diff changeset
1349 }
6ad4bba6313e delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents: 2805
diff changeset
1350 }
6ad4bba6313e delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents: 2805
diff changeset
1351
2757
9cc973b46af1 get a full response if the response is cacheable or storable even
Igor Sysoev <igor@sysoev.ru>
parents: 2708
diff changeset
1352 if (!u->cacheable) {
9cc973b46af1 get a full response if the response is cacheable or storable even
Igor Sysoev <igor@sysoev.ru>
parents: 2708
diff changeset
1353 ngx_http_upstream_finalize_request(r, u,
9cc973b46af1 get a full response if the response is cacheable or storable even
Igor Sysoev <igor@sysoev.ru>
parents: 2708
diff changeset
1354 NGX_HTTP_CLIENT_CLOSED_REQUEST);
9cc973b46af1 get a full response if the response is cacheable or storable even
Igor Sysoev <igor@sysoev.ru>
parents: 2708
diff changeset
1355 }
2807
6ad4bba6313e delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents: 2805
diff changeset
1356
527
7fa11e5c6e96 nginx-0.1.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 525
diff changeset
1357 return;
7fa11e5c6e96 nginx-0.1.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 525
diff changeset
1358 }
7fa11e5c6e96 nginx-0.1.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 525
diff changeset
1359
6246
257b51c37c5a The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents: 6242
diff changeset
1360 #if (NGX_HTTP_V2)
257b51c37c5a The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents: 6242
diff changeset
1361 if (r->stream) {
5121
c0f7b94e88ba Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents: 5113
diff changeset
1362 return;
c0f7b94e88ba Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents: 5113
diff changeset
1363 }
c0f7b94e88ba Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents: 5113
diff changeset
1364 #endif
c0f7b94e88ba Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents: 5113
diff changeset
1365
8921
33226ac61076 HTTP/3: merged ngx_http_quic_module into ngx_http_v3_module.
Roman Arutyunyan <arut@nginx.com>
parents: 8889
diff changeset
1366 #if (NGX_HTTP_V3)
8521
a748095bf94e HTTP/3: special handling of client errors in the upstream module.
Roman Arutyunyan <arut@nginx.com>
parents: 7679
diff changeset
1367
8630
279ad36f2f4b QUIC: renamed c->qs to c->quic.
Roman Arutyunyan <arut@nginx.com>
parents: 8584
diff changeset
1368 if (c->quic) {
8521
a748095bf94e HTTP/3: special handling of client errors in the upstream module.
Roman Arutyunyan <arut@nginx.com>
parents: 7679
diff changeset
1369 if (c->write->error) {
a748095bf94e HTTP/3: special handling of client errors in the upstream module.
Roman Arutyunyan <arut@nginx.com>
parents: 7679
diff changeset
1370 ngx_http_upstream_finalize_request(r, u,
a748095bf94e HTTP/3: special handling of client errors in the upstream module.
Roman Arutyunyan <arut@nginx.com>
parents: 7679
diff changeset
1371 NGX_HTTP_CLIENT_CLOSED_REQUEST);
a748095bf94e HTTP/3: special handling of client errors in the upstream module.
Roman Arutyunyan <arut@nginx.com>
parents: 7679
diff changeset
1372 }
a748095bf94e HTTP/3: special handling of client errors in the upstream module.
Roman Arutyunyan <arut@nginx.com>
parents: 7679
diff changeset
1373
a748095bf94e HTTP/3: special handling of client errors in the upstream module.
Roman Arutyunyan <arut@nginx.com>
parents: 7679
diff changeset
1374 return;
a748095bf94e HTTP/3: special handling of client errors in the upstream module.
Roman Arutyunyan <arut@nginx.com>
parents: 7679
diff changeset
1375 }
a748095bf94e HTTP/3: special handling of client errors in the upstream module.
Roman Arutyunyan <arut@nginx.com>
parents: 7679
diff changeset
1376
a748095bf94e HTTP/3: special handling of client errors in the upstream module.
Roman Arutyunyan <arut@nginx.com>
parents: 7679
diff changeset
1377 #endif
a748095bf94e HTTP/3: special handling of client errors in the upstream module.
Roman Arutyunyan <arut@nginx.com>
parents: 7679
diff changeset
1378
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1379 #if (NGX_HAVE_KQUEUE)
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1380
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1381 if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) {
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1382
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1383 if (!ev->pending_eof) {
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1384 return;
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1385 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1386
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1387 ev->eof = 1;
583
4e296b7d25bf nginx-0.3.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 581
diff changeset
1388 c->error = 1;
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1389
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1390 if (ev->kq_errno) {
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1391 ev->error = 1;
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1392 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1393
2757
9cc973b46af1 get a full response if the response is cacheable or storable even
Igor Sysoev <igor@sysoev.ru>
parents: 2708
diff changeset
1394 if (!u->cacheable && u->peer.connection) {
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1395 ngx_log_error(NGX_LOG_INFO, ev->log, ev->kq_errno,
4182
75d2388bd6b9 Tweaked error messages.
Ruslan Ermilov <ru@nginx.com>
parents: 4176
diff changeset
1396 "kevent() reported that client prematurely closed "
527
7fa11e5c6e96 nginx-0.1.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 525
diff changeset
1397 "connection, so upstream connection is closed too");
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1398 ngx_http_upstream_finalize_request(r, u,
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1399 NGX_HTTP_CLIENT_CLOSED_REQUEST);
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1400 return;
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1401 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1402
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1403 ngx_log_error(NGX_LOG_INFO, ev->log, ev->kq_errno,
4182
75d2388bd6b9 Tweaked error messages.
Ruslan Ermilov <ru@nginx.com>
parents: 4176
diff changeset
1404 "kevent() reported that client prematurely closed "
75d2388bd6b9 Tweaked error messages.
Ruslan Ermilov <ru@nginx.com>
parents: 4176
diff changeset
1405 "connection");
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1406
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1407 if (u->peer.connection == NULL) {
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1408 ngx_http_upstream_finalize_request(r, u,
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1409 NGX_HTTP_CLIENT_CLOSED_REQUEST);
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1410 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1411
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1412 return;
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1413 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1414
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1415 #endif
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1416
5373
46bdbca10dfc Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents: 5368
diff changeset
1417 #if (NGX_HAVE_EPOLLRDHUP)
46bdbca10dfc Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents: 5368
diff changeset
1418
6536
f7849bfb6d21 Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents: 6530
diff changeset
1419 if ((ngx_event_flags & NGX_USE_EPOLL_EVENT) && ngx_use_epoll_rdhup) {
5373
46bdbca10dfc Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents: 5368
diff changeset
1420 socklen_t len;
46bdbca10dfc Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents: 5368
diff changeset
1421
6536
f7849bfb6d21 Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents: 6530
diff changeset
1422 if (!ev->pending_eof) {
f7849bfb6d21 Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents: 6530
diff changeset
1423 return;
f7849bfb6d21 Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents: 6530
diff changeset
1424 }
f7849bfb6d21 Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents: 6530
diff changeset
1425
5373
46bdbca10dfc Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents: 5368
diff changeset
1426 ev->eof = 1;
46bdbca10dfc Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents: 5368
diff changeset
1427 c->error = 1;
46bdbca10dfc Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents: 5368
diff changeset
1428
46bdbca10dfc Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents: 5368
diff changeset
1429 err = 0;
46bdbca10dfc Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents: 5368
diff changeset
1430 len = sizeof(ngx_err_t);
46bdbca10dfc Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents: 5368
diff changeset
1431
46bdbca10dfc Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents: 5368
diff changeset
1432 /*
46bdbca10dfc Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents: 5368
diff changeset
1433 * BSDs and Linux return 0 and set a pending error in err
46bdbca10dfc Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents: 5368
diff changeset
1434 * Solaris returns -1 and sets errno
46bdbca10dfc Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents: 5368
diff changeset
1435 */
46bdbca10dfc Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents: 5368
diff changeset
1436
46bdbca10dfc Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents: 5368
diff changeset
1437 if (getsockopt(c->fd, SOL_SOCKET, SO_ERROR, (void *) &err, &len)
46bdbca10dfc Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents: 5368
diff changeset
1438 == -1)
46bdbca10dfc Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents: 5368
diff changeset
1439 {
5557
188481078faf Use ngx_socket_errno where appropriate.
Piotr Sikora <piotr@cloudflare.com>
parents: 5546
diff changeset
1440 err = ngx_socket_errno;
5373
46bdbca10dfc Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents: 5368
diff changeset
1441 }
46bdbca10dfc Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents: 5368
diff changeset
1442
46bdbca10dfc Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents: 5368
diff changeset
1443 if (err) {
46bdbca10dfc Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents: 5368
diff changeset
1444 ev->error = 1;
46bdbca10dfc Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents: 5368
diff changeset
1445 }
46bdbca10dfc Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents: 5368
diff changeset
1446
46bdbca10dfc Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents: 5368
diff changeset
1447 if (!u->cacheable && u->peer.connection) {
46bdbca10dfc Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents: 5368
diff changeset
1448 ngx_log_error(NGX_LOG_INFO, ev->log, err,
46bdbca10dfc Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents: 5368
diff changeset
1449 "epoll_wait() reported that client prematurely closed "
46bdbca10dfc Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents: 5368
diff changeset
1450 "connection, so upstream connection is closed too");
46bdbca10dfc Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents: 5368
diff changeset
1451 ngx_http_upstream_finalize_request(r, u,
46bdbca10dfc Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents: 5368
diff changeset
1452 NGX_HTTP_CLIENT_CLOSED_REQUEST);
46bdbca10dfc Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents: 5368
diff changeset
1453 return;
46bdbca10dfc Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents: 5368
diff changeset
1454 }
46bdbca10dfc Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents: 5368
diff changeset
1455
46bdbca10dfc Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents: 5368
diff changeset
1456 ngx_log_error(NGX_LOG_INFO, ev->log, err,
46bdbca10dfc Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents: 5368
diff changeset
1457 "epoll_wait() reported that client prematurely closed "
46bdbca10dfc Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents: 5368
diff changeset
1458 "connection");
46bdbca10dfc Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents: 5368
diff changeset
1459
46bdbca10dfc Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents: 5368
diff changeset
1460 if (u->peer.connection == NULL) {
46bdbca10dfc Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents: 5368
diff changeset
1461 ngx_http_upstream_finalize_request(r, u,
46bdbca10dfc Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents: 5368
diff changeset
1462 NGX_HTTP_CLIENT_CLOSED_REQUEST);
46bdbca10dfc Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents: 5368
diff changeset
1463 }
46bdbca10dfc Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents: 5368
diff changeset
1464
46bdbca10dfc Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents: 5368
diff changeset
1465 return;
46bdbca10dfc Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents: 5368
diff changeset
1466 }
46bdbca10dfc Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents: 5368
diff changeset
1467
46bdbca10dfc Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents: 5368
diff changeset
1468 #endif
46bdbca10dfc Upstream: use EPOLLRDHUP to check broken connections (ticket #320).
Valentin Bartenev <vbart@nginx.com>
parents: 5368
diff changeset
1469
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1470 n = recv(c->fd, buf, 1, MSG_PEEK);
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1471
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1472 err = ngx_socket_errno;
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1473
1109
1402dbb554c4 add debug logging
Igor Sysoev <igor@sysoev.ru>
parents: 1107
diff changeset
1474 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ev->log, err,
1402dbb554c4 add debug logging
Igor Sysoev <igor@sysoev.ru>
parents: 1107
diff changeset
1475 "http upstream recv(): %d", n);
1402dbb554c4 add debug logging
Igor Sysoev <igor@sysoev.ru>
parents: 1107
diff changeset
1476
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1477 if (ev->write && (n >= 0 || err == NGX_EAGAIN)) {
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1478 return;
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1479 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1480
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1481 if ((ngx_event_flags & NGX_USE_LEVEL_EVENT) && ev->active) {
2807
6ad4bba6313e delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents: 2805
diff changeset
1482
6ad4bba6313e delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents: 2805
diff changeset
1483 event = ev->write ? NGX_WRITE_EVENT : NGX_READ_EVENT;
6ad4bba6313e delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents: 2805
diff changeset
1484
6ad4bba6313e delete level event of appropriate type, this should fix select()'s EBADF,
Igor Sysoev <igor@sysoev.ru>
parents: 2805
diff changeset
1485 if (ngx_del_event(ev, event, 0) != NGX_OK) {
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1486 ngx_http_upstream_finalize_request(r, u,
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1487 NGX_HTTP_INTERNAL_SERVER_ERROR);
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1488 return;
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1489 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1490 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1491
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1492 if (n > 0) {
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1493 return;
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1494 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1495
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1496 if (n == -1) {
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1497 if (err == NGX_EAGAIN) {
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1498 return;
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1499 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1500
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1501 ev->error = 1;
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1502
483
621229427cba nginx-0.1.16-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 481
diff changeset
1503 } else { /* n == 0 */
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1504 err = 0;
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1505 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1506
529
e5d7d0334fdb nginx-0.1.39-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 527
diff changeset
1507 ev->eof = 1;
583
4e296b7d25bf nginx-0.3.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 581
diff changeset
1508 c->error = 1;
529
e5d7d0334fdb nginx-0.1.39-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 527
diff changeset
1509
2757
9cc973b46af1 get a full response if the response is cacheable or storable even
Igor Sysoev <igor@sysoev.ru>
parents: 2708
diff changeset
1510 if (!u->cacheable && u->peer.connection) {
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1511 ngx_log_error(NGX_LOG_INFO, ev->log, err,
4182
75d2388bd6b9 Tweaked error messages.
Ruslan Ermilov <ru@nginx.com>
parents: 4176
diff changeset
1512 "client prematurely closed connection, "
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1513 "so upstream connection is closed too");
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1514 ngx_http_upstream_finalize_request(r, u,
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1515 NGX_HTTP_CLIENT_CLOSED_REQUEST);
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1516 return;
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1517 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1518
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1519 ngx_log_error(NGX_LOG_INFO, ev->log, err,
4182
75d2388bd6b9 Tweaked error messages.
Ruslan Ermilov <ru@nginx.com>
parents: 4176
diff changeset
1520 "client prematurely closed connection");
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1521
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1522 if (u->peer.connection == NULL) {
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1523 ngx_http_upstream_finalize_request(r, u,
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1524 NGX_HTTP_CLIENT_CLOSED_REQUEST);
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1525 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1526 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1527
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1528
487
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 485
diff changeset
1529 static void
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 485
diff changeset
1530 ngx_http_upstream_connect(ngx_http_request_t *r, ngx_http_upstream_t *u)
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1531 {
7949
862f6130d357 Upstream: sendfile_max_chunk support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7941
diff changeset
1532 ngx_int_t rc;
862f6130d357 Upstream: sendfile_max_chunk support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7941
diff changeset
1533 ngx_connection_t *c;
862f6130d357 Upstream: sendfile_max_chunk support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7941
diff changeset
1534 ngx_http_core_loc_conf_t *clcf;
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1535
483
621229427cba nginx-0.1.16-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 481
diff changeset
1536 r->connection->log->action = "connecting to upstream";
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1537
7397
860d3907da1c Upstream: revised upstream response time variables.
Vladimir Homutov <vl@nginx.com>
parents: 7371
diff changeset
1538 if (u->state && u->state->response_time == (ngx_msec_t) -1) {
860d3907da1c Upstream: revised upstream response time variables.
Vladimir Homutov <vl@nginx.com>
parents: 7371
diff changeset
1539 u->state->response_time = ngx_current_msec - u->start_time;
665
5fd7a5e99047 nginx-0.3.54-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 663
diff changeset
1540 }
5fd7a5e99047 nginx-0.3.54-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 663
diff changeset
1541
1168
4d0d12446c3b store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents: 1166
diff changeset
1542 u->state = ngx_array_push(r->upstream_states);
665
5fd7a5e99047 nginx-0.3.54-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 663
diff changeset
1543 if (u->state == NULL) {
5fd7a5e99047 nginx-0.3.54-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 663
diff changeset
1544 ngx_http_upstream_finalize_request(r, u,
5fd7a5e99047 nginx-0.3.54-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 663
diff changeset
1545 NGX_HTTP_INTERNAL_SERVER_ERROR);
5fd7a5e99047 nginx-0.3.54-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 663
diff changeset
1546 return;
5fd7a5e99047 nginx-0.3.54-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 663
diff changeset
1547 }
5fd7a5e99047 nginx-0.3.54-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 663
diff changeset
1548
5fd7a5e99047 nginx-0.3.54-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 663
diff changeset
1549 ngx_memzero(u->state, sizeof(ngx_http_upstream_state_t));
5fd7a5e99047 nginx-0.3.54-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 663
diff changeset
1550
7397
860d3907da1c Upstream: revised upstream response time variables.
Vladimir Homutov <vl@nginx.com>
parents: 7371
diff changeset
1551 u->start_time = ngx_current_msec;
860d3907da1c Upstream: revised upstream response time variables.
Vladimir Homutov <vl@nginx.com>
parents: 7371
diff changeset
1552
860d3907da1c Upstream: revised upstream response time variables.
Vladimir Homutov <vl@nginx.com>
parents: 7371
diff changeset
1553 u->state->response_time = (ngx_msec_t) -1;
6147
74b6ef56ea56 Upstream: $upstream_connect_time.
Ruslan Ermilov <ru@nginx.com>
parents: 6146
diff changeset
1554 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
1555 u->state->header_time = (ngx_msec_t) -1;
665
5fd7a5e99047 nginx-0.3.54-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 663
diff changeset
1556
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1557 rc = ngx_event_connect_peer(&u->peer);
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1558
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1559 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1560 "http upstream connect: %i", rc);
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1561
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1562 if (rc == NGX_ERROR) {
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1563 ngx_http_upstream_finalize_request(r, u,
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1564 NGX_HTTP_INTERNAL_SERVER_ERROR);
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1565 return;
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1566 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1567
1707
f3188f6eae1f $upstream_addr did not contain last address, the bug was introduced in r1659
Igor Sysoev <igor@sysoev.ru>
parents: 1706
diff changeset
1568 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
1569
543
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
1570 if (rc == NGX_BUSY) {
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
1571 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "no live upstreams");
1378
0be898896d1a backup upstream servers
Igor Sysoev <igor@sysoev.ru>
parents: 1340
diff changeset
1572 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_NOLIVE);
0be898896d1a backup upstream servers
Igor Sysoev <igor@sysoev.ru>
parents: 1340
diff changeset
1573 return;
543
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
1574 }
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
1575
1378
0be898896d1a backup upstream servers
Igor Sysoev <igor@sysoev.ru>
parents: 1340
diff changeset
1576 if (rc == NGX_DECLINED) {
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1577 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR);
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1578 return;
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1579 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1580
5261
af60a210cb78 Upstream: updated list of ngx_event_connect_peer() return values.
Ruslan Ermilov <ru@nginx.com>
parents: 5231
diff changeset
1581 /* rc == NGX_OK || rc == NGX_AGAIN || rc == NGX_DONE */
577
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
1582
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1583 c = u->peer.connection;
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1584
7340
70c6b08973a0 Upstream keepalive: keepalive_requests directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7320
diff changeset
1585 c->requests++;
70c6b08973a0 Upstream keepalive: keepalive_requests directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7320
diff changeset
1586
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1587 c->data = r;
591
8c0cdd81580e nginx-0.3.17-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 589
diff changeset
1588
2377
87b8c44906b5 *) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents: 2360
diff changeset
1589 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
1590 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
1591
87b8c44906b5 *) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents: 2360
diff changeset
1592 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
1593 u->read_event_handler = ngx_http_upstream_process_header;
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1594
1397
6c25a49e548a upstream sendfile bit was overridden by r->connection->sendfile
Igor Sysoev <igor@sysoev.ru>
parents: 1378
diff changeset
1595 c->sendfile &= r->connection->sendfile;
1958
3e9e4581fbba fix peer sendfile capability
Igor Sysoev <igor@sysoev.ru>
parents: 1947
diff changeset
1596 u->output.sendfile = c->sendfile;
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1597
7306
8eab05b83dde Upstream: fixed unexpected tcp_nopush usage on peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7297
diff changeset
1598 if (r->connection->tcp_nopush == NGX_TCP_NOPUSH_DISABLED) {
8eab05b83dde Upstream: fixed unexpected tcp_nopush usage on peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7297
diff changeset
1599 c->tcp_nopush = NGX_TCP_NOPUSH_DISABLED;
8eab05b83dde Upstream: fixed unexpected tcp_nopush usage on peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7297
diff changeset
1600 }
8eab05b83dde Upstream: fixed unexpected tcp_nopush usage on peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7297
diff changeset
1601
4116
9baf12ea5ca1 Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4115
diff changeset
1602 if (c->pool == NULL) {
9baf12ea5ca1 Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4115
diff changeset
1603
9baf12ea5ca1 Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4115
diff changeset
1604 /* 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
1605
9baf12ea5ca1 Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4115
diff changeset
1606 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
1607 if (c->pool == NULL) {
9baf12ea5ca1 Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4115
diff changeset
1608 ngx_http_upstream_finalize_request(r, u,
9baf12ea5ca1 Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4115
diff changeset
1609 NGX_HTTP_INTERNAL_SERVER_ERROR);
9baf12ea5ca1 Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4115
diff changeset
1610 return;
9baf12ea5ca1 Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4115
diff changeset
1611 }
9baf12ea5ca1 Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4115
diff changeset
1612 }
9baf12ea5ca1 Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4115
diff changeset
1613
2847
3e10674139e4 style fix
Igor Sysoev <igor@sysoev.ru>
parents: 2824
diff changeset
1614 c->log = r->connection->log;
4116
9baf12ea5ca1 Upstream: separate pool for peer connections.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4115
diff changeset
1615 c->pool->log = c->log;
2847
3e10674139e4 style fix
Igor Sysoev <igor@sysoev.ru>
parents: 2824
diff changeset
1616 c->read->log = c->log;
3e10674139e4 style fix
Igor Sysoev <igor@sysoev.ru>
parents: 2824
diff changeset
1617 c->write->log = c->log;
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1618
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1619 /* init or reinit the ngx_output_chain() and ngx_chain_writer() contexts */
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1620
7949
862f6130d357 Upstream: sendfile_max_chunk support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7941
diff changeset
1621 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
862f6130d357 Upstream: sendfile_max_chunk support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7941
diff changeset
1622
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1623 u->writer.out = NULL;
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1624 u->writer.last = &u->writer.out;
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1625 u->writer.connection = c;
7949
862f6130d357 Upstream: sendfile_max_chunk support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7941
diff changeset
1626 u->writer.limit = clcf->sendfile_max_chunk;
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1627
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1628 if (u->request_sent) {
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
1629 if (ngx_http_upstream_reinit(r, u) != NGX_OK) {
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
1630 ngx_http_upstream_finalize_request(r, u,
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
1631 NGX_HTTP_INTERNAL_SERVER_ERROR);
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
1632 return;
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
1633 }
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1634 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1635
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
1636 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
1637 && 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
1638 && 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
1639 && 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
1640 {
573
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
1641 /*
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
1642 * 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
1643 * the subrequests should allocate their own temporary bufs
573
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
1644 */
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
1645
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
1646 u->output.free = ngx_alloc_chain_link(r->pool);
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
1647 if (u->output.free == NULL) {
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
1648 ngx_http_upstream_finalize_request(r, u,
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
1649 NGX_HTTP_INTERNAL_SERVER_ERROR);
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
1650 return;
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1651 }
573
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
1652
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
1653 u->output.free->buf = r->request_body->buf;
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
1654 u->output.free->next = NULL;
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
1655 u->output.allocated = 1;
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
1656
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
1657 r->request_body->buf->pos = r->request_body->buf->start;
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
1658 r->request_body->buf->last = r->request_body->buf->start;
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
1659 r->request_body->buf->tag = u->output.tag;
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1660 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1661
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1662 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
1663 u->request_body_sent = 0;
7231
22f7bdbd96d3 Upstream: u->request_body_blocked flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7230
diff changeset
1664 u->request_body_blocked = 0;
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1665
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1666 if (rc == NGX_AGAIN) {
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1667 ngx_add_timer(c->write, u->conf->connect_timeout);
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1668 return;
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1669 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1670
577
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
1671 #if (NGX_HTTP_SSL)
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
1672
1658
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
1673 if (u->ssl && c->ssl == NULL) {
591
8c0cdd81580e nginx-0.3.17-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 589
diff changeset
1674 ngx_http_upstream_ssl_init_connection(r, u, c);
577
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
1675 return;
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
1676 }
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
1677
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
1678 #endif
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
1679
6050
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
1680 ngx_http_upstream_send_request(r, u, 1);
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1681 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1682
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1683
577
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
1684 #if (NGX_HTTP_SSL)
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
1685
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
1686 static void
591
8c0cdd81580e nginx-0.3.17-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 589
diff changeset
1687 ngx_http_upstream_ssl_init_connection(ngx_http_request_t *r,
8c0cdd81580e nginx-0.3.17-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 589
diff changeset
1688 ngx_http_upstream_t *u, ngx_connection_t *c)
8c0cdd81580e nginx-0.3.17-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 589
diff changeset
1689 {
6068
643f2ce02f1c Upstream: abbreviated SSL handshake may interact badly with Nagle.
Ruslan Ermilov <ru@nginx.com>
parents: 6050
diff changeset
1690 ngx_int_t rc;
643f2ce02f1c Upstream: abbreviated SSL handshake may interact badly with Nagle.
Ruslan Ermilov <ru@nginx.com>
parents: 6050
diff changeset
1691 ngx_http_core_loc_conf_t *clcf;
591
8c0cdd81580e nginx-0.3.17-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 589
diff changeset
1692
5305
12b750d35162 Upstream: reliably detect connection failures with SSL peers.
Ruslan Ermilov <ru@nginx.com>
parents: 5304
diff changeset
1693 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
1694 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
1695 return;
12b750d35162 Upstream: reliably detect connection failures with SSL peers.
Ruslan Ermilov <ru@nginx.com>
parents: 5304
diff changeset
1696 }
12b750d35162 Upstream: reliably detect connection failures with SSL peers.
Ruslan Ermilov <ru@nginx.com>
parents: 5304
diff changeset
1697
591
8c0cdd81580e nginx-0.3.17-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 589
diff changeset
1698 if (ngx_ssl_create_connection(u->conf->ssl, c,
8c0cdd81580e nginx-0.3.17-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 589
diff changeset
1699 NGX_SSL_BUFFER|NGX_SSL_CLIENT)
2536
a6d6d762c554 small optimization: " == NGX_ERROR" > " != NGX_OK"
Igor Sysoev <igor@sysoev.ru>
parents: 2463
diff changeset
1700 != NGX_OK)
591
8c0cdd81580e nginx-0.3.17-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 589
diff changeset
1701 {
8c0cdd81580e nginx-0.3.17-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 589
diff changeset
1702 ngx_http_upstream_finalize_request(r, u,
8c0cdd81580e nginx-0.3.17-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 589
diff changeset
1703 NGX_HTTP_INTERNAL_SERVER_ERROR);
8c0cdd81580e nginx-0.3.17-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 589
diff changeset
1704 return;
8c0cdd81580e nginx-0.3.17-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 589
diff changeset
1705 }
8c0cdd81580e nginx-0.3.17-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 589
diff changeset
1706
5661
060c2e692b96 Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5660
diff changeset
1707 if (u->conf->ssl_server_name || u->conf->ssl_verify) {
5660
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1708 if (ngx_http_upstream_ssl_name(r, u, c) != NGX_OK) {
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1709 ngx_http_upstream_finalize_request(r, u,
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1710 NGX_HTTP_INTERNAL_SERVER_ERROR);
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1711 return;
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1712 }
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1713 }
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1714
8042
c7e25324be11 Upstream: handling of certificates specified as an empty string.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8041
diff changeset
1715 if (u->conf->ssl_certificate
c7e25324be11 Upstream: handling of certificates specified as an empty string.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8041
diff changeset
1716 && u->conf->ssl_certificate->value.len
c7e25324be11 Upstream: handling of certificates specified as an empty string.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8041
diff changeset
1717 && (u->conf->ssl_certificate->lengths
c7e25324be11 Upstream: handling of certificates specified as an empty string.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8041
diff changeset
1718 || u->conf->ssl_certificate_key->lengths))
7833
3ab8e1e2f0f7 Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7811
diff changeset
1719 {
3ab8e1e2f0f7 Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7811
diff changeset
1720 if (ngx_http_upstream_ssl_certificate(r, u, c) != NGX_OK) {
3ab8e1e2f0f7 Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7811
diff changeset
1721 ngx_http_upstream_finalize_request(r, u,
3ab8e1e2f0f7 Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7811
diff changeset
1722 NGX_HTTP_INTERNAL_SERVER_ERROR);
3ab8e1e2f0f7 Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7811
diff changeset
1723 return;
3ab8e1e2f0f7 Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7811
diff changeset
1724 }
3ab8e1e2f0f7 Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7811
diff changeset
1725 }
3ab8e1e2f0f7 Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7811
diff changeset
1726
2184
274c0f3ea600 proxy_ssl_session_reuse
Igor Sysoev <igor@sysoev.ru>
parents: 2183
diff changeset
1727 if (u->conf->ssl_session_reuse) {
7320
696df3ac27ac SSL: save sessions for upstream peers using a callback function.
Sergey Kandaurov <pluknet@nginx.com>
parents: 7307
diff changeset
1728 c->ssl->save_session = ngx_http_upstream_ssl_save_session;
696df3ac27ac SSL: save sessions for upstream peers using a callback function.
Sergey Kandaurov <pluknet@nginx.com>
parents: 7307
diff changeset
1729
2184
274c0f3ea600 proxy_ssl_session_reuse
Igor Sysoev <igor@sysoev.ru>
parents: 2183
diff changeset
1730 if (u->peer.set_session(&u->peer, u->peer.data) != NGX_OK) {
274c0f3ea600 proxy_ssl_session_reuse
Igor Sysoev <igor@sysoev.ru>
parents: 2183
diff changeset
1731 ngx_http_upstream_finalize_request(r, u,
274c0f3ea600 proxy_ssl_session_reuse
Igor Sysoev <igor@sysoev.ru>
parents: 2183
diff changeset
1732 NGX_HTTP_INTERNAL_SERVER_ERROR);
274c0f3ea600 proxy_ssl_session_reuse
Igor Sysoev <igor@sysoev.ru>
parents: 2183
diff changeset
1733 return;
274c0f3ea600 proxy_ssl_session_reuse
Igor Sysoev <igor@sysoev.ru>
parents: 2183
diff changeset
1734 }
6068
643f2ce02f1c Upstream: abbreviated SSL handshake may interact badly with Nagle.
Ruslan Ermilov <ru@nginx.com>
parents: 6050
diff changeset
1735
643f2ce02f1c Upstream: abbreviated SSL handshake may interact badly with Nagle.
Ruslan Ermilov <ru@nginx.com>
parents: 6050
diff changeset
1736 /* 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
1737
643f2ce02f1c Upstream: abbreviated SSL handshake may interact badly with Nagle.
Ruslan Ermilov <ru@nginx.com>
parents: 6050
diff changeset
1738 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
1739
7007
ed1101bbf19f Introduced ngx_tcp_nodelay().
Ruslan Ermilov <ru@nginx.com>
parents: 7006
diff changeset
1740 if (clcf->tcp_nodelay && ngx_tcp_nodelay(c) != NGX_OK) {
ed1101bbf19f Introduced ngx_tcp_nodelay().
Ruslan Ermilov <ru@nginx.com>
parents: 7006
diff changeset
1741 ngx_http_upstream_finalize_request(r, u,
6068
643f2ce02f1c Upstream: abbreviated SSL handshake may interact badly with Nagle.
Ruslan Ermilov <ru@nginx.com>
parents: 6050
diff changeset
1742 NGX_HTTP_INTERNAL_SERVER_ERROR);
7007
ed1101bbf19f Introduced ngx_tcp_nodelay().
Ruslan Ermilov <ru@nginx.com>
parents: 7006
diff changeset
1743 return;
6068
643f2ce02f1c Upstream: abbreviated SSL handshake may interact badly with Nagle.
Ruslan Ermilov <ru@nginx.com>
parents: 6050
diff changeset
1744 }
591
8c0cdd81580e nginx-0.3.17-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 589
diff changeset
1745 }
8c0cdd81580e nginx-0.3.17-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 589
diff changeset
1746
641
5e8fb59c18c1 nginx-0.3.42-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 637
diff changeset
1747 r->connection->log->action = "SSL handshaking to upstream";
5e8fb59c18c1 nginx-0.3.42-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 637
diff changeset
1748
591
8c0cdd81580e nginx-0.3.17-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 589
diff changeset
1749 rc = ngx_ssl_handshake(c);
8c0cdd81580e nginx-0.3.17-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 589
diff changeset
1750
8c0cdd81580e nginx-0.3.17-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 589
diff changeset
1751 if (rc == NGX_AGAIN) {
5774
9bf58a3da25b Upstream: SSL handshake timeouts.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5770
diff changeset
1752
9bf58a3da25b Upstream: SSL handshake timeouts.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5770
diff changeset
1753 if (!c->write->timer_set) {
9bf58a3da25b Upstream: SSL handshake timeouts.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5770
diff changeset
1754 ngx_add_timer(c->write, u->conf->connect_timeout);
9bf58a3da25b Upstream: SSL handshake timeouts.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5770
diff changeset
1755 }
9bf58a3da25b Upstream: SSL handshake timeouts.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5770
diff changeset
1756
7042
bd2f97a3aecc Upstream: introduced ngx_http_upstream_ssl_handshake_handler().
Maxim Dounin <mdounin@mdounin.ru>
parents: 7041
diff changeset
1757 c->ssl->handler = ngx_http_upstream_ssl_handshake_handler;
591
8c0cdd81580e nginx-0.3.17-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 589
diff changeset
1758 return;
8c0cdd81580e nginx-0.3.17-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 589
diff changeset
1759 }
8c0cdd81580e nginx-0.3.17-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 589
diff changeset
1760
7042
bd2f97a3aecc Upstream: introduced ngx_http_upstream_ssl_handshake_handler().
Maxim Dounin <mdounin@mdounin.ru>
parents: 7041
diff changeset
1761 ngx_http_upstream_ssl_handshake(r, u, c);
591
8c0cdd81580e nginx-0.3.17-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 589
diff changeset
1762 }
8c0cdd81580e nginx-0.3.17-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 589
diff changeset
1763
8c0cdd81580e nginx-0.3.17-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 589
diff changeset
1764
8c0cdd81580e nginx-0.3.17-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 589
diff changeset
1765 static void
7042
bd2f97a3aecc Upstream: introduced ngx_http_upstream_ssl_handshake_handler().
Maxim Dounin <mdounin@mdounin.ru>
parents: 7041
diff changeset
1766 ngx_http_upstream_ssl_handshake_handler(ngx_connection_t *c)
577
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
1767 {
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
1768 ngx_http_request_t *r;
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
1769 ngx_http_upstream_t *u;
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
1770
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
1771 r = c->data;
7042
bd2f97a3aecc Upstream: introduced ngx_http_upstream_ssl_handshake_handler().
Maxim Dounin <mdounin@mdounin.ru>
parents: 7041
diff changeset
1772
577
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
1773 u = r->upstream;
7042
bd2f97a3aecc Upstream: introduced ngx_http_upstream_ssl_handshake_handler().
Maxim Dounin <mdounin@mdounin.ru>
parents: 7041
diff changeset
1774 c = r->connection;
577
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
1775
5928
8dfee01ff0bd Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5911
diff changeset
1776 ngx_http_set_log_request(c->log, r);
8dfee01ff0bd Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5911
diff changeset
1777
7042
bd2f97a3aecc Upstream: introduced ngx_http_upstream_ssl_handshake_handler().
Maxim Dounin <mdounin@mdounin.ru>
parents: 7041
diff changeset
1778 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
bd2f97a3aecc Upstream: introduced ngx_http_upstream_ssl_handshake_handler().
Maxim Dounin <mdounin@mdounin.ru>
parents: 7041
diff changeset
1779 "http upstream ssl handshake: \"%V?%V\"",
bd2f97a3aecc Upstream: introduced ngx_http_upstream_ssl_handshake_handler().
Maxim Dounin <mdounin@mdounin.ru>
parents: 7041
diff changeset
1780 &r->uri, &r->args);
bd2f97a3aecc Upstream: introduced ngx_http_upstream_ssl_handshake_handler().
Maxim Dounin <mdounin@mdounin.ru>
parents: 7041
diff changeset
1781
bd2f97a3aecc Upstream: introduced ngx_http_upstream_ssl_handshake_handler().
Maxim Dounin <mdounin@mdounin.ru>
parents: 7041
diff changeset
1782 ngx_http_upstream_ssl_handshake(r, u, u->peer.connection);
bd2f97a3aecc Upstream: introduced ngx_http_upstream_ssl_handshake_handler().
Maxim Dounin <mdounin@mdounin.ru>
parents: 7041
diff changeset
1783
bd2f97a3aecc Upstream: introduced ngx_http_upstream_ssl_handshake_handler().
Maxim Dounin <mdounin@mdounin.ru>
parents: 7041
diff changeset
1784 ngx_http_run_posted_requests(c);
bd2f97a3aecc Upstream: introduced ngx_http_upstream_ssl_handshake_handler().
Maxim Dounin <mdounin@mdounin.ru>
parents: 7041
diff changeset
1785 }
bd2f97a3aecc Upstream: introduced ngx_http_upstream_ssl_handshake_handler().
Maxim Dounin <mdounin@mdounin.ru>
parents: 7041
diff changeset
1786
bd2f97a3aecc Upstream: introduced ngx_http_upstream_ssl_handshake_handler().
Maxim Dounin <mdounin@mdounin.ru>
parents: 7041
diff changeset
1787
bd2f97a3aecc Upstream: introduced ngx_http_upstream_ssl_handshake_handler().
Maxim Dounin <mdounin@mdounin.ru>
parents: 7041
diff changeset
1788 static void
bd2f97a3aecc Upstream: introduced ngx_http_upstream_ssl_handshake_handler().
Maxim Dounin <mdounin@mdounin.ru>
parents: 7041
diff changeset
1789 ngx_http_upstream_ssl_handshake(ngx_http_request_t *r, ngx_http_upstream_t *u,
bd2f97a3aecc Upstream: introduced ngx_http_upstream_ssl_handshake_handler().
Maxim Dounin <mdounin@mdounin.ru>
parents: 7041
diff changeset
1790 ngx_connection_t *c)
bd2f97a3aecc Upstream: introduced ngx_http_upstream_ssl_handshake_handler().
Maxim Dounin <mdounin@mdounin.ru>
parents: 7041
diff changeset
1791 {
bd2f97a3aecc Upstream: introduced ngx_http_upstream_ssl_handshake_handler().
Maxim Dounin <mdounin@mdounin.ru>
parents: 7041
diff changeset
1792 long rc;
bd2f97a3aecc Upstream: introduced ngx_http_upstream_ssl_handshake_handler().
Maxim Dounin <mdounin@mdounin.ru>
parents: 7041
diff changeset
1793
577
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
1794 if (c->ssl->handshaked) {
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
1795
5661
060c2e692b96 Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5660
diff changeset
1796 if (u->conf->ssl_verify) {
060c2e692b96 Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5660
diff changeset
1797 rc = SSL_get_verify_result(c->ssl->connection);
060c2e692b96 Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5660
diff changeset
1798
060c2e692b96 Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5660
diff changeset
1799 if (rc != X509_V_OK) {
060c2e692b96 Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5660
diff changeset
1800 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
1801 "upstream SSL certificate verify error: (%l:%s)",
060c2e692b96 Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5660
diff changeset
1802 rc, X509_verify_cert_error_string(rc));
060c2e692b96 Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5660
diff changeset
1803 goto failed;
060c2e692b96 Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5660
diff changeset
1804 }
060c2e692b96 Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5660
diff changeset
1805
060c2e692b96 Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5660
diff changeset
1806 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
1807 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
1808 "upstream SSL certificate does not match \"%V\"",
060c2e692b96 Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5660
diff changeset
1809 &u->ssl_name);
060c2e692b96 Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5660
diff changeset
1810 goto failed;
060c2e692b96 Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5660
diff changeset
1811 }
060c2e692b96 Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5660
diff changeset
1812 }
060c2e692b96 Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5660
diff changeset
1813
7941
65946a191197 SSL: SSL_sendfile() support with kernel TLS.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7906
diff changeset
1814 if (!c->ssl->sendfile) {
65946a191197 SSL: SSL_sendfile() support with kernel TLS.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7906
diff changeset
1815 c->sendfile = 0;
65946a191197 SSL: SSL_sendfile() support with kernel TLS.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7906
diff changeset
1816 u->output.sendfile = 0;
65946a191197 SSL: SSL_sendfile() support with kernel TLS.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7906
diff changeset
1817 }
65946a191197 SSL: SSL_sendfile() support with kernel TLS.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7906
diff changeset
1818
2377
87b8c44906b5 *) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents: 2360
diff changeset
1819 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
1820 c->read->handler = ngx_http_upstream_handler;
577
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
1821
6050
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
1822 ngx_http_upstream_send_request(r, u, 1);
577
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
1823
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
1824 return;
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
1825 }
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
1826
6799
d8d037f20484 Upstream: handling of upstream SSL handshake timeouts.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6795
diff changeset
1827 if (c->write->timedout) {
d8d037f20484 Upstream: handling of upstream SSL handshake timeouts.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6795
diff changeset
1828 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
1829 return;
d8d037f20484 Upstream: handling of upstream SSL handshake timeouts.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6795
diff changeset
1830 }
d8d037f20484 Upstream: handling of upstream SSL handshake timeouts.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6795
diff changeset
1831
5661
060c2e692b96 Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5660
diff changeset
1832 failed:
060c2e692b96 Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5660
diff changeset
1833
577
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
1834 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR);
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
1835 }
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
1836
5660
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1837
7320
696df3ac27ac SSL: save sessions for upstream peers using a callback function.
Sergey Kandaurov <pluknet@nginx.com>
parents: 7307
diff changeset
1838 static void
696df3ac27ac SSL: save sessions for upstream peers using a callback function.
Sergey Kandaurov <pluknet@nginx.com>
parents: 7307
diff changeset
1839 ngx_http_upstream_ssl_save_session(ngx_connection_t *c)
696df3ac27ac SSL: save sessions for upstream peers using a callback function.
Sergey Kandaurov <pluknet@nginx.com>
parents: 7307
diff changeset
1840 {
696df3ac27ac SSL: save sessions for upstream peers using a callback function.
Sergey Kandaurov <pluknet@nginx.com>
parents: 7307
diff changeset
1841 ngx_http_request_t *r;
696df3ac27ac SSL: save sessions for upstream peers using a callback function.
Sergey Kandaurov <pluknet@nginx.com>
parents: 7307
diff changeset
1842 ngx_http_upstream_t *u;
696df3ac27ac SSL: save sessions for upstream peers using a callback function.
Sergey Kandaurov <pluknet@nginx.com>
parents: 7307
diff changeset
1843
696df3ac27ac SSL: save sessions for upstream peers using a callback function.
Sergey Kandaurov <pluknet@nginx.com>
parents: 7307
diff changeset
1844 if (c->idle) {
696df3ac27ac SSL: save sessions for upstream peers using a callback function.
Sergey Kandaurov <pluknet@nginx.com>
parents: 7307
diff changeset
1845 return;
696df3ac27ac SSL: save sessions for upstream peers using a callback function.
Sergey Kandaurov <pluknet@nginx.com>
parents: 7307
diff changeset
1846 }
696df3ac27ac SSL: save sessions for upstream peers using a callback function.
Sergey Kandaurov <pluknet@nginx.com>
parents: 7307
diff changeset
1847
696df3ac27ac SSL: save sessions for upstream peers using a callback function.
Sergey Kandaurov <pluknet@nginx.com>
parents: 7307
diff changeset
1848 r = c->data;
696df3ac27ac SSL: save sessions for upstream peers using a callback function.
Sergey Kandaurov <pluknet@nginx.com>
parents: 7307
diff changeset
1849
696df3ac27ac SSL: save sessions for upstream peers using a callback function.
Sergey Kandaurov <pluknet@nginx.com>
parents: 7307
diff changeset
1850 u = r->upstream;
696df3ac27ac SSL: save sessions for upstream peers using a callback function.
Sergey Kandaurov <pluknet@nginx.com>
parents: 7307
diff changeset
1851 c = r->connection;
696df3ac27ac SSL: save sessions for upstream peers using a callback function.
Sergey Kandaurov <pluknet@nginx.com>
parents: 7307
diff changeset
1852
696df3ac27ac SSL: save sessions for upstream peers using a callback function.
Sergey Kandaurov <pluknet@nginx.com>
parents: 7307
diff changeset
1853 ngx_http_set_log_request(c->log, r);
696df3ac27ac SSL: save sessions for upstream peers using a callback function.
Sergey Kandaurov <pluknet@nginx.com>
parents: 7307
diff changeset
1854
696df3ac27ac SSL: save sessions for upstream peers using a callback function.
Sergey Kandaurov <pluknet@nginx.com>
parents: 7307
diff changeset
1855 u->peer.save_session(&u->peer, u->peer.data);
696df3ac27ac SSL: save sessions for upstream peers using a callback function.
Sergey Kandaurov <pluknet@nginx.com>
parents: 7307
diff changeset
1856 }
696df3ac27ac SSL: save sessions for upstream peers using a callback function.
Sergey Kandaurov <pluknet@nginx.com>
parents: 7307
diff changeset
1857
696df3ac27ac SSL: save sessions for upstream peers using a callback function.
Sergey Kandaurov <pluknet@nginx.com>
parents: 7307
diff changeset
1858
5660
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1859 static ngx_int_t
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1860 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
1861 ngx_connection_t *c)
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1862 {
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1863 u_char *p, *last;
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1864 ngx_str_t name;
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1865
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1866 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
1867 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
1868 return NGX_ERROR;
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1869 }
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1870
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1871 } else {
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1872 name = u->ssl_name;
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1873 }
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1874
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1875 if (name.len == 0) {
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1876 goto done;
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1877 }
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1878
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1879 /*
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1880 * 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
1881 * 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
1882 */
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1883
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1884 p = name.data;
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1885 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
1886
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1887 if (*p == '[') {
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1888 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
1889
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1890 if (p == NULL) {
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1891 p = name.data;
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1892 }
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1893 }
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1894
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1895 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
1896
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1897 if (p != NULL) {
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1898 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
1899 }
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1900
5661
060c2e692b96 Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5660
diff changeset
1901 if (!u->conf->ssl_server_name) {
060c2e692b96 Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5660
diff changeset
1902 goto done;
060c2e692b96 Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5660
diff changeset
1903 }
060c2e692b96 Upstream: proxy_ssl_verify and friends.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5660
diff changeset
1904
5660
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1905 #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
1906
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1907 /* 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
1908
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1909 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
1910 goto done;
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1911 }
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1912
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1913 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
1914 goto done;
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1915 }
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1916
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1917 /*
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1918 * 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
1919 * 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
1920 */
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1921
5667
16405e02e612 Upstream: for ssl name, non-aligned memory allocation is enough.
Ruslan Ermilov <ru@nginx.com>
parents: 5661
diff changeset
1922 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
1923 if (p == NULL) {
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1924 return NGX_ERROR;
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1925 }
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1926
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1927 (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
1928
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1929 name.data = p;
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1930
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1931 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
1932 "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
1933
6777
563a1ee345a4 SSL: compatibility with BoringSSL.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6745
diff changeset
1934 if (SSL_set_tlsext_host_name(c->ssl->connection,
563a1ee345a4 SSL: compatibility with BoringSSL.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6745
diff changeset
1935 (char *) name.data)
563a1ee345a4 SSL: compatibility with BoringSSL.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6745
diff changeset
1936 == 0)
563a1ee345a4 SSL: compatibility with BoringSSL.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6745
diff changeset
1937 {
5660
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1938 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
1939 "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
1940 return NGX_ERROR;
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1941 }
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1942
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1943 #endif
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1944
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1945 done:
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1946
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1947 u->ssl_name = name;
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1948
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1949 return NGX_OK;
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1950 }
7022564a9e0e Upstream: proxy_ssl_name and proxy_ssl_server_name directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5621
diff changeset
1951
7833
3ab8e1e2f0f7 Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7811
diff changeset
1952
3ab8e1e2f0f7 Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7811
diff changeset
1953 static ngx_int_t
3ab8e1e2f0f7 Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7811
diff changeset
1954 ngx_http_upstream_ssl_certificate(ngx_http_request_t *r,
3ab8e1e2f0f7 Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7811
diff changeset
1955 ngx_http_upstream_t *u, ngx_connection_t *c)
3ab8e1e2f0f7 Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7811
diff changeset
1956 {
3ab8e1e2f0f7 Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7811
diff changeset
1957 ngx_str_t cert, key;
3ab8e1e2f0f7 Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7811
diff changeset
1958
3ab8e1e2f0f7 Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7811
diff changeset
1959 if (ngx_http_complex_value(r, u->conf->ssl_certificate, &cert)
3ab8e1e2f0f7 Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7811
diff changeset
1960 != NGX_OK)
3ab8e1e2f0f7 Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7811
diff changeset
1961 {
3ab8e1e2f0f7 Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7811
diff changeset
1962 return NGX_ERROR;
3ab8e1e2f0f7 Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7811
diff changeset
1963 }
3ab8e1e2f0f7 Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7811
diff changeset
1964
3ab8e1e2f0f7 Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7811
diff changeset
1965 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
3ab8e1e2f0f7 Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7811
diff changeset
1966 "http upstream ssl cert: \"%s\"", cert.data);
3ab8e1e2f0f7 Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7811
diff changeset
1967
3ab8e1e2f0f7 Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7811
diff changeset
1968 if (*cert.data == '\0') {
3ab8e1e2f0f7 Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7811
diff changeset
1969 return NGX_OK;
3ab8e1e2f0f7 Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7811
diff changeset
1970 }
3ab8e1e2f0f7 Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7811
diff changeset
1971
3ab8e1e2f0f7 Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7811
diff changeset
1972 if (ngx_http_complex_value(r, u->conf->ssl_certificate_key, &key)
3ab8e1e2f0f7 Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7811
diff changeset
1973 != NGX_OK)
3ab8e1e2f0f7 Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7811
diff changeset
1974 {
3ab8e1e2f0f7 Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7811
diff changeset
1975 return NGX_ERROR;
3ab8e1e2f0f7 Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7811
diff changeset
1976 }
3ab8e1e2f0f7 Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7811
diff changeset
1977
3ab8e1e2f0f7 Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7811
diff changeset
1978 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
3ab8e1e2f0f7 Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7811
diff changeset
1979 "http upstream ssl key: \"%s\"", key.data);
3ab8e1e2f0f7 Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7811
diff changeset
1980
3ab8e1e2f0f7 Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7811
diff changeset
1981 if (ngx_ssl_connection_certificate(c, r->pool, &cert, &key,
3ab8e1e2f0f7 Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7811
diff changeset
1982 u->conf->ssl_passwords)
3ab8e1e2f0f7 Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7811
diff changeset
1983 != NGX_OK)
3ab8e1e2f0f7 Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7811
diff changeset
1984 {
3ab8e1e2f0f7 Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7811
diff changeset
1985 return NGX_ERROR;
3ab8e1e2f0f7 Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7811
diff changeset
1986 }
3ab8e1e2f0f7 Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7811
diff changeset
1987
3ab8e1e2f0f7 Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7811
diff changeset
1988 return NGX_OK;
3ab8e1e2f0f7 Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7811
diff changeset
1989 }
3ab8e1e2f0f7 Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7811
diff changeset
1990
577
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
1991 #endif
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
1992
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
1993
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
1994 static ngx_int_t
487
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 485
diff changeset
1995 ngx_http_upstream_reinit(ngx_http_request_t *r, ngx_http_upstream_t *u)
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1996 {
5848
106a8bfa4f42 Upstream: fixed file buffers reinit in ngx_http_upstream_reinit().
Roman Arutyunyan <arut@nginx.com>
parents: 5832
diff changeset
1997 off_t file_pos;
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1998 ngx_chain_t *cl;
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1999
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
2000 if (u->reinit_request(r) != NGX_OK) {
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
2001 return NGX_ERROR;
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
2002 }
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
2003
4120
42135dd1f0ea Upstream: keepalive flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4119
diff changeset
2004 u->keepalive = 0;
5072
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
2005 u->upgrade = 0;
7679
05e42236e95b FastCGI: protection from responses with wrong length.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7678
diff changeset
2006 u->error = 0;
4120
42135dd1f0ea Upstream: keepalive flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4119
diff changeset
2007
1705
d22095839d86 optimize r->upstream usage
Igor Sysoev <igor@sysoev.ru>
parents: 1701
diff changeset
2008 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
2009 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
2010 u->headers_in.last_modified_time = -1;
1705
d22095839d86 optimize r->upstream usage
Igor Sysoev <igor@sysoev.ru>
parents: 1701
diff changeset
2011
d22095839d86 optimize r->upstream usage
Igor Sysoev <igor@sysoev.ru>
parents: 1701
diff changeset
2012 if (ngx_list_init(&u->headers_in.headers, r->pool, 8,
591
8c0cdd81580e nginx-0.3.17-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 589
diff changeset
2013 sizeof(ngx_table_elt_t))
8c0cdd81580e nginx-0.3.17-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 589
diff changeset
2014 != NGX_OK)
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
2015 {
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
2016 return NGX_ERROR;
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2017 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2018
7230
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
2019 if (ngx_list_init(&u->headers_in.trailers, r->pool, 2,
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
2020 sizeof(ngx_table_elt_t))
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
2021 != NGX_OK)
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
2022 {
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
2023 return NGX_ERROR;
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
2024 }
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
2025
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2026 /* reinit the request chain */
577
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
2027
5848
106a8bfa4f42 Upstream: fixed file buffers reinit in ngx_http_upstream_reinit().
Roman Arutyunyan <arut@nginx.com>
parents: 5832
diff changeset
2028 file_pos = 0;
106a8bfa4f42 Upstream: fixed file buffers reinit in ngx_http_upstream_reinit().
Roman Arutyunyan <arut@nginx.com>
parents: 5832
diff changeset
2029
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
2030 for (cl = u->request_bufs; cl; cl = cl->next) {
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2031 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
2032
106a8bfa4f42 Upstream: fixed file buffers reinit in ngx_http_upstream_reinit().
Roman Arutyunyan <arut@nginx.com>
parents: 5832
diff changeset
2033 /* 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
2034
106a8bfa4f42 Upstream: fixed file buffers reinit in ngx_http_upstream_reinit().
Roman Arutyunyan <arut@nginx.com>
parents: 5832
diff changeset
2035 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
2036 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
2037 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
2038 }
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2039 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2040
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
2041 /* reinit the subrequest's ngx_output_chain() context */
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
2042
573
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
2043 if (r->request_body && r->request_body->temp_file
597
9262f520ce21 nginx-0.3.20-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 593
diff changeset
2044 && r != r->main && u->output.buf)
573
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
2045 {
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
2046 u->output.free = ngx_alloc_chain_link(r->pool);
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
2047 if (u->output.free == NULL) {
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
2048 return NGX_ERROR;
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
2049 }
573
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
2050
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
2051 u->output.free->buf = u->output.buf;
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
2052 u->output.free->next = NULL;
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
2053
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
2054 u->output.buf->pos = u->output.buf->start;
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
2055 u->output.buf->last = u->output.buf->start;
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
2056 }
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2057
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2058 u->output.buf = NULL;
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2059 u->output.in = NULL;
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2060 u->output.busy = NULL;
577
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
2061
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
2062 /* reinit u->buffer */
577
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
2063
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2064 u->buffer.pos = u->buffer.start;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2065
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2066 #if (NGX_HTTP_CACHE)
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2067
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2068 if (r->cache) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2069 u->buffer.pos += r->cache->header_start;
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2070 }
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
2071
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2072 #endif
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2073
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2074 u->buffer.last = u->buffer.pos;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2075
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
2076 return NGX_OK;
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2077 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2078
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2079
487
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 485
diff changeset
2080 static void
6050
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2081 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
2082 ngx_uint_t do_write)
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2083 {
1153
c843f3df3b85 separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents: 1143
diff changeset
2084 ngx_int_t rc;
483
621229427cba nginx-0.1.16-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 481
diff changeset
2085 ngx_connection_t *c;
577
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
2086
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2087 c = u->peer.connection;
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2088
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2089 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2090 "http upstream send request");
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2091
6147
74b6ef56ea56 Upstream: $upstream_connect_time.
Ruslan Ermilov <ru@nginx.com>
parents: 6146
diff changeset
2092 if (u->state->connect_time == (ngx_msec_t) -1) {
7397
860d3907da1c Upstream: revised upstream response time variables.
Vladimir Homutov <vl@nginx.com>
parents: 7371
diff changeset
2093 u->state->connect_time = ngx_current_msec - u->start_time;
6147
74b6ef56ea56 Upstream: $upstream_connect_time.
Ruslan Ermilov <ru@nginx.com>
parents: 6146
diff changeset
2094 }
74b6ef56ea56 Upstream: $upstream_connect_time.
Ruslan Ermilov <ru@nginx.com>
parents: 6146
diff changeset
2095
1153
c843f3df3b85 separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents: 1143
diff changeset
2096 if (!u->request_sent && ngx_http_upstream_test_connect(c) != NGX_OK) {
1166
bde5e4134759 style fix: remove tabs
Igor Sysoev <igor@sysoev.ru>
parents: 1162
diff changeset
2097 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
2098 return;
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2099 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2100
483
621229427cba nginx-0.1.16-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 481
diff changeset
2101 c->log->action = "sending request to upstream";
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2102
6050
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2103 rc = ngx_http_upstream_send_request_body(r, u, do_write);
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2104
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2105 if (rc == NGX_ERROR) {
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2106 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR);
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2107 return;
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2108 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2109
6050
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2110 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) {
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2111 ngx_http_upstream_finalize_request(r, u, rc);
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2112 return;
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2113 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2114
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2115 if (rc == NGX_AGAIN) {
7231
22f7bdbd96d3 Upstream: u->request_body_blocked flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7230
diff changeset
2116 if (!c->write->ready || u->request_body_blocked) {
6050
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2117 ngx_add_timer(c->write, u->conf->send_timeout);
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 } else if (c->write->timer_set) {
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2120 ngx_del_timer(c->write);
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2121 }
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2122
2386
4ccaa42de633 use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents: 2381
diff changeset
2123 if (ngx_handle_write_event(c->write, u->conf->send_lowat) != NGX_OK) {
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2124 ngx_http_upstream_finalize_request(r, u,
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2125 NGX_HTTP_INTERNAL_SERVER_ERROR);
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2126 return;
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2127 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2128
7307
ece9b5454b8a Upstream: fixed tcp_nopush with gRPC.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7306
diff changeset
2129 if (c->write->ready && c->tcp_nopush == NGX_TCP_NOPUSH_SET) {
ece9b5454b8a Upstream: fixed tcp_nopush with gRPC.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7306
diff changeset
2130 if (ngx_tcp_push(c->fd) == -1) {
ece9b5454b8a Upstream: fixed tcp_nopush with gRPC.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7306
diff changeset
2131 ngx_log_error(NGX_LOG_CRIT, c->log, ngx_socket_errno,
ece9b5454b8a Upstream: fixed tcp_nopush with gRPC.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7306
diff changeset
2132 ngx_tcp_push_n " failed");
ece9b5454b8a Upstream: fixed tcp_nopush with gRPC.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7306
diff changeset
2133 ngx_http_upstream_finalize_request(r, u,
ece9b5454b8a Upstream: fixed tcp_nopush with gRPC.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7306
diff changeset
2134 NGX_HTTP_INTERNAL_SERVER_ERROR);
ece9b5454b8a Upstream: fixed tcp_nopush with gRPC.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7306
diff changeset
2135 return;
ece9b5454b8a Upstream: fixed tcp_nopush with gRPC.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7306
diff changeset
2136 }
ece9b5454b8a Upstream: fixed tcp_nopush with gRPC.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7306
diff changeset
2137
ece9b5454b8a Upstream: fixed tcp_nopush with gRPC.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7306
diff changeset
2138 c->tcp_nopush = NGX_TCP_NOPUSH_UNSET;
ece9b5454b8a Upstream: fixed tcp_nopush with gRPC.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7306
diff changeset
2139 }
ece9b5454b8a Upstream: fixed tcp_nopush with gRPC.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7306
diff changeset
2140
7906
058a67435e83 Upstream: fixed timeouts with gRPC, SSL and select (ticket #2229).
Maxim Dounin <mdounin@mdounin.ru>
parents: 7833
diff changeset
2141 if (c->read->ready) {
058a67435e83 Upstream: fixed timeouts with gRPC, SSL and select (ticket #2229).
Maxim Dounin <mdounin@mdounin.ru>
parents: 7833
diff changeset
2142 ngx_post_event(c->read, &ngx_posted_events);
058a67435e83 Upstream: fixed timeouts with gRPC, SSL and select (ticket #2229).
Maxim Dounin <mdounin@mdounin.ru>
parents: 7833
diff changeset
2143 }
058a67435e83 Upstream: fixed timeouts with gRPC, SSL and select (ticket #2229).
Maxim Dounin <mdounin@mdounin.ru>
parents: 7833
diff changeset
2144
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2145 return;
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2146 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2147
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2148 /* rc == NGX_OK */
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2149
6050
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2150 if (c->write->timer_set) {
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2151 ngx_del_timer(c->write);
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2152 }
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2153
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2154 if (c->tcp_nopush == NGX_TCP_NOPUSH_SET) {
7239
400a3412b1e3 Fixed checking ngx_tcp_push() and ngx_tcp_nopush() return values.
Ruslan Ermilov <ru@nginx.com>
parents: 7232
diff changeset
2155 if (ngx_tcp_push(c->fd) == -1) {
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2156 ngx_log_error(NGX_LOG_CRIT, c->log, ngx_socket_errno,
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2157 ngx_tcp_push_n " failed");
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2158 ngx_http_upstream_finalize_request(r, u,
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2159 NGX_HTTP_INTERNAL_SERVER_ERROR);
577
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
2160 return;
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2161 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2162
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2163 c->tcp_nopush = NGX_TCP_NOPUSH_UNSET;
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2164 }
577
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
2165
7232
a7ed15573ae9 Upstream: u->conf->preserve_output flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7231
diff changeset
2166 if (!u->conf->preserve_output) {
a7ed15573ae9 Upstream: u->conf->preserve_output flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7231
diff changeset
2167 u->write_event_handler = ngx_http_upstream_dummy_handler;
a7ed15573ae9 Upstream: u->conf->preserve_output flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7231
diff changeset
2168 }
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2169
2386
4ccaa42de633 use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents: 2381
diff changeset
2170 if (ngx_handle_write_event(c->write, 0) != NGX_OK) {
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2171 ngx_http_upstream_finalize_request(r, u,
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2172 NGX_HTTP_INTERNAL_SERVER_ERROR);
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2173 return;
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2174 }
5745
9d3a9c45fc43 Upstream: fixed handling of write event after sending request.
Valentin Bartenev <vbart@nginx.com>
parents: 5738
diff changeset
2175
7260
08f114ed5449 Upstream: fixed u->conf->preserve_output (ticket #1519).
Maxim Dounin <mdounin@mdounin.ru>
parents: 7255
diff changeset
2176 if (!u->request_body_sent) {
08f114ed5449 Upstream: fixed u->conf->preserve_output (ticket #1519).
Maxim Dounin <mdounin@mdounin.ru>
parents: 7255
diff changeset
2177 u->request_body_sent = 1;
08f114ed5449 Upstream: fixed u->conf->preserve_output (ticket #1519).
Maxim Dounin <mdounin@mdounin.ru>
parents: 7255
diff changeset
2178
08f114ed5449 Upstream: fixed u->conf->preserve_output (ticket #1519).
Maxim Dounin <mdounin@mdounin.ru>
parents: 7255
diff changeset
2179 if (u->header_sent) {
08f114ed5449 Upstream: fixed u->conf->preserve_output (ticket #1519).
Maxim Dounin <mdounin@mdounin.ru>
parents: 7255
diff changeset
2180 return;
08f114ed5449 Upstream: fixed u->conf->preserve_output (ticket #1519).
Maxim Dounin <mdounin@mdounin.ru>
parents: 7255
diff changeset
2181 }
08f114ed5449 Upstream: fixed u->conf->preserve_output (ticket #1519).
Maxim Dounin <mdounin@mdounin.ru>
parents: 7255
diff changeset
2182
08f114ed5449 Upstream: fixed u->conf->preserve_output (ticket #1519).
Maxim Dounin <mdounin@mdounin.ru>
parents: 7255
diff changeset
2183 ngx_add_timer(c->read, u->conf->read_timeout);
08f114ed5449 Upstream: fixed u->conf->preserve_output (ticket #1519).
Maxim Dounin <mdounin@mdounin.ru>
parents: 7255
diff changeset
2184
08f114ed5449 Upstream: fixed u->conf->preserve_output (ticket #1519).
Maxim Dounin <mdounin@mdounin.ru>
parents: 7255
diff changeset
2185 if (c->read->ready) {
08f114ed5449 Upstream: fixed u->conf->preserve_output (ticket #1519).
Maxim Dounin <mdounin@mdounin.ru>
parents: 7255
diff changeset
2186 ngx_http_upstream_process_header(r, u);
08f114ed5449 Upstream: fixed u->conf->preserve_output (ticket #1519).
Maxim Dounin <mdounin@mdounin.ru>
parents: 7255
diff changeset
2187 return;
08f114ed5449 Upstream: fixed u->conf->preserve_output (ticket #1519).
Maxim Dounin <mdounin@mdounin.ru>
parents: 7255
diff changeset
2188 }
5745
9d3a9c45fc43 Upstream: fixed handling of write event after sending request.
Valentin Bartenev <vbart@nginx.com>
parents: 5738
diff changeset
2189 }
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2190 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2191
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2192
6050
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2193 static ngx_int_t
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2194 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
2195 ngx_http_upstream_t *u, ngx_uint_t do_write)
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2196 {
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2197 ngx_int_t rc;
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2198 ngx_chain_t *out, *cl, *ln;
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2199 ngx_connection_t *c;
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2200 ngx_http_core_loc_conf_t *clcf;
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2201
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2202 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
2203 "http upstream send request body");
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2204
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2205 if (!r->request_body_no_buffering) {
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2206
6474
Ruslan Ermilov <ru@nginx.com>
parents: 6467
diff changeset
2207 /* buffered request body */
Ruslan Ermilov <ru@nginx.com>
parents: 6467
diff changeset
2208
Ruslan Ermilov <ru@nginx.com>
parents: 6467
diff changeset
2209 if (!u->request_sent) {
Ruslan Ermilov <ru@nginx.com>
parents: 6467
diff changeset
2210 u->request_sent = 1;
Ruslan Ermilov <ru@nginx.com>
parents: 6467
diff changeset
2211 out = u->request_bufs;
Ruslan Ermilov <ru@nginx.com>
parents: 6467
diff changeset
2212
Ruslan Ermilov <ru@nginx.com>
parents: 6467
diff changeset
2213 } else {
Ruslan Ermilov <ru@nginx.com>
parents: 6467
diff changeset
2214 out = NULL;
Ruslan Ermilov <ru@nginx.com>
parents: 6467
diff changeset
2215 }
Ruslan Ermilov <ru@nginx.com>
parents: 6467
diff changeset
2216
7231
22f7bdbd96d3 Upstream: u->request_body_blocked flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7230
diff changeset
2217 rc = ngx_output_chain(&u->output, out);
22f7bdbd96d3 Upstream: u->request_body_blocked flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7230
diff changeset
2218
22f7bdbd96d3 Upstream: u->request_body_blocked flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7230
diff changeset
2219 if (rc == NGX_AGAIN) {
22f7bdbd96d3 Upstream: u->request_body_blocked flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7230
diff changeset
2220 u->request_body_blocked = 1;
22f7bdbd96d3 Upstream: u->request_body_blocked flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7230
diff changeset
2221
22f7bdbd96d3 Upstream: u->request_body_blocked flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7230
diff changeset
2222 } else {
22f7bdbd96d3 Upstream: u->request_body_blocked flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7230
diff changeset
2223 u->request_body_blocked = 0;
22f7bdbd96d3 Upstream: u->request_body_blocked flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7230
diff changeset
2224 }
22f7bdbd96d3 Upstream: u->request_body_blocked flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7230
diff changeset
2225
22f7bdbd96d3 Upstream: u->request_body_blocked flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7230
diff changeset
2226 return rc;
6050
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2227 }
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2228
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2229 if (!u->request_sent) {
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2230 u->request_sent = 1;
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2231 out = u->request_bufs;
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2232
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2233 if (r->request_body->bufs) {
7341
15ea84e65d07 Upstream: fixed request chain traversal (ticket #1618).
Vladimir Homutov <vl@nginx.com>
parents: 7340
diff changeset
2234 for (cl = out; cl->next; cl = cl->next) { /* void */ }
6050
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2235 cl->next = r->request_body->bufs;
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2236 r->request_body->bufs = NULL;
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2237 }
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2238
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2239 c = u->peer.connection;
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2240 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
2241
7007
ed1101bbf19f Introduced ngx_tcp_nodelay().
Ruslan Ermilov <ru@nginx.com>
parents: 7006
diff changeset
2242 if (clcf->tcp_nodelay && ngx_tcp_nodelay(c) != NGX_OK) {
ed1101bbf19f Introduced ngx_tcp_nodelay().
Ruslan Ermilov <ru@nginx.com>
parents: 7006
diff changeset
2243 return NGX_ERROR;
6050
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2244 }
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2245
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2246 r->read_event_handler = ngx_http_upstream_read_request_handler;
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2247
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2248 } else {
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2249 out = NULL;
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2250 }
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2251
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2252 for ( ;; ) {
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2253
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2254 if (do_write) {
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2255 rc = ngx_output_chain(&u->output, out);
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2256
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2257 if (rc == NGX_ERROR) {
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2258 return NGX_ERROR;
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2259 }
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2260
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2261 while (out) {
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2262 ln = out;
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2263 out = out->next;
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2264 ngx_free_chain(r->pool, ln);
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2265 }
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2266
7231
22f7bdbd96d3 Upstream: u->request_body_blocked flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7230
diff changeset
2267 if (rc == NGX_AGAIN) {
22f7bdbd96d3 Upstream: u->request_body_blocked flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7230
diff changeset
2268 u->request_body_blocked = 1;
22f7bdbd96d3 Upstream: u->request_body_blocked flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7230
diff changeset
2269
22f7bdbd96d3 Upstream: u->request_body_blocked flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7230
diff changeset
2270 } else {
22f7bdbd96d3 Upstream: u->request_body_blocked flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7230
diff changeset
2271 u->request_body_blocked = 0;
22f7bdbd96d3 Upstream: u->request_body_blocked flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7230
diff changeset
2272 }
22f7bdbd96d3 Upstream: u->request_body_blocked flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7230
diff changeset
2273
6050
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2274 if (rc == NGX_OK && !r->reading_body) {
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2275 break;
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2276 }
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2277 }
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2278
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2279 if (r->reading_body) {
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2280 /* read client request body */
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2281
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2282 rc = ngx_http_read_unbuffered_request_body(r);
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2283
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2284 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) {
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2285 return rc;
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2286 }
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2287
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2288 out = r->request_body->bufs;
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2289 r->request_body->bufs = NULL;
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2290 }
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2291
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2292 /* stop if there is nothing to send */
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2293
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2294 if (out == NULL) {
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2295 rc = NGX_AGAIN;
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2296 break;
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2297 }
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2298
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2299 do_write = 1;
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2300 }
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2301
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2302 if (!r->reading_body) {
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2303 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
2304 r->read_event_handler =
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2305 ngx_http_upstream_rd_check_broken_connection;
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2306 }
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2307 }
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2308
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2309 return rc;
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2310 }
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2311
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2312
487
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 485
diff changeset
2313 static void
2386
4ccaa42de633 use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents: 2381
diff changeset
2314 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
2315 ngx_http_upstream_t *u)
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2316 {
2386
4ccaa42de633 use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents: 2381
diff changeset
2317 ngx_connection_t *c;
4ccaa42de633 use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents: 2381
diff changeset
2318
4ccaa42de633 use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents: 2381
diff changeset
2319 c = u->peer.connection;
4ccaa42de633 use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents: 2381
diff changeset
2320
4ccaa42de633 use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents: 2381
diff changeset
2321 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2322 "http upstream send request handler");
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2323
2386
4ccaa42de633 use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents: 2381
diff changeset
2324 if (c->write->timedout) {
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2325 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_TIMEOUT);
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2326 return;
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2327 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2328
591
8c0cdd81580e nginx-0.3.17-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 589
diff changeset
2329 #if (NGX_HTTP_SSL)
8c0cdd81580e nginx-0.3.17-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 589
diff changeset
2330
1658
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
2331 if (u->ssl && c->ssl == NULL) {
591
8c0cdd81580e nginx-0.3.17-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 589
diff changeset
2332 ngx_http_upstream_ssl_init_connection(r, u, c);
8c0cdd81580e nginx-0.3.17-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 589
diff changeset
2333 return;
8c0cdd81580e nginx-0.3.17-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 589
diff changeset
2334 }
8c0cdd81580e nginx-0.3.17-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 589
diff changeset
2335
8c0cdd81580e nginx-0.3.17-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 589
diff changeset
2336 #endif
8c0cdd81580e nginx-0.3.17-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 589
diff changeset
2337
7232
a7ed15573ae9 Upstream: u->conf->preserve_output flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7231
diff changeset
2338 if (u->header_sent && !u->conf->preserve_output) {
2377
87b8c44906b5 *) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents: 2360
diff changeset
2339 u->write_event_handler = ngx_http_upstream_dummy_handler;
651
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
2340
2386
4ccaa42de633 use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents: 2381
diff changeset
2341 (void) ngx_handle_write_event(c->write, 0);
651
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
2342
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
2343 return;
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
2344 }
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
2345
6050
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2346 ngx_http_upstream_send_request(r, u, 1);
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2347 }
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2348
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2349
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2350 static void
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2351 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
2352 {
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2353 ngx_connection_t *c;
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2354 ngx_http_upstream_t *u;
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2355
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2356 c = r->connection;
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2357 u = r->upstream;
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2358
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2359 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
2360 "http upstream read request handler");
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2361
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2362 if (c->read->timedout) {
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2363 c->timedout = 1;
9255
208a4adb82ef Request body: logging of timeouts.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9237
diff changeset
2364 ngx_connection_error(c, NGX_ETIMEDOUT, "client timed out");
6050
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2365 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
2366 return;
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2367 }
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2368
a08fad30aeac Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6031
diff changeset
2369 ngx_http_upstream_send_request(r, u, 0);
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2370 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2371
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2372
487
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 485
diff changeset
2373 static void
2386
4ccaa42de633 use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents: 2381
diff changeset
2374 ngx_http_upstream_process_header(ngx_http_request_t *r, ngx_http_upstream_t *u)
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2375 {
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2376 ssize_t n;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2377 ngx_int_t rc;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2378 ngx_connection_t *c;
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2379
2386
4ccaa42de633 use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents: 2381
diff changeset
2380 c = u->peer.connection;
4ccaa42de633 use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents: 2381
diff changeset
2381
4ccaa42de633 use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents: 2381
diff changeset
2382 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
483
621229427cba nginx-0.1.16-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 481
diff changeset
2383 "http upstream process header");
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2384
483
621229427cba nginx-0.1.16-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 481
diff changeset
2385 c->log->action = "reading response header from upstream";
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2386
2386
4ccaa42de633 use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents: 2381
diff changeset
2387 if (c->read->timedout) {
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2388 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_TIMEOUT);
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2389 return;
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2390 }
577
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
2391
1153
c843f3df3b85 separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents: 1143
diff changeset
2392 if (!u->request_sent && ngx_http_upstream_test_connect(c) != NGX_OK) {
1166
bde5e4134759 style fix: remove tabs
Igor Sysoev <igor@sysoev.ru>
parents: 1162
diff changeset
2393 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
2394 return;
c843f3df3b85 separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents: 1143
diff changeset
2395 }
c843f3df3b85 separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents: 1143
diff changeset
2396
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
2397 if (u->buffer.start == NULL) {
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
2398 u->buffer.start = ngx_palloc(r->pool, u->conf->buffer_size);
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
2399 if (u->buffer.start == NULL) {
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2400 ngx_http_upstream_finalize_request(r, u,
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2401 NGX_HTTP_INTERNAL_SERVER_ERROR);
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2402 return;
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2403 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2404
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
2405 u->buffer.pos = u->buffer.start;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
2406 u->buffer.last = u->buffer.start;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
2407 u->buffer.end = u->buffer.start + u->conf->buffer_size;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
2408 u->buffer.temporary = 1;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
2409
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
2410 u->buffer.tag = u->output.tag;
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2411
1705
d22095839d86 optimize r->upstream usage
Igor Sysoev <igor@sysoev.ru>
parents: 1701
diff changeset
2412 if (ngx_list_init(&u->headers_in.headers, r->pool, 8,
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
2413 sizeof(ngx_table_elt_t))
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
2414 != NGX_OK)
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
2415 {
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
2416 ngx_http_upstream_finalize_request(r, u,
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
2417 NGX_HTTP_INTERNAL_SERVER_ERROR);
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
2418 return;
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
2419 }
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
2420
7230
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
2421 if (ngx_list_init(&u->headers_in.trailers, r->pool, 2,
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
2422 sizeof(ngx_table_elt_t))
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
2423 != NGX_OK)
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
2424 {
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
2425 ngx_http_upstream_finalize_request(r, u,
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
2426 NGX_HTTP_INTERNAL_SERVER_ERROR);
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
2427 return;
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
2428 }
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
2429
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2430 #if (NGX_HTTP_CACHE)
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2431
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2432 if (r->cache) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2433 u->buffer.pos += r->cache->header_start;
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
2434 u->buffer.last = u->buffer.pos;
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2435 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2436 #endif
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2437 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2438
2360
64854406b1f9 read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents: 2308
diff changeset
2439 for ( ;; ) {
64854406b1f9 read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents: 2308
diff changeset
2440
9237
41db21d1ca7c Upstream: improved c->read->ready flag handling.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9217
diff changeset
2441 if (c->read->ready) {
41db21d1ca7c Upstream: improved c->read->ready flag handling.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9217
diff changeset
2442 n = c->recv(c, u->buffer.last, u->buffer.end - u->buffer.last);
41db21d1ca7c Upstream: improved c->read->ready flag handling.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9217
diff changeset
2443
41db21d1ca7c Upstream: improved c->read->ready flag handling.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9217
diff changeset
2444 } else {
41db21d1ca7c Upstream: improved c->read->ready flag handling.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9217
diff changeset
2445 n = NGX_AGAIN;
41db21d1ca7c Upstream: improved c->read->ready flag handling.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9217
diff changeset
2446 }
2360
64854406b1f9 read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents: 2308
diff changeset
2447
64854406b1f9 read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents: 2308
diff changeset
2448 if (n == NGX_AGAIN) {
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2449 #if 0
2360
64854406b1f9 read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents: 2308
diff changeset
2450 ngx_add_timer(rev, u->read_timeout);
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2451 #endif
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2452
2386
4ccaa42de633 use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents: 2381
diff changeset
2453 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
2454 ngx_http_upstream_finalize_request(r, u,
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2455 NGX_HTTP_INTERNAL_SERVER_ERROR);
2360
64854406b1f9 read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents: 2308
diff changeset
2456 return;
64854406b1f9 read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents: 2308
diff changeset
2457 }
64854406b1f9 read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents: 2308
diff changeset
2458
64854406b1f9 read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents: 2308
diff changeset
2459 return;
64854406b1f9 read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents: 2308
diff changeset
2460 }
64854406b1f9 read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents: 2308
diff changeset
2461
64854406b1f9 read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents: 2308
diff changeset
2462 if (n == 0) {
2386
4ccaa42de633 use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents: 2381
diff changeset
2463 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
2464 "upstream prematurely closed connection");
64854406b1f9 read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents: 2308
diff changeset
2465 }
64854406b1f9 read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents: 2308
diff changeset
2466
64854406b1f9 read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents: 2308
diff changeset
2467 if (n == NGX_ERROR || n == 0) {
64854406b1f9 read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents: 2308
diff changeset
2468 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR);
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2469 return;
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2470 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2471
6654
c131f20c9562 Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents: 6594
diff changeset
2472 u->state->bytes_received += n;
c131f20c9562 Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents: 6594
diff changeset
2473
2360
64854406b1f9 read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents: 2308
diff changeset
2474 u->buffer.last += n;
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2475
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2476 #if 0
2360
64854406b1f9 read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents: 2308
diff changeset
2477 u->valid_header_in = 0;
64854406b1f9 read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents: 2308
diff changeset
2478
64854406b1f9 read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents: 2308
diff changeset
2479 u->peer.cached = 0;
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2480 #endif
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2481
2360
64854406b1f9 read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents: 2308
diff changeset
2482 rc = u->process_header(r);
64854406b1f9 read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents: 2308
diff changeset
2483
64854406b1f9 read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents: 2308
diff changeset
2484 if (rc == NGX_AGAIN) {
64854406b1f9 read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents: 2308
diff changeset
2485
4460
6299d1c4dbb4 Upstream: fixed "too big header" check.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4412
diff changeset
2486 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
2487 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
2488 "upstream sent too big header");
64854406b1f9 read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents: 2308
diff changeset
2489
64854406b1f9 read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents: 2308
diff changeset
2490 ngx_http_upstream_next(r, u,
64854406b1f9 read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents: 2308
diff changeset
2491 NGX_HTTP_UPSTREAM_FT_INVALID_HEADER);
64854406b1f9 read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents: 2308
diff changeset
2492 return;
64854406b1f9 read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents: 2308
diff changeset
2493 }
64854406b1f9 read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents: 2308
diff changeset
2494
64854406b1f9 read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents: 2308
diff changeset
2495 continue;
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2496 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2497
2360
64854406b1f9 read and process upstream header in cycle,
Igor Sysoev <igor@sysoev.ru>
parents: 2308
diff changeset
2498 break;
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2499 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2500
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2501 if (rc == NGX_HTTP_UPSTREAM_INVALID_HEADER) {
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2502 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_INVALID_HEADER);
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2503 return;
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2504 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2505
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
2506 if (rc == NGX_ERROR) {
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2507 ngx_http_upstream_finalize_request(r, u,
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2508 NGX_HTTP_INTERNAL_SERVER_ERROR);
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2509 return;
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2510 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2511
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2512 /* rc == NGX_OK */
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2513
7397
860d3907da1c Upstream: revised upstream response time variables.
Vladimir Homutov <vl@nginx.com>
parents: 7371
diff changeset
2514 u->state->header_time = ngx_current_msec - u->start_time;
5964
0a198a517eaf Upstream: $upstream_header_time variable.
Vladimir Homutov <vl@nginx.com>
parents: 5960
diff changeset
2515
5209
07e515e65984 Upstream: allow to intercept responses with status 300.
Ruslan Ermilov <ru@nginx.com>
parents: 5169
diff changeset
2516 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
2517
33556140681a *) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents: 2267
diff changeset
2518 if (ngx_http_upstream_test_next(r, u) == NGX_OK) {
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
2519 return;
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
2520 }
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
2521
2267
920be89a3d2d ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents: 2244
diff changeset
2522 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
2523 return;
487
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 485
diff changeset
2524 }
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 485
diff changeset
2525 }
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 485
diff changeset
2526
9217
6765e5f6d991 Upstream: fixed X-Accel-Redirect handling from cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9204
diff changeset
2527 rc = ngx_http_upstream_process_headers(r, u);
6765e5f6d991 Upstream: fixed X-Accel-Redirect handling from cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9204
diff changeset
2528
6765e5f6d991 Upstream: fixed X-Accel-Redirect handling from cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9204
diff changeset
2529 if (rc == NGX_DONE) {
6765e5f6d991 Upstream: fixed X-Accel-Redirect handling from cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9204
diff changeset
2530 return;
6765e5f6d991 Upstream: fixed X-Accel-Redirect handling from cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9204
diff changeset
2531 }
6765e5f6d991 Upstream: fixed X-Accel-Redirect handling from cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9204
diff changeset
2532
6765e5f6d991 Upstream: fixed X-Accel-Redirect handling from cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9204
diff changeset
2533 if (rc == NGX_ERROR) {
6765e5f6d991 Upstream: fixed X-Accel-Redirect handling from cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9204
diff changeset
2534 ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
515
417a087c9c4d nginx-0.1.32-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 511
diff changeset
2535 return;
417a087c9c4d nginx-0.1.32-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 511
diff changeset
2536 }
417a087c9c4d nginx-0.1.32-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 511
diff changeset
2537
7220
20f139e9ffa8 Generic subrequests in memory.
Roman Arutyunyan <arut@nginx.com>
parents: 7199
diff changeset
2538 ngx_http_upstream_send_response(r, u);
777
4ab852b691f5 <!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents: 757
diff changeset
2539 }
4ab852b691f5 <!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents: 757
diff changeset
2540
4ab852b691f5 <!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents: 757
diff changeset
2541
1153
c843f3df3b85 separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents: 1143
diff changeset
2542 static ngx_int_t
2268
33556140681a *) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents: 2267
diff changeset
2543 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
2544 {
7255
4db4fe3bdeda Upstream: fixed ngx_http_upstream_test_next() conditions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7239
diff changeset
2545 ngx_msec_t timeout;
4db4fe3bdeda Upstream: fixed ngx_http_upstream_test_next() conditions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7239
diff changeset
2546 ngx_uint_t status, mask;
2268
33556140681a *) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents: 2267
diff changeset
2547 ngx_http_upstream_next_t *un;
33556140681a *) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents: 2267
diff changeset
2548
33556140681a *) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents: 2267
diff changeset
2549 status = u->headers_in.status_n;
33556140681a *) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents: 2267
diff changeset
2550
33556140681a *) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents: 2267
diff changeset
2551 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
2552
33556140681a *) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents: 2267
diff changeset
2553 if (status != un->status) {
33556140681a *) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents: 2267
diff changeset
2554 continue;
33556140681a *) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents: 2267
diff changeset
2555 }
33556140681a *) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents: 2267
diff changeset
2556
7255
4db4fe3bdeda Upstream: fixed ngx_http_upstream_test_next() conditions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7239
diff changeset
2557 timeout = u->conf->next_upstream_timeout;
4db4fe3bdeda Upstream: fixed ngx_http_upstream_test_next() conditions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7239
diff changeset
2558
4db4fe3bdeda Upstream: fixed ngx_http_upstream_test_next() conditions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7239
diff changeset
2559 if (u->request_sent
4db4fe3bdeda Upstream: fixed ngx_http_upstream_test_next() conditions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7239
diff changeset
2560 && (r->method & (NGX_HTTP_POST|NGX_HTTP_LOCK|NGX_HTTP_PATCH)))
4db4fe3bdeda Upstream: fixed ngx_http_upstream_test_next() conditions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7239
diff changeset
2561 {
4db4fe3bdeda Upstream: fixed ngx_http_upstream_test_next() conditions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7239
diff changeset
2562 mask = un->mask | NGX_HTTP_UPSTREAM_FT_NON_IDEMPOTENT;
4db4fe3bdeda Upstream: fixed ngx_http_upstream_test_next() conditions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7239
diff changeset
2563
4db4fe3bdeda Upstream: fixed ngx_http_upstream_test_next() conditions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7239
diff changeset
2564 } else {
4db4fe3bdeda Upstream: fixed ngx_http_upstream_test_next() conditions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7239
diff changeset
2565 mask = un->mask;
4db4fe3bdeda Upstream: fixed ngx_http_upstream_test_next() conditions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7239
diff changeset
2566 }
4db4fe3bdeda Upstream: fixed ngx_http_upstream_test_next() conditions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7239
diff changeset
2567
4db4fe3bdeda Upstream: fixed ngx_http_upstream_test_next() conditions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7239
diff changeset
2568 if (u->peer.tries > 1
4db4fe3bdeda Upstream: fixed ngx_http_upstream_test_next() conditions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7239
diff changeset
2569 && ((u->conf->next_upstream & mask) == mask)
4db4fe3bdeda Upstream: fixed ngx_http_upstream_test_next() conditions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7239
diff changeset
2570 && !(u->request_sent && r->request_body_no_buffering)
4db4fe3bdeda Upstream: fixed ngx_http_upstream_test_next() conditions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7239
diff changeset
2571 && !(timeout && ngx_current_msec - u->peer.start_time >= timeout))
4db4fe3bdeda Upstream: fixed ngx_http_upstream_test_next() conditions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7239
diff changeset
2572 {
2268
33556140681a *) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents: 2267
diff changeset
2573 ngx_http_upstream_next(r, u, un->mask);
33556140681a *) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents: 2267
diff changeset
2574 return NGX_OK;
33556140681a *) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents: 2267
diff changeset
2575 }
33556140681a *) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents: 2267
diff changeset
2576
33556140681a *) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents: 2267
diff changeset
2577 #if (NGX_HTTP_CACHE)
33556140681a *) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents: 2267
diff changeset
2578
2952
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2949
diff changeset
2579 if (u->cache_status == NGX_HTTP_CACHE_EXPIRED
7702
7015f26aef90 Cache: ignore stale-if-error for 4xx and 5xx codes.
Roman Arutyunyan <arut@nginx.com>
parents: 7679
diff changeset
2580 && (u->conf->cache_use_stale & un->mask))
2952
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2949
diff changeset
2581 {
2824
d106509491b5 fix building --without-http-cache
Igor Sysoev <igor@sysoev.ru>
parents: 2807
diff changeset
2582 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
2583
60551422e150 reinit proxy/fastcgi header parser before ngx_http_upstream_cache_send()
Igor Sysoev <igor@sysoev.ru>
parents: 2804
diff changeset
2584 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
2585
7126
77fe752b4586 Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents: 7125
diff changeset
2586 if (rc != NGX_OK) {
77fe752b4586 Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents: 7125
diff changeset
2587 ngx_http_upstream_finalize_request(r, u, rc);
77fe752b4586 Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents: 7125
diff changeset
2588 return NGX_OK;
77fe752b4586 Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents: 7125
diff changeset
2589 }
77fe752b4586 Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents: 7125
diff changeset
2590
77fe752b4586 Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents: 7125
diff changeset
2591 u->cache_status = NGX_HTTP_CACHE_STALE;
77fe752b4586 Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents: 7125
diff changeset
2592 rc = ngx_http_upstream_cache_send(r, u);
77fe752b4586 Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents: 7125
diff changeset
2593
77fe752b4586 Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents: 7125
diff changeset
2594 if (rc == NGX_DONE) {
77fe752b4586 Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents: 7125
diff changeset
2595 return NGX_OK;
77fe752b4586 Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents: 7125
diff changeset
2596 }
77fe752b4586 Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents: 7125
diff changeset
2597
77fe752b4586 Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents: 7125
diff changeset
2598 if (rc == NGX_HTTP_UPSTREAM_INVALID_HEADER) {
77fe752b4586 Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents: 7125
diff changeset
2599 rc = NGX_HTTP_INTERNAL_SERVER_ERROR;
2805
60551422e150 reinit proxy/fastcgi header parser before ngx_http_upstream_cache_send()
Igor Sysoev <igor@sysoev.ru>
parents: 2804
diff changeset
2600 }
60551422e150 reinit proxy/fastcgi header parser before ngx_http_upstream_cache_send()
Igor Sysoev <igor@sysoev.ru>
parents: 2804
diff changeset
2601
60551422e150 reinit proxy/fastcgi header parser before ngx_http_upstream_cache_send()
Igor Sysoev <igor@sysoev.ru>
parents: 2804
diff changeset
2602 ngx_http_upstream_finalize_request(r, u, rc);
2268
33556140681a *) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents: 2267
diff changeset
2603 return NGX_OK;
33556140681a *) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents: 2267
diff changeset
2604 }
33556140681a *) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents: 2267
diff changeset
2605
33556140681a *) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents: 2267
diff changeset
2606 #endif
7649
3c8082c3f98a Upstream: jump out of loop after matching the status code.
Jinhua Tan <312841925@qq.com>
parents: 7538
diff changeset
2607
3c8082c3f98a Upstream: jump out of loop after matching the status code.
Jinhua Tan <312841925@qq.com>
parents: 7538
diff changeset
2608 break;
2268
33556140681a *) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents: 2267
diff changeset
2609 }
33556140681a *) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents: 2267
diff changeset
2610
5441
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
2611 #if (NGX_HTTP_CACHE)
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
2612
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
2613 if (status == NGX_HTTP_NOT_MODIFIED
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
2614 && u->cache_status == NGX_HTTP_CACHE_EXPIRED
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
2615 && u->conf->cache_revalidate)
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
2616 {
6905
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6899
diff changeset
2617 time_t now, valid, updating, error;
5441
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
2618 ngx_int_t rc;
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
2619
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
2620 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
2621 "http upstream not modified");
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
2622
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
2623 now = ngx_time();
6905
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6899
diff changeset
2624
5441
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
2625 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
2626 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
2627 error = r->cache->error_sec;
5441
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
2628
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
2629 rc = u->reinit_request(r);
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
2630
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
2631 if (rc != NGX_OK) {
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
2632 ngx_http_upstream_finalize_request(r, u, rc);
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
2633 return NGX_OK;
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
2634 }
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
2635
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
2636 u->cache_status = NGX_HTTP_CACHE_REVALIDATED;
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
2637 rc = ngx_http_upstream_cache_send(r, u);
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
2638
7126
77fe752b4586 Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents: 7125
diff changeset
2639 if (rc == NGX_DONE) {
77fe752b4586 Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents: 7125
diff changeset
2640 return NGX_OK;
77fe752b4586 Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents: 7125
diff changeset
2641 }
77fe752b4586 Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents: 7125
diff changeset
2642
77fe752b4586 Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents: 7125
diff changeset
2643 if (rc == NGX_HTTP_UPSTREAM_INVALID_HEADER) {
77fe752b4586 Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents: 7125
diff changeset
2644 rc = NGX_HTTP_INTERNAL_SERVER_ERROR;
77fe752b4586 Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents: 7125
diff changeset
2645 }
77fe752b4586 Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents: 7125
diff changeset
2646
5441
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
2647 if (valid == 0) {
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
2648 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
2649 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
2650 error = r->cache->error_sec;
5441
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
2651 }
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
2652
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
2653 if (valid == 0) {
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
2654 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
2655 u->headers_in.status_n);
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
2656 if (valid) {
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
2657 valid = now + valid;
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
2658 }
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
2659 }
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
2660
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
2661 if (valid) {
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
2662 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
2663 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
2664 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
2665
5441
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
2666 r->cache->date = now;
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
2667
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
2668 ngx_http_file_cache_update_header(r);
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
2669 }
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
2670
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
2671 ngx_http_upstream_finalize_request(r, u, rc);
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
2672 return NGX_OK;
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
2673 }
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
2674
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
2675 #endif
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
2676
2268
33556140681a *) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents: 2267
diff changeset
2677 return NGX_DECLINED;
33556140681a *) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents: 2267
diff changeset
2678 }
33556140681a *) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents: 2267
diff changeset
2679
33556140681a *) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents: 2267
diff changeset
2680
33556140681a *) ngx_http_upstream_test_next()
Igor Sysoev <igor@sysoev.ru>
parents: 2267
diff changeset
2681 static ngx_int_t
2267
920be89a3d2d ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents: 2244
diff changeset
2682 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
2683 ngx_http_upstream_t *u)
920be89a3d2d ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents: 2244
diff changeset
2684 {
920be89a3d2d ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents: 2244
diff changeset
2685 ngx_int_t status;
920be89a3d2d ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents: 2244
diff changeset
2686 ngx_uint_t i;
8036
f739c8142fb2 Upstream: multiple WWW-Authenticate headers (ticket #485).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8035
diff changeset
2687 ngx_table_elt_t *h, *ho, **ph;
2267
920be89a3d2d ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents: 2244
diff changeset
2688 ngx_http_err_page_t *err_page;
920be89a3d2d ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents: 2244
diff changeset
2689 ngx_http_core_loc_conf_t *clcf;
920be89a3d2d ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents: 2244
diff changeset
2690
2441
0c117a89f399 in miss case memcached module returned END instead of default 404 page body
Igor Sysoev <igor@sysoev.ru>
parents: 2422
diff changeset
2691 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
2692
0c117a89f399 in miss case memcached module returned END instead of default 404 page body
Igor Sysoev <igor@sysoev.ru>
parents: 2422
diff changeset
2693 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
2694 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
2695 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
2696 }
0c117a89f399 in miss case memcached module returned END instead of default 404 page body
Igor Sysoev <igor@sysoev.ru>
parents: 2422
diff changeset
2697
2267
920be89a3d2d ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents: 2244
diff changeset
2698 if (!u->conf->intercept_errors) {
920be89a3d2d ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents: 2244
diff changeset
2699 return NGX_DECLINED;
920be89a3d2d ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents: 2244
diff changeset
2700 }
920be89a3d2d ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents: 2244
diff changeset
2701
920be89a3d2d ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents: 2244
diff changeset
2702 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
2703
920be89a3d2d ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents: 2244
diff changeset
2704 if (clcf->error_pages == NULL) {
920be89a3d2d ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents: 2244
diff changeset
2705 return NGX_DECLINED;
920be89a3d2d ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents: 2244
diff changeset
2706 }
920be89a3d2d ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents: 2244
diff changeset
2707
920be89a3d2d ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents: 2244
diff changeset
2708 err_page = clcf->error_pages->elts;
920be89a3d2d ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents: 2244
diff changeset
2709 for (i = 0; i < clcf->error_pages->nelts; i++) {
920be89a3d2d ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents: 2244
diff changeset
2710
920be89a3d2d ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents: 2244
diff changeset
2711 if (err_page[i].status == status) {
920be89a3d2d ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents: 2244
diff changeset
2712
2953
aa12525236da fix segfault if there is error_page 401, proxy_intercept_errors is on
Igor Sysoev <igor@sysoev.ru>
parents: 2952
diff changeset
2713 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
2714 && 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
2715 {
8036
f739c8142fb2 Upstream: multiple WWW-Authenticate headers (ticket #485).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8035
diff changeset
2716 h = u->headers_in.www_authenticate;
f739c8142fb2 Upstream: multiple WWW-Authenticate headers (ticket #485).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8035
diff changeset
2717 ph = &r->headers_out.www_authenticate;
f739c8142fb2 Upstream: multiple WWW-Authenticate headers (ticket #485).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8035
diff changeset
2718
f739c8142fb2 Upstream: multiple WWW-Authenticate headers (ticket #485).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8035
diff changeset
2719 while (h) {
f739c8142fb2 Upstream: multiple WWW-Authenticate headers (ticket #485).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8035
diff changeset
2720 ho = ngx_list_push(&r->headers_out.headers);
f739c8142fb2 Upstream: multiple WWW-Authenticate headers (ticket #485).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8035
diff changeset
2721
f739c8142fb2 Upstream: multiple WWW-Authenticate headers (ticket #485).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8035
diff changeset
2722 if (ho == NULL) {
f739c8142fb2 Upstream: multiple WWW-Authenticate headers (ticket #485).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8035
diff changeset
2723 ngx_http_upstream_finalize_request(r, u,
2267
920be89a3d2d ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents: 2244
diff changeset
2724 NGX_HTTP_INTERNAL_SERVER_ERROR);
8036
f739c8142fb2 Upstream: multiple WWW-Authenticate headers (ticket #485).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8035
diff changeset
2725 return NGX_OK;
f739c8142fb2 Upstream: multiple WWW-Authenticate headers (ticket #485).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8035
diff changeset
2726 }
f739c8142fb2 Upstream: multiple WWW-Authenticate headers (ticket #485).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8035
diff changeset
2727
f739c8142fb2 Upstream: multiple WWW-Authenticate headers (ticket #485).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8035
diff changeset
2728 *ho = *h;
f739c8142fb2 Upstream: multiple WWW-Authenticate headers (ticket #485).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8035
diff changeset
2729 ho->next = NULL;
f739c8142fb2 Upstream: multiple WWW-Authenticate headers (ticket #485).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8035
diff changeset
2730
f739c8142fb2 Upstream: multiple WWW-Authenticate headers (ticket #485).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8035
diff changeset
2731 *ph = ho;
f739c8142fb2 Upstream: multiple WWW-Authenticate headers (ticket #485).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8035
diff changeset
2732 ph = &ho->next;
f739c8142fb2 Upstream: multiple WWW-Authenticate headers (ticket #485).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8035
diff changeset
2733
f739c8142fb2 Upstream: multiple WWW-Authenticate headers (ticket #485).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8035
diff changeset
2734 h = h->next;
2267
920be89a3d2d ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents: 2244
diff changeset
2735 }
920be89a3d2d ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents: 2244
diff changeset
2736 }
920be89a3d2d ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents: 2244
diff changeset
2737
3706
ea908f6ae499 an intercepted error code was not cached
Igor Sysoev <igor@sysoev.ru>
parents: 3705
diff changeset
2738 #if (NGX_HTTP_CACHE)
ea908f6ae499 an intercepted error code was not cached
Igor Sysoev <igor@sysoev.ru>
parents: 3705
diff changeset
2739
3709
64777690c697 fix r3707: cache node should be freed be a response is not cached
Igor Sysoev <igor@sysoev.ru>
parents: 3708
diff changeset
2740 if (r->cache) {
7117
dbd77a638eb7 Cache: fixed caching of intercepted errors (ticket #1382).
Maxim Dounin <mdounin@mdounin.ru>
parents: 7116
diff changeset
2741
8041
0784ab86ad08 Upstream: fixed X-Accel-Expires/Cache-Control/Expires handling.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8040
diff changeset
2742 if (u->headers_in.no_cache || u->headers_in.expired) {
0784ab86ad08 Upstream: fixed X-Accel-Expires/Cache-Control/Expires handling.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8040
diff changeset
2743 u->cacheable = 0;
0784ab86ad08 Upstream: fixed X-Accel-Expires/Cache-Control/Expires handling.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8040
diff changeset
2744 }
0784ab86ad08 Upstream: fixed X-Accel-Expires/Cache-Control/Expires handling.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8040
diff changeset
2745
7117
dbd77a638eb7 Cache: fixed caching of intercepted errors (ticket #1382).
Maxim Dounin <mdounin@mdounin.ru>
parents: 7116
diff changeset
2746 if (u->cacheable) {
dbd77a638eb7 Cache: fixed caching of intercepted errors (ticket #1382).
Maxim Dounin <mdounin@mdounin.ru>
parents: 7116
diff changeset
2747 time_t valid;
dbd77a638eb7 Cache: fixed caching of intercepted errors (ticket #1382).
Maxim Dounin <mdounin@mdounin.ru>
parents: 7116
diff changeset
2748
dbd77a638eb7 Cache: fixed caching of intercepted errors (ticket #1382).
Maxim Dounin <mdounin@mdounin.ru>
parents: 7116
diff changeset
2749 valid = r->cache->valid_sec;
dbd77a638eb7 Cache: fixed caching of intercepted errors (ticket #1382).
Maxim Dounin <mdounin@mdounin.ru>
parents: 7116
diff changeset
2750
dbd77a638eb7 Cache: fixed caching of intercepted errors (ticket #1382).
Maxim Dounin <mdounin@mdounin.ru>
parents: 7116
diff changeset
2751 if (valid == 0) {
dbd77a638eb7 Cache: fixed caching of intercepted errors (ticket #1382).
Maxim Dounin <mdounin@mdounin.ru>
parents: 7116
diff changeset
2752 valid = ngx_http_file_cache_valid(u->conf->cache_valid,
dbd77a638eb7 Cache: fixed caching of intercepted errors (ticket #1382).
Maxim Dounin <mdounin@mdounin.ru>
parents: 7116
diff changeset
2753 status);
dbd77a638eb7 Cache: fixed caching of intercepted errors (ticket #1382).
Maxim Dounin <mdounin@mdounin.ru>
parents: 7116
diff changeset
2754 if (valid) {
dbd77a638eb7 Cache: fixed caching of intercepted errors (ticket #1382).
Maxim Dounin <mdounin@mdounin.ru>
parents: 7116
diff changeset
2755 r->cache->valid_sec = ngx_time() + valid;
dbd77a638eb7 Cache: fixed caching of intercepted errors (ticket #1382).
Maxim Dounin <mdounin@mdounin.ru>
parents: 7116
diff changeset
2756 }
dbd77a638eb7 Cache: fixed caching of intercepted errors (ticket #1382).
Maxim Dounin <mdounin@mdounin.ru>
parents: 7116
diff changeset
2757 }
dbd77a638eb7 Cache: fixed caching of intercepted errors (ticket #1382).
Maxim Dounin <mdounin@mdounin.ru>
parents: 7116
diff changeset
2758
dbd77a638eb7 Cache: fixed caching of intercepted errors (ticket #1382).
Maxim Dounin <mdounin@mdounin.ru>
parents: 7116
diff changeset
2759 if (valid) {
dbd77a638eb7 Cache: fixed caching of intercepted errors (ticket #1382).
Maxim Dounin <mdounin@mdounin.ru>
parents: 7116
diff changeset
2760 r->cache->error = status;
dbd77a638eb7 Cache: fixed caching of intercepted errors (ticket #1382).
Maxim Dounin <mdounin@mdounin.ru>
parents: 7116
diff changeset
2761 }
3706
ea908f6ae499 an intercepted error code was not cached
Igor Sysoev <igor@sysoev.ru>
parents: 3705
diff changeset
2762 }
ea908f6ae499 an intercepted error code was not cached
Igor Sysoev <igor@sysoev.ru>
parents: 3705
diff changeset
2763
3711
ce6ba077c270 several changes in cache cleanup handling:
Igor Sysoev <igor@sysoev.ru>
parents: 3709
diff changeset
2764 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
2765 }
ea908f6ae499 an intercepted error code was not cached
Igor Sysoev <igor@sysoev.ru>
parents: 3705
diff changeset
2766 #endif
2267
920be89a3d2d ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents: 2244
diff changeset
2767 ngx_http_upstream_finalize_request(r, u, status);
920be89a3d2d ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents: 2244
diff changeset
2768
920be89a3d2d ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents: 2244
diff changeset
2769 return NGX_OK;
920be89a3d2d ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents: 2244
diff changeset
2770 }
920be89a3d2d ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents: 2244
diff changeset
2771 }
920be89a3d2d ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents: 2244
diff changeset
2772
920be89a3d2d ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents: 2244
diff changeset
2773 return NGX_DECLINED;
920be89a3d2d ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents: 2244
diff changeset
2774 }
920be89a3d2d ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents: 2244
diff changeset
2775
920be89a3d2d ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents: 2244
diff changeset
2776
920be89a3d2d ngx_http_upstream_intercept_errors()
Igor Sysoev <igor@sysoev.ru>
parents: 2244
diff changeset
2777 static ngx_int_t
1153
c843f3df3b85 separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents: 1143
diff changeset
2778 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
2779 {
c843f3df3b85 separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents: 1143
diff changeset
2780 int err;
c843f3df3b85 separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents: 1143
diff changeset
2781 socklen_t len;
c843f3df3b85 separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents: 1143
diff changeset
2782
c843f3df3b85 separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents: 1143
diff changeset
2783 #if (NGX_HAVE_KQUEUE)
c843f3df3b85 separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents: 1143
diff changeset
2784
c843f3df3b85 separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents: 1143
diff changeset
2785 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
2786 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
2787 if (c->write->pending_eof) {
e62219793beb Upstream: better detection of connect() failures with kqueue.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4895
diff changeset
2788 err = c->write->kq_errno;
e62219793beb Upstream: better detection of connect() failures with kqueue.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4895
diff changeset
2789
e62219793beb Upstream: better detection of connect() failures with kqueue.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4895
diff changeset
2790 } else {
e62219793beb Upstream: better detection of connect() failures with kqueue.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4895
diff changeset
2791 err = c->read->kq_errno;
e62219793beb Upstream: better detection of connect() failures with kqueue.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4895
diff changeset
2792 }
e62219793beb Upstream: better detection of connect() failures with kqueue.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4895
diff changeset
2793
1469
0a269c464eaf connection error should be logged with "connecting to upstream" action,
Igor Sysoev <igor@sysoev.ru>
parents: 1468
diff changeset
2794 c->log->action = "connecting to upstream";
4916
79c8e87b1fcb Trailing whitespace fix.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4915
diff changeset
2795 (void) ngx_connection_error(c, err,
1166
bde5e4134759 style fix: remove tabs
Igor Sysoev <igor@sysoev.ru>
parents: 1162
diff changeset
2796 "kevent() reported that connect() failed");
bde5e4134759 style fix: remove tabs
Igor Sysoev <igor@sysoev.ru>
parents: 1162
diff changeset
2797 return NGX_ERROR;
bde5e4134759 style fix: remove tabs
Igor Sysoev <igor@sysoev.ru>
parents: 1162
diff changeset
2798 }
1153
c843f3df3b85 separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents: 1143
diff changeset
2799
c843f3df3b85 separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents: 1143
diff changeset
2800 } else
c843f3df3b85 separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents: 1143
diff changeset
2801 #endif
c843f3df3b85 separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents: 1143
diff changeset
2802 {
1166
bde5e4134759 style fix: remove tabs
Igor Sysoev <igor@sysoev.ru>
parents: 1162
diff changeset
2803 err = 0;
bde5e4134759 style fix: remove tabs
Igor Sysoev <igor@sysoev.ru>
parents: 1162
diff changeset
2804 len = sizeof(int);
bde5e4134759 style fix: remove tabs
Igor Sysoev <igor@sysoev.ru>
parents: 1162
diff changeset
2805
bde5e4134759 style fix: remove tabs
Igor Sysoev <igor@sysoev.ru>
parents: 1162
diff changeset
2806 /*
bde5e4134759 style fix: remove tabs
Igor Sysoev <igor@sysoev.ru>
parents: 1162
diff changeset
2807 * BSDs and Linux return 0 and set a pending error in err
bde5e4134759 style fix: remove tabs
Igor Sysoev <igor@sysoev.ru>
parents: 1162
diff changeset
2808 * Solaris returns -1 and sets errno
bde5e4134759 style fix: remove tabs
Igor Sysoev <igor@sysoev.ru>
parents: 1162
diff changeset
2809 */
bde5e4134759 style fix: remove tabs
Igor Sysoev <igor@sysoev.ru>
parents: 1162
diff changeset
2810
bde5e4134759 style fix: remove tabs
Igor Sysoev <igor@sysoev.ru>
parents: 1162
diff changeset
2811 if (getsockopt(c->fd, SOL_SOCKET, SO_ERROR, (void *) &err, &len)
bde5e4134759 style fix: remove tabs
Igor Sysoev <igor@sysoev.ru>
parents: 1162
diff changeset
2812 == -1)
bde5e4134759 style fix: remove tabs
Igor Sysoev <igor@sysoev.ru>
parents: 1162
diff changeset
2813 {
5557
188481078faf Use ngx_socket_errno where appropriate.
Piotr Sikora <piotr@cloudflare.com>
parents: 5546
diff changeset
2814 err = ngx_socket_errno;
1166
bde5e4134759 style fix: remove tabs
Igor Sysoev <igor@sysoev.ru>
parents: 1162
diff changeset
2815 }
bde5e4134759 style fix: remove tabs
Igor Sysoev <igor@sysoev.ru>
parents: 1162
diff changeset
2816
bde5e4134759 style fix: remove tabs
Igor Sysoev <igor@sysoev.ru>
parents: 1162
diff changeset
2817 if (err) {
1469
0a269c464eaf connection error should be logged with "connecting to upstream" action,
Igor Sysoev <igor@sysoev.ru>
parents: 1468
diff changeset
2818 c->log->action = "connecting to upstream";
1166
bde5e4134759 style fix: remove tabs
Igor Sysoev <igor@sysoev.ru>
parents: 1162
diff changeset
2819 (void) ngx_connection_error(c, err, "connect() failed");
bde5e4134759 style fix: remove tabs
Igor Sysoev <igor@sysoev.ru>
parents: 1162
diff changeset
2820 return NGX_ERROR;
bde5e4134759 style fix: remove tabs
Igor Sysoev <igor@sysoev.ru>
parents: 1162
diff changeset
2821 }
1153
c843f3df3b85 separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents: 1143
diff changeset
2822 }
c843f3df3b85 separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents: 1143
diff changeset
2823
c843f3df3b85 separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents: 1143
diff changeset
2824 return NGX_OK;
c843f3df3b85 separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents: 1143
diff changeset
2825 }
c843f3df3b85 separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents: 1143
diff changeset
2826
c843f3df3b85 separate ngx_http_upstream_test_connect() and
Igor Sysoev <igor@sysoev.ru>
parents: 1143
diff changeset
2827
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2828 static ngx_int_t
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2829 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
2830 {
5489
6d357b2a9d6e Upstream: keep $upstream_http_x_accel_redirect intact.
Ruslan Ermilov <ru@nginx.com>
parents: 5477
diff changeset
2831 ngx_str_t uri, args;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2832 ngx_uint_t i, flags;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2833 ngx_list_part_t *part;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2834 ngx_table_elt_t *h;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2835 ngx_http_upstream_header_t *hh;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2836 ngx_http_upstream_main_conf_t *umcf;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2837
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2838 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
2839
8041
0784ab86ad08 Upstream: fixed X-Accel-Expires/Cache-Control/Expires handling.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8040
diff changeset
2840 if (u->headers_in.no_cache || u->headers_in.expired) {
0784ab86ad08 Upstream: fixed X-Accel-Expires/Cache-Control/Expires handling.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8040
diff changeset
2841 u->cacheable = 0;
0784ab86ad08 Upstream: fixed X-Accel-Expires/Cache-Control/Expires handling.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8040
diff changeset
2842 }
0784ab86ad08 Upstream: fixed X-Accel-Expires/Cache-Control/Expires handling.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8040
diff changeset
2843
2786
4e002555652d proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents: 2757
diff changeset
2844 if (u->headers_in.x_accel_redirect
4e002555652d proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents: 2757
diff changeset
2845 && !(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
2846 {
9217
6765e5f6d991 Upstream: fixed X-Accel-Redirect handling from cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9204
diff changeset
2847 if (u->cleanup) {
6765e5f6d991 Upstream: fixed X-Accel-Redirect handling from cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9204
diff changeset
2848 ngx_http_upstream_finalize_request(r, u, NGX_DECLINED);
6765e5f6d991 Upstream: fixed X-Accel-Redirect handling from cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9204
diff changeset
2849 }
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2850
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2851 part = &u->headers_in.headers.part;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2852 h = part->elts;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2853
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2854 for (i = 0; /* void */; i++) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2855
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2856 if (i >= part->nelts) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2857 if (part->next == NULL) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2858 break;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2859 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2860
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2861 part = part->next;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2862 h = part->elts;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2863 i = 0;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2864 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2865
8034
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
2866 if (h[i].hash == 0) {
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
2867 continue;
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
2868 }
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
2869
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2870 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
2871 h[i].lowcase_key, h[i].key.len);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2872
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2873 if (hh && hh->redirect) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2874 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
2875 ngx_http_finalize_request(r,
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2876 NGX_HTTP_INTERNAL_SERVER_ERROR);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2877 return NGX_DONE;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2878 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2879 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2880 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2881
5489
6d357b2a9d6e Upstream: keep $upstream_http_x_accel_redirect intact.
Ruslan Ermilov <ru@nginx.com>
parents: 5477
diff changeset
2882 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
2883
7d7eac6e31df Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents: 5885
diff changeset
2884 if (uri.data[0] == '@') {
7d7eac6e31df Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents: 5885
diff changeset
2885 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
2886
7d7eac6e31df Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents: 5885
diff changeset
2887 } else {
7d7eac6e31df Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents: 5885
diff changeset
2888 ngx_str_null(&args);
7d7eac6e31df Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents: 5885
diff changeset
2889 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
2890
7d7eac6e31df Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents: 5885
diff changeset
2891 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
2892 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
2893 return NGX_DONE;
7d7eac6e31df Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents: 5885
diff changeset
2894 }
7d7eac6e31df Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents: 5885
diff changeset
2895
7d7eac6e31df Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents: 5885
diff changeset
2896 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
2897 r->method = NGX_HTTP_GET;
6334
b31928ca3870 Upstream: fixed changing method on X-Accel-Redirect.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6332
diff changeset
2898 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
2899 }
7d7eac6e31df Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents: 5885
diff changeset
2900
7d7eac6e31df Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents: 5885
diff changeset
2901 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
2902 }
7d7eac6e31df Upstream: support named location for X-Accel-Redirect.
Toshikuni Fukaya <toshikuni-fukaya@cybozu.co.jp>
parents: 5885
diff changeset
2903
3120
40b8b398dbbc fix request counter for X-Accel-Redirect, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents: 3112
diff changeset
2904 ngx_http_finalize_request(r, NGX_DONE);
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2905 return NGX_DONE;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2906 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2907
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2908 part = &u->headers_in.headers.part;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2909 h = part->elts;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2910
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2911 for (i = 0; /* void */; i++) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2912
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2913 if (i >= part->nelts) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2914 if (part->next == NULL) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2915 break;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2916 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2917
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2918 part = part->next;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2919 h = part->elts;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2920 i = 0;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2921 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2922
8034
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
2923 if (h[i].hash == 0) {
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
2924 continue;
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
2925 }
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
2926
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2927 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
2928 h[i].lowcase_key, h[i].key.len))
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2929 {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2930 continue;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2931 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2932
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2933 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
2934 h[i].lowcase_key, h[i].key.len);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2935
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2936 if (hh) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2937 if (hh->copy_handler(r, &h[i], hh->conf) != NGX_OK) {
9217
6765e5f6d991 Upstream: fixed X-Accel-Redirect handling from cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9204
diff changeset
2938 return NGX_ERROR;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2939 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2940
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2941 continue;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2942 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2943
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2944 if (ngx_http_upstream_copy_header_line(r, &h[i], 0) != NGX_OK) {
9217
6765e5f6d991 Upstream: fixed X-Accel-Redirect handling from cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9204
diff changeset
2945 return NGX_ERROR;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2946 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2947 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2948
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2949 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
2950 r->headers_out.server->hash = 0;
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
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2953 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
2954 r->headers_out.date->hash = 0;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2955 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2956
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2957 r->headers_out.status = u->headers_in.status_n;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2958 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
2959
4117
103b0d9afe07 Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4116
diff changeset
2960 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
2961
5735
5fb1e57c758a Entity tags: explicit flag to skip not modified filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5732
diff changeset
2962 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
2963
5874
2aff40b3dea2 Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5869
diff changeset
2964 if (u->conf->force_ranges) {
2aff40b3dea2 Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5869
diff changeset
2965 r->allow_ranges = 1;
2aff40b3dea2 Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5869
diff changeset
2966 r->single_range = 1;
2aff40b3dea2 Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5869
diff changeset
2967
2aff40b3dea2 Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5869
diff changeset
2968 #if (NGX_HTTP_CACHE)
2aff40b3dea2 Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5869
diff changeset
2969 if (r->cached) {
2aff40b3dea2 Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5869
diff changeset
2970 r->single_range = 0;
2aff40b3dea2 Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5869
diff changeset
2971 }
2aff40b3dea2 Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5869
diff changeset
2972 #endif
2aff40b3dea2 Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5869
diff changeset
2973 }
2aff40b3dea2 Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5869
diff changeset
2974
5300
f538a67c9f77 Upstream: u->length now defaults to -1 (API change).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5299
diff changeset
2975 u->length = -1;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2976
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2977 return NGX_OK;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2978 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2979
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
2980
7230
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
2981 static ngx_int_t
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
2982 ngx_http_upstream_process_trailers(ngx_http_request_t *r,
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
2983 ngx_http_upstream_t *u)
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
2984 {
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
2985 ngx_uint_t i;
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
2986 ngx_list_part_t *part;
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
2987 ngx_table_elt_t *h, *ho;
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
2988
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
2989 if (!u->conf->pass_trailers) {
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
2990 return NGX_OK;
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
2991 }
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
2992
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
2993 part = &u->headers_in.trailers.part;
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
2994 h = part->elts;
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
2995
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
2996 for (i = 0; /* void */; i++) {
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
2997
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
2998 if (i >= part->nelts) {
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
2999 if (part->next == NULL) {
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
3000 break;
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
3001 }
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
3002
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
3003 part = part->next;
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
3004 h = part->elts;
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
3005 i = 0;
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
3006 }
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
3007
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
3008 if (ngx_hash_find(&u->conf->hide_headers_hash, h[i].hash,
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
3009 h[i].lowcase_key, h[i].key.len))
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
3010 {
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
3011 continue;
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
3012 }
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
3013
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
3014 ho = ngx_list_push(&r->headers_out.trailers);
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
3015 if (ho == NULL) {
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
3016 return NGX_ERROR;
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
3017 }
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
3018
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
3019 *ho = h[i];
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
3020 }
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
3021
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
3022 return NGX_OK;
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
3023 }
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
3024
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
3025
777
4ab852b691f5 <!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents: 757
diff changeset
3026 static void
681
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 675
diff changeset
3027 ngx_http_upstream_send_response(ngx_http_request_t *r, ngx_http_upstream_t *u)
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 675
diff changeset
3028 {
2402
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
3029 ssize_t n;
681
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 675
diff changeset
3030 ngx_int_t rc;
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 675
diff changeset
3031 ngx_event_pipe_t *p;
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 675
diff changeset
3032 ngx_connection_t *c;
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 675
diff changeset
3033 ngx_http_core_loc_conf_t *clcf;
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 675
diff changeset
3034
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
3035 rc = ngx_http_send_header(r);
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3036
2701
756f73ca1e39 support HEAD in proxy cache
Igor Sysoev <igor@sysoev.ru>
parents: 2692
diff changeset
3037 if (rc == NGX_ERROR || rc > NGX_OK || r->post_action) {
485
4ebe09b07e30 nginx-0.1.17-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 483
diff changeset
3038 ngx_http_upstream_finalize_request(r, u, rc);
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3039 return;
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3040 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3041
5353
1608b1135a1d Upstream: setting u->header_sent before ngx_http_upstream_upgrade().
Maxim Dounin <mdounin@mdounin.ru>
parents: 5340
diff changeset
3042 u->header_sent = 1;
1608b1135a1d Upstream: setting u->header_sent before ngx_http_upstream_upgrade().
Maxim Dounin <mdounin@mdounin.ru>
parents: 5340
diff changeset
3043
5072
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3044 if (u->upgrade) {
6794
93b294c5d581 Upstream: avoid holding a cache node with upgraded connections.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6793
diff changeset
3045
93b294c5d581 Upstream: avoid holding a cache node with upgraded connections.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6793
diff changeset
3046 #if (NGX_HTTP_CACHE)
93b294c5d581 Upstream: avoid holding a cache node with upgraded connections.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6793
diff changeset
3047
93b294c5d581 Upstream: avoid holding a cache node with upgraded connections.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6793
diff changeset
3048 if (r->cache) {
93b294c5d581 Upstream: avoid holding a cache node with upgraded connections.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6793
diff changeset
3049 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
3050 }
93b294c5d581 Upstream: avoid holding a cache node with upgraded connections.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6793
diff changeset
3051
93b294c5d581 Upstream: avoid holding a cache node with upgraded connections.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6793
diff changeset
3052 #endif
93b294c5d581 Upstream: avoid holding a cache node with upgraded connections.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6793
diff changeset
3053
5072
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3054 ngx_http_upstream_upgrade(r, u);
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3055 return;
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3056 }
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3057
2704
ac1e2e199c9f shutdown client connection for cacheable header only responses
Igor Sysoev <igor@sysoev.ru>
parents: 2703
diff changeset
3058 c = r->connection;
ac1e2e199c9f shutdown client connection for cacheable header only responses
Igor Sysoev <igor@sysoev.ru>
parents: 2703
diff changeset
3059
2701
756f73ca1e39 support HEAD in proxy cache
Igor Sysoev <igor@sysoev.ru>
parents: 2692
diff changeset
3060 if (r->header_only) {
2704
ac1e2e199c9f shutdown client connection for cacheable header only responses
Igor Sysoev <igor@sysoev.ru>
parents: 2703
diff changeset
3061
5746
35990c69b3ac Upstream: p->downstream_error instead of closing connection.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5745
diff changeset
3062 if (!u->buffering) {
2701
756f73ca1e39 support HEAD in proxy cache
Igor Sysoev <igor@sysoev.ru>
parents: 2692
diff changeset
3063 ngx_http_upstream_finalize_request(r, u, rc);
756f73ca1e39 support HEAD in proxy cache
Igor Sysoev <igor@sysoev.ru>
parents: 2692
diff changeset
3064 return;
756f73ca1e39 support HEAD in proxy cache
Igor Sysoev <igor@sysoev.ru>
parents: 2692
diff changeset
3065 }
5746
35990c69b3ac Upstream: p->downstream_error instead of closing connection.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5745
diff changeset
3066
35990c69b3ac Upstream: p->downstream_error instead of closing connection.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5745
diff changeset
3067 if (!u->cacheable && !u->store) {
35990c69b3ac Upstream: p->downstream_error instead of closing connection.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5745
diff changeset
3068 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
3069 return;
35990c69b3ac Upstream: p->downstream_error instead of closing connection.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5745
diff changeset
3070 }
35990c69b3ac Upstream: p->downstream_error instead of closing connection.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5745
diff changeset
3071
35990c69b3ac Upstream: p->downstream_error instead of closing connection.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5745
diff changeset
3072 u->pipe->downstream_error = 1;
2701
756f73ca1e39 support HEAD in proxy cache
Igor Sysoev <igor@sysoev.ru>
parents: 2692
diff changeset
3073 }
756f73ca1e39 support HEAD in proxy cache
Igor Sysoev <igor@sysoev.ru>
parents: 2692
diff changeset
3074
7070
f583559aadc7 Upstream: keep request body file from removal if requested.
Roman Arutyunyan <arut@nginx.com>
parents: 7067
diff changeset
3075 if (r->request_body && r->request_body->temp_file
7297
a10e5fe44762 Upstream: disable body cleanup with preserve_output (ticket #1565).
Maxim Dounin <mdounin@mdounin.ru>
parents: 7260
diff changeset
3076 && r == r->main && !r->preserve_body
a10e5fe44762 Upstream: disable body cleanup with preserve_output (ticket #1565).
Maxim Dounin <mdounin@mdounin.ru>
parents: 7260
diff changeset
3077 && !u->conf->preserve_output)
7070
f583559aadc7 Upstream: keep request body file from removal if requested.
Roman Arutyunyan <arut@nginx.com>
parents: 7067
diff changeset
3078 {
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
3079 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
3080 r->request_body->temp_file->file.fd = NGX_INVALID_FILE;
563
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
3081 }
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
3082
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3083 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3084
649
1e720b0be7ec nginx-0.3.46-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 641
diff changeset
3085 if (!u->buffering) {
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3086
6794
93b294c5d581 Upstream: avoid holding a cache node with upgraded connections.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6793
diff changeset
3087 #if (NGX_HTTP_CACHE)
93b294c5d581 Upstream: avoid holding a cache node with upgraded connections.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6793
diff changeset
3088
93b294c5d581 Upstream: avoid holding a cache node with upgraded connections.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6793
diff changeset
3089 if (r->cache) {
93b294c5d581 Upstream: avoid holding a cache node with upgraded connections.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6793
diff changeset
3090 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
3091 }
93b294c5d581 Upstream: avoid holding a cache node with upgraded connections.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6793
diff changeset
3092
93b294c5d581 Upstream: avoid holding a cache node with upgraded connections.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6793
diff changeset
3093 #endif
93b294c5d581 Upstream: avoid holding a cache node with upgraded connections.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6793
diff changeset
3094
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3095 if (u->input_filter == NULL) {
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3096 u->input_filter_init = ngx_http_upstream_non_buffered_filter_init;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3097 u->input_filter = ngx_http_upstream_non_buffered_filter;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3098 u->input_filter_ctx = r;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3099 }
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3100
2381
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
3101 u->read_event_handler = ngx_http_upstream_process_non_buffered_upstream;
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3102 r->write_event_handler =
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3103 ngx_http_upstream_process_non_buffered_downstream;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3104
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3105 r->limit_rate = 0;
7504
c19ca381b2e6 Variables support in limit_rate and limit_rate_after (ticket #293).
Ruslan Ermilov <ru@nginx.com>
parents: 7456
diff changeset
3106 r->limit_rate_set = 1;
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3107
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3108 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
3109 ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3110 return;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3111 }
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3112
7007
ed1101bbf19f Introduced ngx_tcp_nodelay().
Ruslan Ermilov <ru@nginx.com>
parents: 7006
diff changeset
3113 if (clcf->tcp_nodelay && ngx_tcp_nodelay(c) != NGX_OK) {
ed1101bbf19f Introduced ngx_tcp_nodelay().
Ruslan Ermilov <ru@nginx.com>
parents: 7006
diff changeset
3114 ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
ed1101bbf19f Introduced ngx_tcp_nodelay().
Ruslan Ermilov <ru@nginx.com>
parents: 7006
diff changeset
3115 return;
583
4e296b7d25bf nginx-0.3.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 581
diff changeset
3116 }
4e296b7d25bf nginx-0.3.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 581
diff changeset
3117
2402
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
3118 n = u->buffer.last - u->buffer.pos;
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
3119
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
3120 if (n) {
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3121 u->buffer.last = u->buffer.pos;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3122
2402
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
3123 u->state->response_length += n;
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
3124
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
3125 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
3126 ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3127 return;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3128 }
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3129
2381
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
3130 ngx_http_upstream_process_non_buffered_downstream(r);
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3131
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3132 } else {
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3133 u->buffer.pos = u->buffer.start;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3134 u->buffer.last = u->buffer.start;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3135
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3136 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
3137 ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3138 return;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3139 }
1468
491e5059ea19 read EOF of header only responses in non-buffered proxying
Igor Sysoev <igor@sysoev.ru>
parents: 1397
diff changeset
3140
7809
b1302f1dd2f6 Upstream: fixed non-buffered proxying with eventport.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7760
diff changeset
3141 ngx_http_upstream_process_non_buffered_upstream(r, u);
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3142 }
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3143
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3144 return;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3145 }
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3146
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3147 /* TODO: preallocate event_pipe bufs, look "Content-Length" */
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3148
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
3149 #if (NGX_HTTP_CACHE)
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
3150
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
3151 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
3152 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
3153 r->cache->file.fd = NGX_INVALID_FILE;
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3154 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3155
3699
b0a0686a85bb proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents: 3698
diff changeset
3156 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
3157
b0a0686a85bb proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents: 3698
diff changeset
3158 case NGX_ERROR:
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);
3699
b0a0686a85bb proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents: 3698
diff changeset
3160 return;
b0a0686a85bb proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents: 3698
diff changeset
3161
b0a0686a85bb proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents: 3698
diff changeset
3162 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
3163 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
3164 break;
b0a0686a85bb proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents: 3698
diff changeset
3165
b0a0686a85bb proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents: 3698
diff changeset
3166 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
3167
b0a0686a85bb proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents: 3698
diff changeset
3168 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
3169
5950
eaeecf00d5d7 Upstream: preset some cache configuration when bypassing.
Valentin Bartenev <vbart@nginx.com>
parents: 5949
diff changeset
3170 /* 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
3171
b0a0686a85bb proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents: 3698
diff changeset
3172 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
3173 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
3174 return;
b0a0686a85bb proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents: 3698
diff changeset
3175 }
b0a0686a85bb proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents: 3698
diff changeset
3176 }
b0a0686a85bb proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents: 3698
diff changeset
3177
b0a0686a85bb proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents: 3698
diff changeset
3178 break;
b0a0686a85bb proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents: 3698
diff changeset
3179 }
b0a0686a85bb proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents: 3698
diff changeset
3180
1565
4c43e25d11ea fix English grammar
Igor Sysoev <igor@sysoev.ru>
parents: 1559
diff changeset
3181 if (u->cacheable) {
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
3182 time_t now, valid;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
3183
2663
09725d69cb25 support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2662
diff changeset
3184 now = ngx_time();
09725d69cb25 support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2662
diff changeset
3185
09725d69cb25 support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2662
diff changeset
3186 valid = r->cache->valid_sec;
09725d69cb25 support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2662
diff changeset
3187
09725d69cb25 support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2662
diff changeset
3188 if (valid == 0) {
09725d69cb25 support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2662
diff changeset
3189 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
3190 u->headers_in.status_n);
09725d69cb25 support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2662
diff changeset
3191 if (valid) {
09725d69cb25 support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2662
diff changeset
3192 r->cache->valid_sec = now + valid;
09725d69cb25 support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2662
diff changeset
3193 }
09725d69cb25 support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2662
diff changeset
3194 }
09725d69cb25 support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2662
diff changeset
3195
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
3196 if (valid) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
3197 r->cache->date = now;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
3198 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
3199
5935
1573fc7875fa Cache: send conditional requests only for cached 200/206 responses.
Piotr Sikora <piotr@cloudflare.com>
parents: 5928
diff changeset
3200 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
3201 || 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
3202 {
1573fc7875fa Cache: send conditional requests only for cached 200/206 responses.
Piotr Sikora <piotr@cloudflare.com>
parents: 5928
diff changeset
3203 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
3204
1573fc7875fa Cache: send conditional requests only for cached 200/206 responses.
Piotr Sikora <piotr@cloudflare.com>
parents: 5928
diff changeset
3205 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
3206 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
3207
174512857ccf Cache: do not inherit last_modified and etag from stale response.
Roman Arutyunyan <arut@nginx.com>
parents: 5977
diff changeset
3208 } else {
174512857ccf Cache: do not inherit last_modified and etag from stale response.
Roman Arutyunyan <arut@nginx.com>
parents: 5977
diff changeset
3209 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
3210 }
5992
174512857ccf Cache: do not inherit last_modified and etag from stale response.
Roman Arutyunyan <arut@nginx.com>
parents: 5977
diff changeset
3211
174512857ccf Cache: do not inherit last_modified and etag from stale response.
Roman Arutyunyan <arut@nginx.com>
parents: 5977
diff changeset
3212 } else {
174512857ccf Cache: do not inherit last_modified and etag from stale response.
Roman Arutyunyan <arut@nginx.com>
parents: 5977
diff changeset
3213 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
3214 ngx_str_null(&r->cache->etag);
5737
44b9ab7752e3 Cache: ETag now saved into cache header.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5735
diff changeset
3215 }
44b9ab7752e3 Cache: ETag now saved into cache header.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5735
diff changeset
3216
5959
f7584d7c0ccb Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents: 5951
diff changeset
3217 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
3218 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
3219 return;
f7584d7c0ccb Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents: 5951
diff changeset
3220 }
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
3221
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
3222 } else {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
3223 u->cacheable = 0;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
3224 }
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3225 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3226
2690
d3cffe32b930 add debug logging
Igor Sysoev <igor@sysoev.ru>
parents: 2669
diff changeset
3227 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
d3cffe32b930 add debug logging
Igor Sysoev <igor@sysoev.ru>
parents: 2669
diff changeset
3228 "http cacheable: %d", u->cacheable);
d3cffe32b930 add debug logging
Igor Sysoev <igor@sysoev.ru>
parents: 2669
diff changeset
3229
3083
ffe8bfb38184 clean cache updating state if a response has uncacheable code or
Igor Sysoev <igor@sysoev.ru>
parents: 3056
diff changeset
3230 if (u->cacheable == 0 && r->cache) {
3711
ce6ba077c270 several changes in cache cleanup handling:
Igor Sysoev <igor@sysoev.ru>
parents: 3709
diff changeset
3231 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
3232 }
ffe8bfb38184 clean cache updating state if a response has uncacheable code or
Igor Sysoev <igor@sysoev.ru>
parents: 3056
diff changeset
3233
6428
545b5e4d83b2 Upstream: avoid closing client connection in edge case.
Justin Li <jli.justinli@gmail.com>
parents: 6427
diff changeset
3234 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
3235 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
3236 return;
545b5e4d83b2 Upstream: avoid closing client connection in edge case.
Justin Li <jli.justinli@gmail.com>
parents: 6427
diff changeset
3237 }
545b5e4d83b2 Upstream: avoid closing client connection in edge case.
Justin Li <jli.justinli@gmail.com>
parents: 6427
diff changeset
3238
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3239 #endif
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3240
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3241 p = u->pipe;
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3242
6443
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
3243 p->output_filter = ngx_http_upstream_output_filter;
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3244 p->output_ctx = r;
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3245 p->tag = u->output.tag;
577
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
3246 p->bufs = u->conf->bufs;
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3247 p->busy_size = u->conf->busy_buffers_size;
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3248 p->upstream = u->peer.connection;
583
4e296b7d25bf nginx-0.3.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 581
diff changeset
3249 p->downstream = c;
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3250 p->pool = r->pool;
583
4e296b7d25bf nginx-0.3.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 581
diff changeset
3251 p->log = c->log;
5883
973ee2276300 Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5878
diff changeset
3252 p->limit_rate = u->conf->limit_rate;
973ee2276300 Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5878
diff changeset
3253 p->start_sec = ngx_time();
577
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
3254
1565
4c43e25d11ea fix English grammar
Igor Sysoev <igor@sysoev.ru>
parents: 1559
diff changeset
3255 p->cacheable = u->cacheable || u->store;
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3256
501
d4ea69372b94 nginx-0.1.25-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 487
diff changeset
3257 p->temp_file = ngx_pcalloc(r->pool, sizeof(ngx_temp_file_t));
d4ea69372b94 nginx-0.1.25-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 487
diff changeset
3258 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
3259 ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3260 return;
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3261 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3262
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3263 p->temp_file->file.fd = NGX_INVALID_FILE;
583
4e296b7d25bf nginx-0.3.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 581
diff changeset
3264 p->temp_file->file.log = c->log;
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3265 p->temp_file->path = u->conf->temp_path;
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3266 p->temp_file->pool = r->pool;
577
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
3267
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
3268 if (p->cacheable) {
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3269 p->temp_file->persistent = 1;
1291
13a4ce6e7f1e proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents: 1284
diff changeset
3270
5960
e9effef98874 Upstream: use_temp_path parameter of proxy_cache_path and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5959
diff changeset
3271 #if (NGX_HTTP_CACHE)
6795
1a917932db96 Cache: prefix-based temporary files.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6794
diff changeset
3272 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
3273 p->temp_file->path = r->cache->file_cache->path;
1a917932db96 Cache: prefix-based temporary files.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6794
diff changeset
3274 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
3275 }
e9effef98874 Upstream: use_temp_path parameter of proxy_cache_path and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5959
diff changeset
3276 #endif
e9effef98874 Upstream: use_temp_path parameter of proxy_cache_path and friends.
Valentin Bartenev <vbart@nginx.com>
parents: 5959
diff changeset
3277
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3278 } else {
667
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 665
diff changeset
3279 p->temp_file->log_level = NGX_LOG_WARN;
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3280 p->temp_file->warn = "an upstream response is buffered "
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3281 "to a temporary file";
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3282 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3283
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3284 p->max_temp_file_size = u->conf->max_temp_file_size;
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3285 p->temp_file_write_size = u->conf->temp_file_write_size;
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3286
6443
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
3287 #if (NGX_THREADS)
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
3288 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
3289 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
3290 p->thread_ctx = r;
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
3291 }
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
3292 #endif
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
3293
501
d4ea69372b94 nginx-0.1.25-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 487
diff changeset
3294 p->preread_bufs = ngx_alloc_chain_link(r->pool);
d4ea69372b94 nginx-0.1.25-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 487
diff changeset
3295 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
3296 ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3297 return;
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3298 }
1291
13a4ce6e7f1e proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents: 1284
diff changeset
3299
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3300 p->preread_bufs->buf = &u->buffer;
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3301 p->preread_bufs->next = NULL;
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3302 u->buffer.recycled = 1;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3303
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3304 p->preread_size = u->buffer.last - u->buffer.pos;
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3305
1565
4c43e25d11ea fix English grammar
Igor Sysoev <igor@sysoev.ru>
parents: 1559
diff changeset
3306 if (u->cacheable) {
1291
13a4ce6e7f1e proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents: 1284
diff changeset
3307
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3308 p->buf_to_file = ngx_calloc_buf(r->pool);
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3309 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
3310 ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3311 return;
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3312 }
1291
13a4ce6e7f1e proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents: 1284
diff changeset
3313
4895
508e61393b6c Event pipe: fixed handling of buf_to_file data.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4769
diff changeset
3314 p->buf_to_file->start = u->buffer.start;
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3315 p->buf_to_file->pos = u->buffer.start;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3316 p->buf_to_file->last = u->buffer.pos;
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3317 p->buf_to_file->temporary = 1;
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3318 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3319
6125
4dc8e7b62216 Removed the obsolete aio module.
Ruslan Ermilov <ru@nginx.com>
parents: 6068
diff changeset
3320 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
3321 /* the posted aio operation may corrupt a shadow buffer */
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3322 p->single_buf = 1;
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3323 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3324
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3325 /* TODO: p->free_bufs = 0 if use ngx_create_chain_of_bufs() */
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3326 p->free_bufs = 1;
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3327
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3328 /*
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3329 * event_pipe would do u->buffer.last += p->preread_size
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3330 * as though these bytes were read
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3331 */
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3332 u->buffer.last = u->buffer.pos;
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3333
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3334 if (u->conf->cyclic_temp_file) {
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3335
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3336 /*
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3337 * we need to disable the use of sendfile() if we use cyclic temp file
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3338 * because the writing a new data may interfere with sendfile()
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3339 * that uses the same kernel file pages (at least on FreeBSD)
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3340 */
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3341
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3342 p->cyclic_temp_file = 1;
583
4e296b7d25bf nginx-0.3.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 581
diff changeset
3343 c->sendfile = 0;
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3344
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3345 } else {
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3346 p->cyclic_temp_file = 0;
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3347 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3348
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3349 p->read_timeout = u->conf->read_timeout;
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3350 p->send_timeout = clcf->send_timeout;
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3351 p->send_lowat = clcf->send_lowat;
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3352
4119
b66712cde67d Upstream: pipe length and input_filter_init in buffered mode.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4118
diff changeset
3353 p->length = -1;
b66712cde67d Upstream: pipe length and input_filter_init in buffered mode.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4118
diff changeset
3354
b66712cde67d Upstream: pipe length and input_filter_init in buffered mode.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4118
diff changeset
3355 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
3356 && 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
3357 {
5295
a489c31c9783 Upstream: ngx_http_upstream_finalize_request(NGX_ERROR) on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5294
diff changeset
3358 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
3359 return;
b66712cde67d Upstream: pipe length and input_filter_init in buffered mode.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4118
diff changeset
3360 }
b66712cde67d Upstream: pipe length and input_filter_init in buffered mode.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4118
diff changeset
3361
2381
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
3362 u->read_event_handler = ngx_http_upstream_process_upstream;
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
3363 r->write_event_handler = ngx_http_upstream_process_downstream;
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3364
2386
4ccaa42de633 use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents: 2381
diff changeset
3365 ngx_http_upstream_process_upstream(r, u);
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3366 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3367
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3368
487
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 485
diff changeset
3369 static void
5072
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3370 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
3371 {
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3372 ngx_connection_t *c;
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3373 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
3374
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3375 c = r->connection;
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3376 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
3377
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3378 /* 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
3379
7131
6a5a91de5b74 Upstream: disabled upgrading in subrequests.
Roman Arutyunyan <arut@nginx.com>
parents: 7130
diff changeset
3380 if (r != r->main) {
6a5a91de5b74 Upstream: disabled upgrading in subrequests.
Roman Arutyunyan <arut@nginx.com>
parents: 7130
diff changeset
3381 ngx_log_error(NGX_LOG_ERR, c->log, 0,
6a5a91de5b74 Upstream: disabled upgrading in subrequests.
Roman Arutyunyan <arut@nginx.com>
parents: 7130
diff changeset
3382 "connection upgrade in subrequest");
6a5a91de5b74 Upstream: disabled upgrading in subrequests.
Roman Arutyunyan <arut@nginx.com>
parents: 7130
diff changeset
3383 ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
6a5a91de5b74 Upstream: disabled upgrading in subrequests.
Roman Arutyunyan <arut@nginx.com>
parents: 7130
diff changeset
3384 return;
6a5a91de5b74 Upstream: disabled upgrading in subrequests.
Roman Arutyunyan <arut@nginx.com>
parents: 7130
diff changeset
3385 }
6a5a91de5b74 Upstream: disabled upgrading in subrequests.
Roman Arutyunyan <arut@nginx.com>
parents: 7130
diff changeset
3386
5072
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3387 r->keepalive = 0;
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3388 c->log->action = "proxying upgraded connection";
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 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
3391 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
3392 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
3393 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
3394
5142
afea5259e05c Upstream: fixed tcp_nodelay with connection upgrade (ticket #325).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5132
diff changeset
3395 if (clcf->tcp_nodelay) {
7007
ed1101bbf19f Introduced ngx_tcp_nodelay().
Ruslan Ermilov <ru@nginx.com>
parents: 7006
diff changeset
3396
ed1101bbf19f Introduced ngx_tcp_nodelay().
Ruslan Ermilov <ru@nginx.com>
parents: 7006
diff changeset
3397 if (ngx_tcp_nodelay(c) != NGX_OK) {
ed1101bbf19f Introduced ngx_tcp_nodelay().
Ruslan Ermilov <ru@nginx.com>
parents: 7006
diff changeset
3398 ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
ed1101bbf19f Introduced ngx_tcp_nodelay().
Ruslan Ermilov <ru@nginx.com>
parents: 7006
diff changeset
3399 return;
ed1101bbf19f Introduced ngx_tcp_nodelay().
Ruslan Ermilov <ru@nginx.com>
parents: 7006
diff changeset
3400 }
ed1101bbf19f Introduced ngx_tcp_nodelay().
Ruslan Ermilov <ru@nginx.com>
parents: 7006
diff changeset
3401
ed1101bbf19f Introduced ngx_tcp_nodelay().
Ruslan Ermilov <ru@nginx.com>
parents: 7006
diff changeset
3402 if (ngx_tcp_nodelay(u->peer.connection) != NGX_OK) {
ed1101bbf19f Introduced ngx_tcp_nodelay().
Ruslan Ermilov <ru@nginx.com>
parents: 7006
diff changeset
3403 ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
ed1101bbf19f Introduced ngx_tcp_nodelay().
Ruslan Ermilov <ru@nginx.com>
parents: 7006
diff changeset
3404 return;
5072
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3405 }
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3406 }
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3407
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3408 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
3409 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
3410 return;
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3411 }
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3412
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3413 if (u->peer.connection->read->ready
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3414 || u->buffer.pos != u->buffer.last)
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3415 {
5579
7586e7b2dbe9 Upstream: ngx_post_event() instead of upgraded call (ticket #503).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5557
diff changeset
3416 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
3417 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
3418 return;
5072
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3419 }
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3420
5532
17134d29782e Upstream: reading from a client after connection upgrade.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5500
diff changeset
3421 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
3422 }
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3423
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3424
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3425 static void
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3426 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
3427 {
5073
52eb762c68a9 Proxy: fixed do_write handling in previous commit.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5072
diff changeset
3428 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
3429 }
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3430
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3431
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3432 static void
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3433 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
3434 {
5073
52eb762c68a9 Proxy: fixed do_write handling in previous commit.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5072
diff changeset
3435 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
3436 }
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3437
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3438
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3439 static void
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3440 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
3441 ngx_http_upstream_t *u)
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3442 {
5073
52eb762c68a9 Proxy: fixed do_write handling in previous commit.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5072
diff changeset
3443 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
3444 }
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3445
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3446
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3447 static void
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3448 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
3449 ngx_http_upstream_t *u)
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3450 {
5073
52eb762c68a9 Proxy: fixed do_write handling in previous commit.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5072
diff changeset
3451 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
3452 }
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3453
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3454
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3455 static void
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3456 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
3457 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
3458 {
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3459 size_t size;
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3460 ssize_t n;
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3461 ngx_buf_t *b;
7538
08ed570ad93c Upstream: fixed EOF handling in unbuffered and upgraded modes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7514
diff changeset
3462 ngx_uint_t flags;
5072
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3463 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
3464 ngx_http_upstream_t *u;
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3465 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
3466
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3467 c = r->connection;
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3468 u = r->upstream;
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3469
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3470 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
3471 "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
3472
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3473 downstream = c;
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3474 upstream = u->peer.connection;
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3475
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3476 if (downstream->write->timedout) {
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3477 c->timedout = 1;
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3478 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
3479 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
3480 return;
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3481 }
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3482
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3483 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
3484 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
3485 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
3486 return;
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3487 }
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3488
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3489 if (from_upstream) {
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3490 src = upstream;
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3491 dst = downstream;
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3492 b = &u->buffer;
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3493
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3494 } else {
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3495 src = downstream;
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3496 dst = upstream;
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3497 b = &u->from_client;
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3498
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3499 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
3500 b = r->header_in;
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3501 b->end = b->last;
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3502 do_write = 1;
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3503 }
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3504
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3505 if (b->start == NULL) {
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3506 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
3507 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
3508 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
3509 return;
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3510 }
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3511
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3512 b->pos = b->start;
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3513 b->last = b->start;
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3514 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
3515 b->temporary = 1;
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3516 b->tag = u->output.tag;
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3517 }
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3518 }
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3519
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3520 for ( ;; ) {
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3521
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3522 if (do_write) {
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3523
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3524 size = b->last - b->pos;
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3525
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3526 if (size && dst->write->ready) {
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3527
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3528 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
3529
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3530 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
3531 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
3532 return;
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3533 }
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3534
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3535 if (n > 0) {
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3536 b->pos += n;
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3537
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3538 if (b->pos == b->last) {
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3539 b->pos = b->start;
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3540 b->last = b->start;
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3541 }
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3542 }
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3543 }
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3544 }
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3545
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3546 size = b->end - b->last;
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3547
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3548 if (size && src->read->ready) {
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3549
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3550 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
3551
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3552 if (n == NGX_AGAIN || n == 0) {
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3553 break;
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3554 }
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3555
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3556 if (n > 0) {
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3557 do_write = 1;
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3558 b->last += n;
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3559
6654
c131f20c9562 Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents: 6594
diff changeset
3560 if (from_upstream) {
c131f20c9562 Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents: 6594
diff changeset
3561 u->state->bytes_received += n;
c131f20c9562 Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents: 6594
diff changeset
3562 }
c131f20c9562 Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents: 6594
diff changeset
3563
5072
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3564 continue;
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3565 }
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3566
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3567 if (n == NGX_ERROR) {
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3568 src->read->eof = 1;
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3569 }
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3570 }
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3571
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3572 break;
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3573 }
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3574
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3575 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
3576 || (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
3577 || (downstream->read->eof && upstream->read->eof))
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3578 {
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3579 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
3580 "http upstream upgraded done");
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3581 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
3582 return;
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3583 }
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3584
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3585 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
3586
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3587 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
3588 != NGX_OK)
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3589 {
5295
a489c31c9783 Upstream: ngx_http_upstream_finalize_request(NGX_ERROR) on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5294
diff changeset
3590 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
3591 return;
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3592 }
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3593
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3594 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
3595 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
3596
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3597 } else if (upstream->write->timer_set) {
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3598 ngx_del_timer(upstream->write);
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3599 }
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3600
7538
08ed570ad93c Upstream: fixed EOF handling in unbuffered and upgraded modes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7514
diff changeset
3601 if (upstream->read->eof || upstream->read->error) {
08ed570ad93c Upstream: fixed EOF handling in unbuffered and upgraded modes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7514
diff changeset
3602 flags = NGX_CLOSE_EVENT;
08ed570ad93c Upstream: fixed EOF handling in unbuffered and upgraded modes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7514
diff changeset
3603
08ed570ad93c Upstream: fixed EOF handling in unbuffered and upgraded modes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7514
diff changeset
3604 } else {
08ed570ad93c Upstream: fixed EOF handling in unbuffered and upgraded modes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7514
diff changeset
3605 flags = 0;
08ed570ad93c Upstream: fixed EOF handling in unbuffered and upgraded modes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7514
diff changeset
3606 }
08ed570ad93c Upstream: fixed EOF handling in unbuffered and upgraded modes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7514
diff changeset
3607
08ed570ad93c Upstream: fixed EOF handling in unbuffered and upgraded modes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7514
diff changeset
3608 if (ngx_handle_read_event(upstream->read, flags) != NGX_OK) {
5295
a489c31c9783 Upstream: ngx_http_upstream_finalize_request(NGX_ERROR) on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5294
diff changeset
3609 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
3610 return;
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3611 }
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3612
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3613 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
3614 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
3615
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3616 } else if (upstream->read->timer_set) {
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3617 ngx_del_timer(upstream->read);
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3618 }
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3619
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3620 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
3621 != NGX_OK)
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3622 {
5295
a489c31c9783 Upstream: ngx_http_upstream_finalize_request(NGX_ERROR) on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5294
diff changeset
3623 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
3624 return;
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3625 }
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3626
7538
08ed570ad93c Upstream: fixed EOF handling in unbuffered and upgraded modes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7514
diff changeset
3627 if (downstream->read->eof || downstream->read->error) {
08ed570ad93c Upstream: fixed EOF handling in unbuffered and upgraded modes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7514
diff changeset
3628 flags = NGX_CLOSE_EVENT;
08ed570ad93c Upstream: fixed EOF handling in unbuffered and upgraded modes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7514
diff changeset
3629
08ed570ad93c Upstream: fixed EOF handling in unbuffered and upgraded modes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7514
diff changeset
3630 } else {
08ed570ad93c Upstream: fixed EOF handling in unbuffered and upgraded modes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7514
diff changeset
3631 flags = 0;
08ed570ad93c Upstream: fixed EOF handling in unbuffered and upgraded modes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7514
diff changeset
3632 }
08ed570ad93c Upstream: fixed EOF handling in unbuffered and upgraded modes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7514
diff changeset
3633
08ed570ad93c Upstream: fixed EOF handling in unbuffered and upgraded modes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7514
diff changeset
3634 if (ngx_handle_read_event(downstream->read, flags) != NGX_OK) {
5295
a489c31c9783 Upstream: ngx_http_upstream_finalize_request(NGX_ERROR) on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5294
diff changeset
3635 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
3636 return;
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3637 }
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3638
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3639 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
3640 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
3641
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3642 } else if (downstream->write->timer_set) {
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3643 ngx_del_timer(downstream->write);
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3644 }
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3645 }
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3646
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3647
7fa7e60a7f66 Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5008
diff changeset
3648 static void
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3649 ngx_http_upstream_process_non_buffered_downstream(ngx_http_request_t *r)
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3650 {
2381
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
3651 ngx_event_t *wev;
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
3652 ngx_connection_t *c;
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
3653 ngx_http_upstream_t *u;
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
3654
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
3655 c = r->connection;
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
3656 u = r->upstream;
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
3657 wev = c->write;
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
3658
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
3659 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
3660 "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
3661
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
3662 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
3663
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
3664 if (wev->timedout) {
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
3665 c->timedout = 1;
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
3666 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
3667 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
3668 return;
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
3669 }
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
3670
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
3671 ngx_http_upstream_process_non_buffered_request(r, 1);
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3672 }
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3673
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3674
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3675 static void
2386
4ccaa42de633 use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents: 2381
diff changeset
3676 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
3677 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
3678 {
2386
4ccaa42de633 use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents: 2381
diff changeset
3679 ngx_connection_t *c;
4ccaa42de633 use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents: 2381
diff changeset
3680
4ccaa42de633 use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents: 2381
diff changeset
3681 c = u->peer.connection;
2381
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
3682
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
3683 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
3684 "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
3685
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
3686 c->log->action = "reading upstream";
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
3687
2386
4ccaa42de633 use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents: 2381
diff changeset
3688 if (c->read->timedout) {
2381
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
3689 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
3690 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
3691 return;
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
3692 }
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
3693
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
3694 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
3695 }
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
3696
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
3697
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
3698 static void
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
3699 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
3700 ngx_uint_t do_write)
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3701 {
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3702 size_t size;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3703 ssize_t n;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3704 ngx_buf_t *b;
583
4e296b7d25bf nginx-0.3.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 581
diff changeset
3705 ngx_int_t rc;
7538
08ed570ad93c Upstream: fixed EOF handling in unbuffered and upgraded modes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7514
diff changeset
3706 ngx_uint_t flags;
2381
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
3707 ngx_connection_t *downstream, *upstream;
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3708 ngx_http_upstream_t *u;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3709 ngx_http_core_loc_conf_t *clcf;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3710
756
d904b5cb3bba fix building introduced by previous commit
Igor Sysoev <igor@sysoev.ru>
parents: 755
diff changeset
3711 u = r->upstream;
884
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
3712 downstream = r->connection;
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
3713 upstream = u->peer.connection;
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3714
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3715 b = &u->buffer;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3716
2381
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
3717 do_write = do_write || u->length == 0;
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3718
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3719 for ( ;; ) {
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3720
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3721 if (do_write) {
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3722
7166
a762ddf22dbb Upstream: flush low-level buffers on write retry.
Patryk Lesiewicz <patryk@google.com>
parents: 7131
diff changeset
3723 if (u->out_bufs || u->busy_bufs || downstream->buffered) {
583
4e296b7d25bf nginx-0.3.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 581
diff changeset
3724 rc = ngx_http_output_filter(r, u->out_bufs);
4e296b7d25bf nginx-0.3.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 581
diff changeset
3725
4e296b7d25bf nginx-0.3.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 581
diff changeset
3726 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
3727 ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3728 return;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3729 }
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3730
4114
5db098f97e0e API change: ngx_chain_update_chains() now requires pool.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3976
diff changeset
3731 ngx_chain_update_chains(r->pool, &u->free_bufs, &u->busy_bufs,
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3732 &u->out_bufs, u->output.tag);
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3733 }
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3734
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3735 if (u->busy_bufs == NULL) {
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3736
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3737 if (u->length == 0
5301
a50e26148d21 Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5300
diff changeset
3738 || (upstream->read->eof && u->length == -1))
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3739 {
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3740 ngx_http_upstream_finalize_request(r, u, 0);
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3741 return;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3742 }
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3743
5301
a50e26148d21 Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5300
diff changeset
3744 if (upstream->read->eof) {
a50e26148d21 Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5300
diff changeset
3745 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
3746 "upstream prematurely closed connection");
a50e26148d21 Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5300
diff changeset
3747
a50e26148d21 Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5300
diff changeset
3748 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
3749 NGX_HTTP_BAD_GATEWAY);
a50e26148d21 Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5300
diff changeset
3750 return;
a50e26148d21 Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5300
diff changeset
3751 }
a50e26148d21 Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5300
diff changeset
3752
7679
05e42236e95b FastCGI: protection from responses with wrong length.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7678
diff changeset
3753 if (upstream->read->error || u->error) {
5301
a50e26148d21 Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5300
diff changeset
3754 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
3755 NGX_HTTP_BAD_GATEWAY);
a50e26148d21 Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5300
diff changeset
3756 return;
a50e26148d21 Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5300
diff changeset
3757 }
a50e26148d21 Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5300
diff changeset
3758
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3759 b->pos = b->start;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3760 b->last = b->start;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3761 }
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3762 }
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3763
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3764 size = b->end - b->last;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3765
884
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
3766 if (size && upstream->read->ready) {
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
3767
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
3768 n = upstream->recv(upstream, b->last, size);
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3769
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3770 if (n == NGX_AGAIN) {
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3771 break;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3772 }
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3773
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3774 if (n > 0) {
6654
c131f20c9562 Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents: 6594
diff changeset
3775 u->state->bytes_received += n;
2402
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
3776 u->state->response_length += n;
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
3777
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3778 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
3779 ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3780 return;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3781 }
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3782 }
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3783
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3784 do_write = 1;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3785
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3786 continue;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3787 }
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3788
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3789 break;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3790 }
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3791
2381
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
3792 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
3793
884
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
3794 if (downstream->data == r) {
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
3795 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
3796 != NGX_OK)
583
4e296b7d25bf nginx-0.3.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 581
diff changeset
3797 {
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);
583
4e296b7d25bf nginx-0.3.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 581
diff changeset
3799 return;
4e296b7d25bf nginx-0.3.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 581
diff changeset
3800 }
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3801 }
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3802
1063
e2a6ecc5a3ae a non-active client connection must not closed after send timeout
Igor Sysoev <igor@sysoev.ru>
parents: 1031
diff changeset
3803 if (downstream->write->active && !downstream->write->ready) {
884
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
3804 ngx_add_timer(downstream->write, clcf->send_timeout);
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
3805
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
3806 } else if (downstream->write->timer_set) {
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
3807 ngx_del_timer(downstream->write);
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3808 }
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3809
7538
08ed570ad93c Upstream: fixed EOF handling in unbuffered and upgraded modes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7514
diff changeset
3810 if (upstream->read->eof || upstream->read->error) {
08ed570ad93c Upstream: fixed EOF handling in unbuffered and upgraded modes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7514
diff changeset
3811 flags = NGX_CLOSE_EVENT;
08ed570ad93c Upstream: fixed EOF handling in unbuffered and upgraded modes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7514
diff changeset
3812
08ed570ad93c Upstream: fixed EOF handling in unbuffered and upgraded modes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7514
diff changeset
3813 } else {
08ed570ad93c Upstream: fixed EOF handling in unbuffered and upgraded modes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7514
diff changeset
3814 flags = 0;
08ed570ad93c Upstream: fixed EOF handling in unbuffered and upgraded modes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7514
diff changeset
3815 }
08ed570ad93c Upstream: fixed EOF handling in unbuffered and upgraded modes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7514
diff changeset
3816
08ed570ad93c Upstream: fixed EOF handling in unbuffered and upgraded modes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7514
diff changeset
3817 if (ngx_handle_read_event(upstream->read, flags) != NGX_OK) {
5295
a489c31c9783 Upstream: ngx_http_upstream_finalize_request(NGX_ERROR) on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5294
diff changeset
3818 ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3819 return;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3820 }
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3821
1063
e2a6ecc5a3ae a non-active client connection must not closed after send timeout
Igor Sysoev <igor@sysoev.ru>
parents: 1031
diff changeset
3822 if (upstream->read->active && !upstream->read->ready) {
884
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
3823 ngx_add_timer(upstream->read, u->conf->read_timeout);
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
3824
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
3825 } else if (upstream->read->timer_set) {
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
3826 ngx_del_timer(upstream->read);
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3827 }
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3828 }
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3829
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3830
7678
bffcc5af1d72 Upstream: drop extra data sent by upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7649
diff changeset
3831 ngx_int_t
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3832 ngx_http_upstream_non_buffered_filter_init(void *data)
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3833 {
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3834 return NGX_OK;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3835 }
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3836
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3837
7678
bffcc5af1d72 Upstream: drop extra data sent by upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7649
diff changeset
3838 ngx_int_t
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3839 ngx_http_upstream_non_buffered_filter(void *data, ssize_t bytes)
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3840 {
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3841 ngx_http_request_t *r = data;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3842
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3843 ngx_buf_t *b;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3844 ngx_chain_t *cl, **ll;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3845 ngx_http_upstream_t *u;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3846
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3847 u = r->upstream;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3848
7760
83c4622053b0 Upstream: fixed zero size buf alerts on extra data (ticket #2117).
Maxim Dounin <mdounin@mdounin.ru>
parents: 7702
diff changeset
3849 if (u->length == 0) {
83c4622053b0 Upstream: fixed zero size buf alerts on extra data (ticket #2117).
Maxim Dounin <mdounin@mdounin.ru>
parents: 7702
diff changeset
3850 ngx_log_error(NGX_LOG_WARN, r->connection->log, 0,
83c4622053b0 Upstream: fixed zero size buf alerts on extra data (ticket #2117).
Maxim Dounin <mdounin@mdounin.ru>
parents: 7702
diff changeset
3851 "upstream sent more data than specified in "
83c4622053b0 Upstream: fixed zero size buf alerts on extra data (ticket #2117).
Maxim Dounin <mdounin@mdounin.ru>
parents: 7702
diff changeset
3852 "\"Content-Length\" header");
83c4622053b0 Upstream: fixed zero size buf alerts on extra data (ticket #2117).
Maxim Dounin <mdounin@mdounin.ru>
parents: 7702
diff changeset
3853 return NGX_OK;
83c4622053b0 Upstream: fixed zero size buf alerts on extra data (ticket #2117).
Maxim Dounin <mdounin@mdounin.ru>
parents: 7702
diff changeset
3854 }
83c4622053b0 Upstream: fixed zero size buf alerts on extra data (ticket #2117).
Maxim Dounin <mdounin@mdounin.ru>
parents: 7702
diff changeset
3855
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3856 for (cl = u->out_bufs, ll = &u->out_bufs; cl; cl = cl->next) {
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3857 ll = &cl->next;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3858 }
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3859
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3860 cl = ngx_chain_get_free_buf(r->pool, &u->free_bufs);
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3861 if (cl == NULL) {
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3862 return NGX_ERROR;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3863 }
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3864
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3865 *ll = cl;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3866
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3867 cl->buf->flush = 1;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3868 cl->buf->memory = 1;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3869
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3870 b = &u->buffer;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3871
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3872 cl->buf->pos = b->last;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3873 b->last += bytes;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3874 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
3875 cl->buf->tag = u->output.tag;
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3876
4118
dbddec65fdab Upstream: r->upstream->length type change to off_t.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4117
diff changeset
3877 if (u->length == -1) {
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3878 return NGX_OK;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3879 }
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3880
7678
bffcc5af1d72 Upstream: drop extra data sent by upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7649
diff changeset
3881 if (bytes > u->length) {
bffcc5af1d72 Upstream: drop extra data sent by upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7649
diff changeset
3882
bffcc5af1d72 Upstream: drop extra data sent by upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7649
diff changeset
3883 ngx_log_error(NGX_LOG_WARN, r->connection->log, 0,
bffcc5af1d72 Upstream: drop extra data sent by upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7649
diff changeset
3884 "upstream sent more data than specified in "
bffcc5af1d72 Upstream: drop extra data sent by upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7649
diff changeset
3885 "\"Content-Length\" header");
bffcc5af1d72 Upstream: drop extra data sent by upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7649
diff changeset
3886
bffcc5af1d72 Upstream: drop extra data sent by upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7649
diff changeset
3887 cl->buf->last = cl->buf->pos + u->length;
bffcc5af1d72 Upstream: drop extra data sent by upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7649
diff changeset
3888 u->length = 0;
bffcc5af1d72 Upstream: drop extra data sent by upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7649
diff changeset
3889
bffcc5af1d72 Upstream: drop extra data sent by upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7649
diff changeset
3890 return NGX_OK;
bffcc5af1d72 Upstream: drop extra data sent by upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7649
diff changeset
3891 }
bffcc5af1d72 Upstream: drop extra data sent by upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7649
diff changeset
3892
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3893 u->length -= bytes;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3894
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3895 return NGX_OK;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3896 }
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3897
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
3898
6443
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
3899 #if (NGX_THREADS)
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
3900
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
3901 static ngx_int_t
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
3902 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
3903 {
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
3904 ngx_str_t name;
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
3905 ngx_event_pipe_t *p;
7974
555533169506 HTTP/2: fixed "task already active" with sendfile in threads.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7949
diff changeset
3906 ngx_connection_t *c;
6443
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
3907 ngx_thread_pool_t *tp;
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
3908 ngx_http_request_t *r;
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
3909 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
3910
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
3911 r = file->thread_ctx;
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
3912 p = r->upstream->pipe;
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
3913
7974
555533169506 HTTP/2: fixed "task already active" with sendfile in threads.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7949
diff changeset
3914 if (r->aio) {
555533169506 HTTP/2: fixed "task already active" with sendfile in threads.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7949
diff changeset
3915 /*
555533169506 HTTP/2: fixed "task already active" with sendfile in threads.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7949
diff changeset
3916 * tolerate sendfile() calls if another operation is already
555533169506 HTTP/2: fixed "task already active" with sendfile in threads.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7949
diff changeset
3917 * running; this can happen due to subrequests, multiple calls
555533169506 HTTP/2: fixed "task already active" with sendfile in threads.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7949
diff changeset
3918 * of the next body filter from a filter, or in HTTP/2 due to
555533169506 HTTP/2: fixed "task already active" with sendfile in threads.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7949
diff changeset
3919 * a write event on the main connection
555533169506 HTTP/2: fixed "task already active" with sendfile in threads.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7949
diff changeset
3920 */
555533169506 HTTP/2: fixed "task already active" with sendfile in threads.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7949
diff changeset
3921
555533169506 HTTP/2: fixed "task already active" with sendfile in threads.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7949
diff changeset
3922 c = r->connection;
555533169506 HTTP/2: fixed "task already active" with sendfile in threads.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7949
diff changeset
3923
555533169506 HTTP/2: fixed "task already active" with sendfile in threads.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7949
diff changeset
3924 #if (NGX_HTTP_V2)
555533169506 HTTP/2: fixed "task already active" with sendfile in threads.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7949
diff changeset
3925 if (r->stream) {
555533169506 HTTP/2: fixed "task already active" with sendfile in threads.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7949
diff changeset
3926 c = r->stream->connection->connection;
555533169506 HTTP/2: fixed "task already active" with sendfile in threads.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7949
diff changeset
3927 }
555533169506 HTTP/2: fixed "task already active" with sendfile in threads.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7949
diff changeset
3928 #endif
555533169506 HTTP/2: fixed "task already active" with sendfile in threads.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7949
diff changeset
3929
555533169506 HTTP/2: fixed "task already active" with sendfile in threads.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7949
diff changeset
3930 if (task == c->sendfile_task) {
555533169506 HTTP/2: fixed "task already active" with sendfile in threads.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7949
diff changeset
3931 return NGX_OK;
555533169506 HTTP/2: fixed "task already active" with sendfile in threads.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7949
diff changeset
3932 }
555533169506 HTTP/2: fixed "task already active" with sendfile in threads.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7949
diff changeset
3933 }
555533169506 HTTP/2: fixed "task already active" with sendfile in threads.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7949
diff changeset
3934
6443
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
3935 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
3936 tp = clcf->thread_pool;
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
3937
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
3938 if (tp == NULL) {
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
3939 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
3940 != NGX_OK)
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
3941 {
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
3942 return NGX_ERROR;
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
3943 }
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
3944
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
3945 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
3946
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
3947 if (tp == NULL) {
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
3948 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
3949 "thread pool \"%V\" not found", &name);
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
3950 return NGX_ERROR;
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
3951 }
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
3952 }
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
3953
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
3954 task->event.data = r;
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
3955 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
3956
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
3957 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
3958 return NGX_ERROR;
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
3959 }
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
3960
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
3961 r->main->blocked++;
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
3962 r->aio = 1;
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
3963 p->aio = 1;
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
3964
9202
e88cdaa0f1ff AIO operations now add timers (ticket #2162).
Maxim Dounin <mdounin@mdounin.ru>
parents: 9021
diff changeset
3965 ngx_add_timer(&task->event, 60000);
e88cdaa0f1ff AIO operations now add timers (ticket #2162).
Maxim Dounin <mdounin@mdounin.ru>
parents: 9021
diff changeset
3966
6443
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
3967 return NGX_OK;
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
3968 }
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
3969
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
3970
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
3971 static void
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
3972 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
3973 {
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
3974 ngx_connection_t *c;
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
3975 ngx_http_request_t *r;
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
3976
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
3977 r = ev->data;
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
3978 c = r->connection;
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
3979
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
3980 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
3981
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
3982 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
3983 "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
3984
9202
e88cdaa0f1ff AIO operations now add timers (ticket #2162).
Maxim Dounin <mdounin@mdounin.ru>
parents: 9021
diff changeset
3985 if (ev->timedout) {
e88cdaa0f1ff AIO operations now add timers (ticket #2162).
Maxim Dounin <mdounin@mdounin.ru>
parents: 9021
diff changeset
3986 ngx_log_error(NGX_LOG_ALERT, c->log, 0,
e88cdaa0f1ff AIO operations now add timers (ticket #2162).
Maxim Dounin <mdounin@mdounin.ru>
parents: 9021
diff changeset
3987 "thread operation took too long");
e88cdaa0f1ff AIO operations now add timers (ticket #2162).
Maxim Dounin <mdounin@mdounin.ru>
parents: 9021
diff changeset
3988 ev->timedout = 0;
e88cdaa0f1ff AIO operations now add timers (ticket #2162).
Maxim Dounin <mdounin@mdounin.ru>
parents: 9021
diff changeset
3989 return;
e88cdaa0f1ff AIO operations now add timers (ticket #2162).
Maxim Dounin <mdounin@mdounin.ru>
parents: 9021
diff changeset
3990 }
e88cdaa0f1ff AIO operations now add timers (ticket #2162).
Maxim Dounin <mdounin@mdounin.ru>
parents: 9021
diff changeset
3991
e88cdaa0f1ff AIO operations now add timers (ticket #2162).
Maxim Dounin <mdounin@mdounin.ru>
parents: 9021
diff changeset
3992 if (ev->timer_set) {
e88cdaa0f1ff AIO operations now add timers (ticket #2162).
Maxim Dounin <mdounin@mdounin.ru>
parents: 9021
diff changeset
3993 ngx_del_timer(ev);
e88cdaa0f1ff AIO operations now add timers (ticket #2162).
Maxim Dounin <mdounin@mdounin.ru>
parents: 9021
diff changeset
3994 }
e88cdaa0f1ff AIO operations now add timers (ticket #2162).
Maxim Dounin <mdounin@mdounin.ru>
parents: 9021
diff changeset
3995
6443
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
3996 r->main->blocked--;
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
3997 r->aio = 0;
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
3998
7975
a7a77549265e HTTP/2: fixed sendfile() aio handling.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7974
diff changeset
3999 #if (NGX_HTTP_V2)
a7a77549265e HTTP/2: fixed sendfile() aio handling.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7974
diff changeset
4000
a7a77549265e HTTP/2: fixed sendfile() aio handling.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7974
diff changeset
4001 if (r->stream) {
a7a77549265e HTTP/2: fixed sendfile() aio handling.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7974
diff changeset
4002 /*
a7a77549265e HTTP/2: fixed sendfile() aio handling.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7974
diff changeset
4003 * for HTTP/2, update write event to make sure processing will
a7a77549265e HTTP/2: fixed sendfile() aio handling.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7974
diff changeset
4004 * reach the main connection to handle sendfile() in threads
a7a77549265e HTTP/2: fixed sendfile() aio handling.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7974
diff changeset
4005 */
a7a77549265e HTTP/2: fixed sendfile() aio handling.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7974
diff changeset
4006
a7a77549265e HTTP/2: fixed sendfile() aio handling.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7974
diff changeset
4007 c->write->ready = 1;
a7a77549265e HTTP/2: fixed sendfile() aio handling.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7974
diff changeset
4008 c->write->active = 0;
a7a77549265e HTTP/2: fixed sendfile() aio handling.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7974
diff changeset
4009 }
a7a77549265e HTTP/2: fixed sendfile() aio handling.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7974
diff changeset
4010
a7a77549265e HTTP/2: fixed sendfile() aio handling.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7974
diff changeset
4011 #endif
a7a77549265e HTTP/2: fixed sendfile() aio handling.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7974
diff changeset
4012
9203
0de20f43db25 Fixed request termination with AIO and subrequests (ticket #2555).
Maxim Dounin <mdounin@mdounin.ru>
parents: 9202
diff changeset
4013 if (r->done || r->main->terminated) {
6950
4cb4ffe06785 Threads: fixed request hang with aio_write and subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6923
diff changeset
4014 /*
4cb4ffe06785 Threads: fixed request hang with aio_write and subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6923
diff changeset
4015 * trigger connection event handler if the subrequest was
9203
0de20f43db25 Fixed request termination with AIO and subrequests (ticket #2555).
Maxim Dounin <mdounin@mdounin.ru>
parents: 9202
diff changeset
4016 * already finalized (this can happen if the handler is used
0de20f43db25 Fixed request termination with AIO and subrequests (ticket #2555).
Maxim Dounin <mdounin@mdounin.ru>
parents: 9202
diff changeset
4017 * for sendfile() in threads), or if the request was terminated
6950
4cb4ffe06785 Threads: fixed request hang with aio_write and subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6923
diff changeset
4018 */
4cb4ffe06785 Threads: fixed request hang with aio_write and subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6923
diff changeset
4019
4cb4ffe06785 Threads: fixed request hang with aio_write and subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6923
diff changeset
4020 c->write->handler(c->write);
4cb4ffe06785 Threads: fixed request hang with aio_write and subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6923
diff changeset
4021
4cb4ffe06785 Threads: fixed request hang with aio_write and subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6923
diff changeset
4022 } else {
4cb4ffe06785 Threads: fixed request hang with aio_write and subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6923
diff changeset
4023 r->write_event_handler(r);
4cb4ffe06785 Threads: fixed request hang with aio_write and subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6923
diff changeset
4024 ngx_http_run_posted_requests(c);
4cb4ffe06785 Threads: fixed request hang with aio_write and subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6923
diff changeset
4025 }
6443
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
4026 }
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
4027
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
4028 #endif
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
4029
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
4030
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
4031 static ngx_int_t
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
4032 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
4033 {
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
4034 ngx_int_t rc;
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
4035 ngx_event_pipe_t *p;
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
4036 ngx_http_request_t *r;
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
4037
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
4038 r = data;
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
4039 p = r->upstream->pipe;
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
4040
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
4041 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
4042
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
4043 p->aio = r->aio;
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
4044
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
4045 return rc;
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
4046 }
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
4047
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
4048
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
4049 static void
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
4050 ngx_http_upstream_process_downstream(ngx_http_request_t *r)
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
4051 {
2381
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
4052 ngx_event_t *wev;
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
4053 ngx_connection_t *c;
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
4054 ngx_event_pipe_t *p;
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4055 ngx_http_upstream_t *u;
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4056
2381
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
4057 c = r->connection;
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4058 u = r->upstream;
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
4059 p = u->pipe;
2381
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
4060 wev = c->write;
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
4061
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
4062 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
4063 "http upstream process downstream");
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
4064
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
4065 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
4066
6443
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
4067 #if (NGX_THREADS)
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
4068 p->aio = r->aio;
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
4069 #endif
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
4070
2381
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
4071 if (wev->timedout) {
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
4072
6961
903fb1ddc07f Moved handling of wev->delayed to the connection event handler.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6950
diff changeset
4073 p->downstream_error = 1;
903fb1ddc07f Moved handling of wev->delayed to the connection event handler.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6950
diff changeset
4074 c->timedout = 1;
903fb1ddc07f Moved handling of wev->delayed to the connection event handler.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6950
diff changeset
4075 ngx_connection_error(c, NGX_ETIMEDOUT, "client timed out");
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4076
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4077 } else {
2381
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
4078
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
4079 if (wev->delayed) {
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
4080
527
7fa11e5c6e96 nginx-0.1.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 525
diff changeset
4081 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
7fa11e5c6e96 nginx-0.1.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 525
diff changeset
4082 "http downstream delayed");
7fa11e5c6e96 nginx-0.1.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 525
diff changeset
4083
2381
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
4084 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
4085 ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
527
7fa11e5c6e96 nginx-0.1.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 525
diff changeset
4086 }
7fa11e5c6e96 nginx-0.1.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 525
diff changeset
4087
7fa11e5c6e96 nginx-0.1.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 525
diff changeset
4088 return;
7fa11e5c6e96 nginx-0.1.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 525
diff changeset
4089 }
7fa11e5c6e96 nginx-0.1.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 525
diff changeset
4090
2381
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
4091 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
4092 ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4093 return;
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4094 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4095 }
577
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
4096
5995
5f179f344096 Upstream: upstream argument in ngx_http_upstream_process_request().
Maxim Dounin <mdounin@mdounin.ru>
parents: 5994
diff changeset
4097 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
4098 }
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
4099
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
4100
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
4101 static void
2386
4ccaa42de633 use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents: 2381
diff changeset
4102 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
4103 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
4104 {
5883
973ee2276300 Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5878
diff changeset
4105 ngx_event_t *rev;
973ee2276300 Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5878
diff changeset
4106 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
4107 ngx_connection_t *c;
4ccaa42de633 use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents: 2381
diff changeset
4108
4ccaa42de633 use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents: 2381
diff changeset
4109 c = u->peer.connection;
5883
973ee2276300 Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5878
diff changeset
4110 p = u->pipe;
973ee2276300 Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5878
diff changeset
4111 rev = c->read;
2381
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
4112
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
4113 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
4114 "http upstream process upstream");
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
4115
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
4116 c->log->action = "reading upstream";
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
4117
5883
973ee2276300 Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5878
diff changeset
4118 if (rev->timedout) {
973ee2276300 Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5878
diff changeset
4119
6961
903fb1ddc07f Moved handling of wev->delayed to the connection event handler.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6950
diff changeset
4120 p->upstream_error = 1;
903fb1ddc07f Moved handling of wev->delayed to the connection event handler.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6950
diff changeset
4121 ngx_connection_error(c, NGX_ETIMEDOUT, "upstream timed out");
2381
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
4122
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
4123 } else {
5883
973ee2276300 Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5878
diff changeset
4124
973ee2276300 Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5878
diff changeset
4125 if (rev->delayed) {
973ee2276300 Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5878
diff changeset
4126
973ee2276300 Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5878
diff changeset
4127 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
4128 "http upstream delayed");
973ee2276300 Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5878
diff changeset
4129
973ee2276300 Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5878
diff changeset
4130 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
4131 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
4132 }
973ee2276300 Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5878
diff changeset
4133
973ee2276300 Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5878
diff changeset
4134 return;
973ee2276300 Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5878
diff changeset
4135 }
973ee2276300 Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5878
diff changeset
4136
973ee2276300 Upstream: proxy_limit_rate and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5878
diff changeset
4137 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
4138 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
4139 return;
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
4140 }
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
4141 }
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
4142
5995
5f179f344096 Upstream: upstream argument in ngx_http_upstream_process_request().
Maxim Dounin <mdounin@mdounin.ru>
parents: 5994
diff changeset
4143 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
4144 }
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
4145
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
4146
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
4147 static void
5995
5f179f344096 Upstream: upstream argument in ngx_http_upstream_process_request().
Maxim Dounin <mdounin@mdounin.ru>
parents: 5994
diff changeset
4148 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
4149 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
4150 {
5996
Maxim Dounin <mdounin@mdounin.ru>
parents: 5995
diff changeset
4151 ngx_temp_file_t *tf;
Maxim Dounin <mdounin@mdounin.ru>
parents: 5995
diff changeset
4152 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
4153
2381
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
4154 p = u->pipe;
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
4155
6443
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
4156 #if (NGX_THREADS)
6876
a5d1b1383dea Upstream: fixed cache corruption and socket leaks with aio_write.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6853
diff changeset
4157
a5d1b1383dea Upstream: fixed cache corruption and socket leaks with aio_write.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6853
diff changeset
4158 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
4159
a5d1b1383dea Upstream: fixed cache corruption and socket leaks with aio_write.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6853
diff changeset
4160 /*
a5d1b1383dea Upstream: fixed cache corruption and socket leaks with aio_write.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6853
diff changeset
4161 * 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
4162 * 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
4163 */
a5d1b1383dea Upstream: fixed cache corruption and socket leaks with aio_write.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6853
diff changeset
4164
a5d1b1383dea Upstream: fixed cache corruption and socket leaks with aio_write.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6853
diff changeset
4165 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
4166 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
4167 return;
a5d1b1383dea Upstream: fixed cache corruption and socket leaks with aio_write.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6853
diff changeset
4168 }
a5d1b1383dea Upstream: fixed cache corruption and socket leaks with aio_write.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6853
diff changeset
4169 }
a5d1b1383dea Upstream: fixed cache corruption and socket leaks with aio_write.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6853
diff changeset
4170
6443
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
4171 if (p->writing) {
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
4172 return;
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
4173 }
6876
a5d1b1383dea Upstream: fixed cache corruption and socket leaks with aio_write.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6853
diff changeset
4174
6443
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
4175 #endif
fc72784b1f52 Threads: writing via threads pools in event pipe.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6439
diff changeset
4176
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4177 if (u->peer.connection) {
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4178
1291
13a4ce6e7f1e proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents: 1284
diff changeset
4179 if (u->store) {
13a4ce6e7f1e proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents: 1284
diff changeset
4180
2463
4bc8ea10d62b fix fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents: 2445
diff changeset
4181 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
4182
5298
a7b2db9119e0 Upstream: replaced u->pipe->temp_file with p->temp_file.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5297
diff changeset
4183 tf = p->temp_file;
4469
24c0dca04eb9 Fix for proxy_store leaving temporary files for subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4464
diff changeset
4184
2445
3c6af1fb7586 proxy/fastcgi_store did not delete incomplete files
Igor Sysoev <igor@sysoev.ru>
parents: 2441
diff changeset
4185 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
4186 && (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
4187 && (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
4188 || 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
4189 {
3c6af1fb7586 proxy/fastcgi_store did not delete incomplete files
Igor Sysoev <igor@sysoev.ru>
parents: 2441
diff changeset
4190 ngx_http_upstream_store(r, u);
1291
13a4ce6e7f1e proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents: 1284
diff changeset
4191 }
13a4ce6e7f1e proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents: 1284
diff changeset
4192 }
13a4ce6e7f1e proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents: 1284
diff changeset
4193 }
13a4ce6e7f1e proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents: 1284
diff changeset
4194
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
4195 #if (NGX_HTTP_CACHE)
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
4196
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
4197 if (u->cacheable) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
4198
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
4199 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
4200 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
4201
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
4202 } else if (p->upstream_eof) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
4203
5298
a7b2db9119e0 Upstream: replaced u->pipe->temp_file with p->temp_file.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5297
diff changeset
4204 tf = p->temp_file;
4298
186f02886bed Upstream: don't cache unfinished responses.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4197
diff changeset
4205
5299
b779728b180c Upstream: fixed store/cache of unfinished responses.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5298
diff changeset
4206 if (p->length == -1
b779728b180c Upstream: fixed store/cache of unfinished responses.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5298
diff changeset
4207 && (u->headers_in.content_length_n == -1
b779728b180c Upstream: fixed store/cache of unfinished responses.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5298
diff changeset
4208 || u->headers_in.content_length_n
b779728b180c Upstream: fixed store/cache of unfinished responses.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5298
diff changeset
4209 == 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
4210 {
186f02886bed Upstream: don't cache unfinished responses.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4197
diff changeset
4211 ngx_http_file_cache_update(r, tf);
186f02886bed Upstream: don't cache unfinished responses.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4197
diff changeset
4212
186f02886bed Upstream: don't cache unfinished responses.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4197
diff changeset
4213 } else {
186f02886bed Upstream: don't cache unfinished responses.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4197
diff changeset
4214 ngx_http_file_cache_free(r->cache, tf);
186f02886bed Upstream: don't cache unfinished responses.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4197
diff changeset
4215 }
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
4216
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
4217 } 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
4218 ngx_http_file_cache_free(r->cache, p->temp_file);
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4219 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4220 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4221
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4222 #endif
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4223
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4224 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
4225 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
483
621229427cba nginx-0.1.16-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 481
diff changeset
4226 "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
4227
a50e26148d21 Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5300
diff changeset
4228 if (p->upstream_done
a50e26148d21 Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5300
diff changeset
4229 || (p->upstream_eof && p->length == -1))
a50e26148d21 Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5300
diff changeset
4230 {
a50e26148d21 Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5300
diff changeset
4231 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
4232 return;
a50e26148d21 Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5300
diff changeset
4233 }
a50e26148d21 Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5300
diff changeset
4234
a50e26148d21 Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5300
diff changeset
4235 if (p->upstream_eof) {
a50e26148d21 Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5300
diff changeset
4236 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
4237 "upstream prematurely closed connection");
a50e26148d21 Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5300
diff changeset
4238 }
a50e26148d21 Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5300
diff changeset
4239
a50e26148d21 Upstream: added check if a response is complete.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5300
diff changeset
4240 ngx_http_upstream_finalize_request(r, u, NGX_HTTP_BAD_GATEWAY);
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4241 return;
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4242 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4243 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4244
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4245 if (p->downstream_error) {
2381
3d7a70173d77 fix r2378, run posted requests after upstream event handling
Igor Sysoev <igor@sysoev.ru>
parents: 2377
diff changeset
4246 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
483
621229427cba nginx-0.1.16-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 481
diff changeset
4247 "http upstream downstream error");
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4248
2757
9cc973b46af1 get a full response if the response is cacheable or storable even
Igor Sysoev <igor@sysoev.ru>
parents: 2708
diff changeset
4249 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
4250 ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4251 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4252 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4253 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4254
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4255
487
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 485
diff changeset
4256 static void
1291
13a4ce6e7f1e proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents: 1284
diff changeset
4257 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
4258 {
1947
94b03bbd328e use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents: 1916
diff changeset
4259 size_t root;
94b03bbd328e use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents: 1916
diff changeset
4260 time_t lm;
94b03bbd328e use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents: 1916
diff changeset
4261 ngx_str_t path;
94b03bbd328e use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents: 1916
diff changeset
4262 ngx_temp_file_t *tf;
94b03bbd328e use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents: 1916
diff changeset
4263 ngx_ext_rename_file_t ext;
1291
13a4ce6e7f1e proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents: 1284
diff changeset
4264
1777
edaea30d83be optimization
Igor Sysoev <igor@sysoev.ru>
parents: 1707
diff changeset
4265 tf = u->pipe->temp_file;
edaea30d83be optimization
Igor Sysoev <igor@sysoev.ru>
parents: 1707
diff changeset
4266
edaea30d83be optimization
Igor Sysoev <igor@sysoev.ru>
parents: 1707
diff changeset
4267 if (tf->file.fd == NGX_INVALID_FILE) {
1291
13a4ce6e7f1e proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents: 1284
diff changeset
4268
13a4ce6e7f1e proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents: 1284
diff changeset
4269 /* create file for empty 200 response */
13a4ce6e7f1e proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents: 1284
diff changeset
4270
13a4ce6e7f1e proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents: 1284
diff changeset
4271 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
4272 if (tf == NULL) {
13a4ce6e7f1e proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents: 1284
diff changeset
4273 return;
13a4ce6e7f1e proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents: 1284
diff changeset
4274 }
13a4ce6e7f1e proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents: 1284
diff changeset
4275
13a4ce6e7f1e proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents: 1284
diff changeset
4276 tf->file.fd = NGX_INVALID_FILE;
13a4ce6e7f1e proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents: 1284
diff changeset
4277 tf->file.log = r->connection->log;
13a4ce6e7f1e proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents: 1284
diff changeset
4278 tf->path = u->conf->temp_path;
13a4ce6e7f1e proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents: 1284
diff changeset
4279 tf->pool = r->pool;
13a4ce6e7f1e proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents: 1284
diff changeset
4280 tf->persistent = 1;
13a4ce6e7f1e proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents: 1284
diff changeset
4281
13a4ce6e7f1e proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents: 1284
diff changeset
4282 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
4283 tf->persistent, tf->clean, tf->access)
13a4ce6e7f1e proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents: 1284
diff changeset
4284 != NGX_OK)
13a4ce6e7f1e proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents: 1284
diff changeset
4285 {
13a4ce6e7f1e proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents: 1284
diff changeset
4286 return;
13a4ce6e7f1e proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents: 1284
diff changeset
4287 }
13a4ce6e7f1e proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents: 1284
diff changeset
4288
13a4ce6e7f1e proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents: 1284
diff changeset
4289 u->pipe->temp_file = tf;
13a4ce6e7f1e proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents: 1284
diff changeset
4290 }
13a4ce6e7f1e proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents: 1284
diff changeset
4291
1947
94b03bbd328e use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents: 1916
diff changeset
4292 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
4293 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
4294 ext.time = -1;
94b03bbd328e use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents: 1916
diff changeset
4295 ext.create_path = 1;
94b03bbd328e use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents: 1916
diff changeset
4296 ext.delete_file = 1;
94b03bbd328e use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents: 1916
diff changeset
4297 ext.log = r->connection->log;
1291
13a4ce6e7f1e proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents: 1284
diff changeset
4298
1705
d22095839d86 optimize r->upstream usage
Igor Sysoev <igor@sysoev.ru>
parents: 1701
diff changeset
4299 if (u->headers_in.last_modified) {
d22095839d86 optimize r->upstream usage
Igor Sysoev <igor@sysoev.ru>
parents: 1701
diff changeset
4300
6180
8b6fa4842133 Moved ngx_http_parse_time() to core, renamed accordingly.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6147
diff changeset
4301 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
4302 u->headers_in.last_modified->value.len);
1291
13a4ce6e7f1e proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents: 1284
diff changeset
4303
13a4ce6e7f1e proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents: 1284
diff changeset
4304 if (lm != NGX_ERROR) {
1947
94b03bbd328e use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents: 1916
diff changeset
4305 ext.time = lm;
94b03bbd328e use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents: 1916
diff changeset
4306 ext.fd = tf->file.fd;
1291
13a4ce6e7f1e proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents: 1284
diff changeset
4307 }
13a4ce6e7f1e proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents: 1284
diff changeset
4308 }
13a4ce6e7f1e proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents: 1284
diff changeset
4309
1295
5383f5232364 proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents: 1291
diff changeset
4310 if (u->conf->store_lengths == NULL) {
5383f5232364 proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents: 1291
diff changeset
4311
5770
9de5820bb3e0 Upstream: ngx_http_upstream_store() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5757
diff changeset
4312 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
4313 return;
9de5820bb3e0 Upstream: ngx_http_upstream_store() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5757
diff changeset
4314 }
1295
5383f5232364 proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents: 1291
diff changeset
4315
5383f5232364 proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents: 1291
diff changeset
4316 } else {
5383f5232364 proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents: 1291
diff changeset
4317 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
4318 u->conf->store_values->elts)
5383f5232364 proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents: 1291
diff changeset
4319 == NULL)
5383f5232364 proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents: 1291
diff changeset
4320 {
5383f5232364 proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents: 1291
diff changeset
4321 return;
5383f5232364 proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents: 1291
diff changeset
4322 }
5383f5232364 proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents: 1291
diff changeset
4323 }
1291
13a4ce6e7f1e proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents: 1284
diff changeset
4324
3032
524ba56ba9f7 fix copy destination name length, introduced in r3025
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
4325 path.len--;
524ba56ba9f7 fix copy destination name length, introduced in r3025
Igor Sysoev <igor@sysoev.ru>
parents: 3024
diff changeset
4326
1291
13a4ce6e7f1e proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents: 1284
diff changeset
4327 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
4328 "upstream stores \"%s\" to \"%s\"",
94b03bbd328e use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents: 1916
diff changeset
4329 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
4330
94b03bbd328e use ngx_ext_rename_file() in proxy/fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents: 1916
diff changeset
4331 (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
4332
9de5820bb3e0 Upstream: ngx_http_upstream_store() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5757
diff changeset
4333 u->store = 0;
1291
13a4ce6e7f1e proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents: 1284
diff changeset
4334 }
13a4ce6e7f1e proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents: 1284
diff changeset
4335
13a4ce6e7f1e proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents: 1284
diff changeset
4336
13a4ce6e7f1e proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents: 1284
diff changeset
4337 static void
2386
4ccaa42de633 use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents: 2381
diff changeset
4338 ngx_http_upstream_dummy_handler(ngx_http_request_t *r, ngx_http_upstream_t *u)
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4339 {
2386
4ccaa42de633 use already available r and u instead of ev
Igor Sysoev <igor@sysoev.ru>
parents: 2381
diff changeset
4340 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4341 "http upstream dummy handler");
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4342 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4343
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4344
487
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 485
diff changeset
4345 static void
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 485
diff changeset
4346 ngx_http_upstream_next(ngx_http_request_t *r, ngx_http_upstream_t *u,
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 485
diff changeset
4347 ngx_uint_t ft_type)
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4348 {
5832
d09b689911ac Upstream: limited next_upstream time and tries (ticket #544).
Roman Arutyunyan <arut@nginx.com>
parents: 5827
diff changeset
4349 ngx_msec_t timeout;
884
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
4350 ngx_uint_t status, state;
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4351
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4352 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
884
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
4353 "http next upstream, %xi", ft_type);
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4354
5132
9bcf89ca78d2 Upstream: only call peer.free() if peer.get() selected a peer.
Ruslan Ermilov <ru@nginx.com>
parents: 5121
diff changeset
4355 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
4356
7429
e573d74299a0 Upstream: implemented $upstream_bytes_sent.
Ruslan Ermilov <ru@nginx.com>
parents: 7397
diff changeset
4357 if (u->peer.connection) {
e573d74299a0 Upstream: implemented $upstream_bytes_sent.
Ruslan Ermilov <ru@nginx.com>
parents: 7397
diff changeset
4358 u->state->bytes_sent = u->peer.connection->sent;
e573d74299a0 Upstream: implemented $upstream_bytes_sent.
Ruslan Ermilov <ru@nginx.com>
parents: 7397
diff changeset
4359 }
e573d74299a0 Upstream: implemented $upstream_bytes_sent.
Ruslan Ermilov <ru@nginx.com>
parents: 7397
diff changeset
4360
5231
05c53652e7b4 Upstream: http_403 support in proxy_next_upstream (and friends).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5217
diff changeset
4361 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
4362 || 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
4363 {
5132
9bcf89ca78d2 Upstream: only call peer.free() if peer.get() selected a peer.
Ruslan Ermilov <ru@nginx.com>
parents: 5121
diff changeset
4364 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
4365
5132
9bcf89ca78d2 Upstream: only call peer.free() if peer.get() selected a peer.
Ruslan Ermilov <ru@nginx.com>
parents: 5121
diff changeset
4366 } else {
9bcf89ca78d2 Upstream: only call peer.free() if peer.get() selected a peer.
Ruslan Ermilov <ru@nginx.com>
parents: 5121
diff changeset
4367 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
4368 }
9bcf89ca78d2 Upstream: only call peer.free() if peer.get() selected a peer.
Ruslan Ermilov <ru@nginx.com>
parents: 5121
diff changeset
4369
1378
0be898896d1a backup upstream servers
Igor Sysoev <igor@sysoev.ru>
parents: 1340
diff changeset
4370 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
4371 u->peer.sockaddr = NULL;
1378
0be898896d1a backup upstream servers
Igor Sysoev <igor@sysoev.ru>
parents: 1340
diff changeset
4372 }
525
09b42134ac0c nginx-0.1.37-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 515
diff changeset
4373
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4374 if (ft_type == NGX_HTTP_UPSTREAM_FT_TIMEOUT) {
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4375 ngx_log_error(NGX_LOG_ERR, r->connection->log, NGX_ETIMEDOUT,
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4376 "upstream timed out");
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4377 }
577
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
4378
6466
984687f25998 Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6443
diff changeset
4379 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
4380 /* TODO: inform balancer instead */
70a45a504905 Workaround for cpu hog on errors with cached connections.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4114
diff changeset
4381 u->peer.tries++;
6466
984687f25998 Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6443
diff changeset
4382 }
984687f25998 Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6443
diff changeset
4383
984687f25998 Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6443
diff changeset
4384 switch (ft_type) {
984687f25998 Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6443
diff changeset
4385
984687f25998 Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6443
diff changeset
4386 case NGX_HTTP_UPSTREAM_FT_TIMEOUT:
7130
882ad033d43c Upstream: fixed $upstream_status when upstream returns 503/504.
Ruslan Ermilov <ru@nginx.com>
parents: 7126
diff changeset
4387 case NGX_HTTP_UPSTREAM_FT_HTTP_504:
6466
984687f25998 Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6443
diff changeset
4388 status = NGX_HTTP_GATEWAY_TIME_OUT;
984687f25998 Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6443
diff changeset
4389 break;
984687f25998 Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6443
diff changeset
4390
984687f25998 Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6443
diff changeset
4391 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
4392 status = NGX_HTTP_INTERNAL_SERVER_ERROR;
984687f25998 Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6443
diff changeset
4393 break;
984687f25998 Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6443
diff changeset
4394
7130
882ad033d43c Upstream: fixed $upstream_status when upstream returns 503/504.
Ruslan Ermilov <ru@nginx.com>
parents: 7126
diff changeset
4395 case NGX_HTTP_UPSTREAM_FT_HTTP_503:
882ad033d43c Upstream: fixed $upstream_status when upstream returns 503/504.
Ruslan Ermilov <ru@nginx.com>
parents: 7126
diff changeset
4396 status = NGX_HTTP_SERVICE_UNAVAILABLE;
882ad033d43c Upstream: fixed $upstream_status when upstream returns 503/504.
Ruslan Ermilov <ru@nginx.com>
parents: 7126
diff changeset
4397 break;
882ad033d43c Upstream: fixed $upstream_status when upstream returns 503/504.
Ruslan Ermilov <ru@nginx.com>
parents: 7126
diff changeset
4398
6466
984687f25998 Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6443
diff changeset
4399 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
4400 status = NGX_HTTP_FORBIDDEN;
984687f25998 Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6443
diff changeset
4401 break;
984687f25998 Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6443
diff changeset
4402
984687f25998 Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6443
diff changeset
4403 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
4404 status = NGX_HTTP_NOT_FOUND;
984687f25998 Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6443
diff changeset
4405 break;
984687f25998 Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6443
diff changeset
4406
6966
fa56ab75cffc Upstream: allow recovery from "429 Too Many Requests" response.
Piotr Sikora <piotrsikora@google.com>
parents: 6961
diff changeset
4407 case NGX_HTTP_UPSTREAM_FT_HTTP_429:
fa56ab75cffc Upstream: allow recovery from "429 Too Many Requests" response.
Piotr Sikora <piotrsikora@google.com>
parents: 6961
diff changeset
4408 status = NGX_HTTP_TOO_MANY_REQUESTS;
fa56ab75cffc Upstream: allow recovery from "429 Too Many Requests" response.
Piotr Sikora <piotrsikora@google.com>
parents: 6961
diff changeset
4409 break;
fa56ab75cffc Upstream: allow recovery from "429 Too Many Requests" response.
Piotr Sikora <piotrsikora@google.com>
parents: 6961
diff changeset
4410
6466
984687f25998 Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6443
diff changeset
4411 /*
984687f25998 Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6443
diff changeset
4412 * 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
4413 * never reach here
984687f25998 Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6443
diff changeset
4414 */
984687f25998 Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6443
diff changeset
4415
984687f25998 Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6443
diff changeset
4416 default:
984687f25998 Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6443
diff changeset
4417 status = NGX_HTTP_BAD_GATEWAY;
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4418 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4419
583
4e296b7d25bf nginx-0.3.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 581
diff changeset
4420 if (r->connection->error) {
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4421 ngx_http_upstream_finalize_request(r, u,
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4422 NGX_HTTP_CLIENT_CLOSED_REQUEST);
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4423 return;
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4424 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4425
6466
984687f25998 Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6443
diff changeset
4426 u->state->status = status;
984687f25998 Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6443
diff changeset
4427
984687f25998 Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6443
diff changeset
4428 timeout = u->conf->next_upstream_timeout;
984687f25998 Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6443
diff changeset
4429
6467
91c8d990fb45 Upstream: proxy_next_upstream non_idempotent.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6466
diff changeset
4430 if (u->request_sent
91c8d990fb45 Upstream: proxy_next_upstream non_idempotent.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6466
diff changeset
4431 && (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
4432 {
91c8d990fb45 Upstream: proxy_next_upstream non_idempotent.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6466
diff changeset
4433 ft_type |= NGX_HTTP_UPSTREAM_FT_NON_IDEMPOTENT;
91c8d990fb45 Upstream: proxy_next_upstream non_idempotent.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6466
diff changeset
4434 }
91c8d990fb45 Upstream: proxy_next_upstream non_idempotent.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6466
diff changeset
4435
6466
984687f25998 Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6443
diff changeset
4436 if (u->peer.tries == 0
6467
91c8d990fb45 Upstream: proxy_next_upstream non_idempotent.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6466
diff changeset
4437 || ((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
4438 || (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
4439 || (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
4440 {
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4441 #if (NGX_HTTP_CACHE)
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4442
6466
984687f25998 Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6443
diff changeset
4443 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
4444 && ((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
4445 {
984687f25998 Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6443
diff changeset
4446 ngx_int_t rc;
984687f25998 Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6443
diff changeset
4447
984687f25998 Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6443
diff changeset
4448 rc = u->reinit_request(r);
984687f25998 Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6443
diff changeset
4449
7126
77fe752b4586 Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents: 7125
diff changeset
4450 if (rc != NGX_OK) {
77fe752b4586 Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents: 7125
diff changeset
4451 ngx_http_upstream_finalize_request(r, u, rc);
77fe752b4586 Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents: 7125
diff changeset
4452 return;
77fe752b4586 Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents: 7125
diff changeset
4453 }
77fe752b4586 Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents: 7125
diff changeset
4454
77fe752b4586 Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents: 7125
diff changeset
4455 u->cache_status = NGX_HTTP_CACHE_STALE;
77fe752b4586 Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents: 7125
diff changeset
4456 rc = ngx_http_upstream_cache_send(r, u);
77fe752b4586 Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents: 7125
diff changeset
4457
77fe752b4586 Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents: 7125
diff changeset
4458 if (rc == NGX_DONE) {
77fe752b4586 Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents: 7125
diff changeset
4459 return;
77fe752b4586 Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents: 7125
diff changeset
4460 }
77fe752b4586 Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents: 7125
diff changeset
4461
77fe752b4586 Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents: 7125
diff changeset
4462 if (rc == NGX_HTTP_UPSTREAM_INVALID_HEADER) {
77fe752b4586 Upstream: fixed error handling of stale and revalidated cache send.
Sergey Kandaurov <pluknet@nginx.com>
parents: 7125
diff changeset
4463 rc = NGX_HTTP_INTERNAL_SERVER_ERROR;
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4464 }
6466
984687f25998 Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6443
diff changeset
4465
984687f25998 Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6443
diff changeset
4466 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
4467 return;
984687f25998 Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6443
diff changeset
4468 }
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4469 #endif
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4470
6466
984687f25998 Upstream: cached connections now tested against next_upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6443
diff changeset
4471 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
4472 return;
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4473 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4474
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4475 if (u->peer.connection) {
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4476 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4477 "close http upstream connection: %d",
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4478 u->peer.connection->fd);
577
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
4479 #if (NGX_HTTP_SSL)
884
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
4480
577
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
4481 if (u->peer.connection->ssl) {
884
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
4482 u->peer.connection->ssl->no_wait_shutdown = 1;
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
4483 u->peer.connection->ssl->no_send_shutdown = 1;
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
4484
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
4485 (void) ngx_ssl_shutdown(u->peer.connection);
577
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
4486 }
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
4487 #endif
884
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
4488
4138
70e1ee2307f9 Fix of separate pool for upstream connections (r4117).
Maxim Dounin <mdounin@mdounin.ru>
parents: 4124
diff changeset
4489 if (u->peer.connection->pool) {
70e1ee2307f9 Fix of separate pool for upstream connections (r4117).
Maxim Dounin <mdounin@mdounin.ru>
parents: 4124
diff changeset
4490 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
4491 }
70e1ee2307f9 Fix of separate pool for upstream connections (r4117).
Maxim Dounin <mdounin@mdounin.ru>
parents: 4124
diff changeset
4492
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4493 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
4494 u->peer.connection = NULL;
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4495 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4496
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4497 ngx_http_upstream_connect(r, u);
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4498 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4499
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4500
487
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 485
diff changeset
4501 static void
569
174f1e853e1e nginx-0.3.6-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 563
diff changeset
4502 ngx_http_upstream_cleanup(void *data)
174f1e853e1e nginx-0.3.6-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 563
diff changeset
4503 {
174f1e853e1e nginx-0.3.6-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 563
diff changeset
4504 ngx_http_request_t *r = data;
174f1e853e1e nginx-0.3.6-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 563
diff changeset
4505
174f1e853e1e nginx-0.3.6-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 563
diff changeset
4506 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
174f1e853e1e nginx-0.3.6-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 563
diff changeset
4507 "cleanup http upstream request: \"%V\"", &r->uri);
174f1e853e1e nginx-0.3.6-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 563
diff changeset
4508
5167
85ee9d858dcb Upstream: removed surplus ngx_resolve_name_done() call.
Valentin Bartenev <vbart@nginx.com>
parents: 5142
diff changeset
4509 ngx_http_upstream_finalize_request(r, r->upstream, NGX_DONE);
569
174f1e853e1e nginx-0.3.6-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 563
diff changeset
4510 }
174f1e853e1e nginx-0.3.6-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 563
diff changeset
4511
174f1e853e1e nginx-0.3.6-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 563
diff changeset
4512
174f1e853e1e nginx-0.3.6-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 563
diff changeset
4513 static void
487
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 485
diff changeset
4514 ngx_http_upstream_finalize_request(ngx_http_request_t *r,
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 485
diff changeset
4515 ngx_http_upstream_t *u, ngx_int_t rc)
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4516 {
6146
59fc60585f1e Upstream: times to obtain header/response are stored as ngx_msec_t.
Ruslan Ermilov <ru@nginx.com>
parents: 6125
diff changeset
4517 ngx_uint_t flush;
563
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
4518
483
621229427cba nginx-0.1.16-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 481
diff changeset
4519 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
621229427cba nginx-0.1.16-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 481
diff changeset
4520 "finalize http upstream request: %i", rc);
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4521
5994
5abf5af257a7 Upstream: avoid duplicate finalization.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5992
diff changeset
4522 if (u->cleanup == NULL) {
5abf5af257a7 Upstream: avoid duplicate finalization.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5992
diff changeset
4523 /* the request was already finalized */
5abf5af257a7 Upstream: avoid duplicate finalization.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5992
diff changeset
4524 ngx_http_finalize_request(r, NGX_DONE);
5abf5af257a7 Upstream: avoid duplicate finalization.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5992
diff changeset
4525 return;
5abf5af257a7 Upstream: avoid duplicate finalization.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5992
diff changeset
4526 }
5abf5af257a7 Upstream: avoid duplicate finalization.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5992
diff changeset
4527
5abf5af257a7 Upstream: avoid duplicate finalization.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5992
diff changeset
4528 *u->cleanup = NULL;
5abf5af257a7 Upstream: avoid duplicate finalization.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5992
diff changeset
4529 u->cleanup = NULL;
569
174f1e853e1e nginx-0.3.6-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 563
diff changeset
4530
3169
b1013d768911 fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents: 3161
diff changeset
4531 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
4532 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
4533 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
4534 }
b1013d768911 fix request counter in resolver handling, the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents: 3161
diff changeset
4535
7397
860d3907da1c Upstream: revised upstream response time variables.
Vladimir Homutov <vl@nginx.com>
parents: 7371
diff changeset
4536 if (u->state && u->state->response_time == (ngx_msec_t) -1) {
860d3907da1c Upstream: revised upstream response time variables.
Vladimir Homutov <vl@nginx.com>
parents: 7371
diff changeset
4537 u->state->response_time = ngx_current_msec - u->start_time;
2402
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
4538
5169
f6bbe77794aa Upstream: fixed $upstream_response_length without buffering.
Sergey Kandaurov <pluknet@nginx.com>
parents: 5167
diff changeset
4539 if (u->pipe && u->pipe->read_length) {
6654
c131f20c9562 Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents: 6594
diff changeset
4540 u->state->bytes_received += u->pipe->read_length
c131f20c9562 Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents: 6594
diff changeset
4541 - u->pipe->preread_size;
2402
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
4542 u->state->response_length = u->pipe->read_length;
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
4543 }
7429
e573d74299a0 Upstream: implemented $upstream_bytes_sent.
Ruslan Ermilov <ru@nginx.com>
parents: 7397
diff changeset
4544
e573d74299a0 Upstream: implemented $upstream_bytes_sent.
Ruslan Ermilov <ru@nginx.com>
parents: 7397
diff changeset
4545 if (u->peer.connection) {
e573d74299a0 Upstream: implemented $upstream_bytes_sent.
Ruslan Ermilov <ru@nginx.com>
parents: 7397
diff changeset
4546 u->state->bytes_sent = u->peer.connection->sent;
e573d74299a0 Upstream: implemented $upstream_bytes_sent.
Ruslan Ermilov <ru@nginx.com>
parents: 7397
diff changeset
4547 }
563
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
4548 }
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
4549
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4550 u->finalize_request(r, rc);
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4551
5132
9bcf89ca78d2 Upstream: only call peer.free() if peer.get() selected a peer.
Ruslan Ermilov <ru@nginx.com>
parents: 5121
diff changeset
4552 if (u->peer.free && u->peer.sockaddr) {
1658
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
4553 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
4554 u->peer.sockaddr = NULL;
1658
13f8dec720b5 proxy_pass variables support
Igor Sysoev <igor@sysoev.ru>
parents: 1654
diff changeset
4555 }
884
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
4556
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4557 if (u->peer.connection) {
884
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
4558
577
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
4559 #if (NGX_HTTP_SSL)
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
4560
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
4561 /* TODO: do not shutdown persistent connection */
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
4562
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
4563 if (u->peer.connection->ssl) {
884
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
4564
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
4565 /*
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
4566 * We send the "close notify" shutdown alert to the upstream only
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
4567 * and do not wait its "close notify" shutdown alert.
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
4568 * It is acceptable according to the TLS standard.
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
4569 */
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
4570
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
4571 u->peer.connection->ssl->no_wait_shutdown = 1;
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
4572
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
4573 (void) ngx_ssl_shutdown(u->peer.connection);
577
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
4574 }
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
4575 #endif
884
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
4576
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
4577 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
4578 "close http upstream connection: %d",
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
4579 u->peer.connection->fd);
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
4580
4138
70e1ee2307f9 Fix of separate pool for upstream connections (r4117).
Maxim Dounin <mdounin@mdounin.ru>
parents: 4124
diff changeset
4581 if (u->peer.connection->pool) {
70e1ee2307f9 Fix of separate pool for upstream connections (r4117).
Maxim Dounin <mdounin@mdounin.ru>
parents: 4124
diff changeset
4582 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
4583 }
70e1ee2307f9 Fix of separate pool for upstream connections (r4117).
Maxim Dounin <mdounin@mdounin.ru>
parents: 4124
diff changeset
4584
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4585 ngx_close_connection(u->peer.connection);
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4586 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4587
483
621229427cba nginx-0.1.16-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 481
diff changeset
4588 u->peer.connection = NULL;
621229427cba nginx-0.1.16-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 481
diff changeset
4589
9204
631ee3c6d38c Upstream: fixed usage of closed sockets with filter finalization.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9203
diff changeset
4590 if (u->pipe) {
631ee3c6d38c Upstream: fixed usage of closed sockets with filter finalization.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9203
diff changeset
4591 u->pipe->upstream = NULL;
631ee3c6d38c Upstream: fixed usage of closed sockets with filter finalization.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9203
diff changeset
4592 }
631ee3c6d38c Upstream: fixed usage of closed sockets with filter finalization.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9203
diff changeset
4593
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
4594 if (u->pipe && u->pipe->temp_file) {
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4595 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4596 "http upstream temp fd: %d",
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
4597 u->pipe->temp_file->file.fd);
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4598 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4599
4469
24c0dca04eb9 Fix for proxy_store leaving temporary files for subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4464
diff changeset
4600 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
4601 && 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
4602 {
24c0dca04eb9 Fix for proxy_store leaving temporary files for subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4464
diff changeset
4603 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
4604 == NGX_FILE_ERROR)
24c0dca04eb9 Fix for proxy_store leaving temporary files for subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4464
diff changeset
4605 {
24c0dca04eb9 Fix for proxy_store leaving temporary files for subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4464
diff changeset
4606 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
4607 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
4608 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
4609 }
24c0dca04eb9 Fix for proxy_store leaving temporary files for subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4464
diff changeset
4610 }
24c0dca04eb9 Fix for proxy_store leaving temporary files for subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4464
diff changeset
4611
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
4612 #if (NGX_HTTP_CACHE)
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
4613
3940
22f3e9197096 revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents: 3934
diff changeset
4614 if (r->cache) {
22f3e9197096 revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents: 3934
diff changeset
4615
22f3e9197096 revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents: 3934
diff changeset
4616 if (u->cacheable) {
22f3e9197096 revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents: 3934
diff changeset
4617
22f3e9197096 revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents: 3934
diff changeset
4618 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
4619 time_t valid;
22f3e9197096 revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents: 3934
diff changeset
4620
22f3e9197096 revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents: 3934
diff changeset
4621 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
4622
22f3e9197096 revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents: 3934
diff changeset
4623 if (valid) {
22f3e9197096 revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents: 3934
diff changeset
4624 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
4625 r->cache->error = rc;
22f3e9197096 revert r3935 and fix "stalled cache updating" alert
Igor Sysoev <igor@sysoev.ru>
parents: 3934
diff changeset
4626 }
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
4627 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
4628 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
4629
3711
ce6ba077c270 several changes in cache cleanup handling:
Igor Sysoev <igor@sysoev.ru>
parents: 3709
diff changeset
4630 ngx_http_file_cache_free(r->cache, u->pipe->temp_file);
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4631 }
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
4632
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4633 #endif
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4634
6909
5850fed24639 Upstream: read handler cleared on upstream finalization.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6906
diff changeset
4635 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
4636
515
417a087c9c4d nginx-0.1.32-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 511
diff changeset
4637 if (rc == NGX_DECLINED) {
417a087c9c4d nginx-0.1.32-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 511
diff changeset
4638 return;
417a087c9c4d nginx-0.1.32-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 511
diff changeset
4639 }
417a087c9c4d nginx-0.1.32-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 511
diff changeset
4640
483
621229427cba nginx-0.1.16-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 481
diff changeset
4641 r->connection->log->action = "sending to client";
621229427cba nginx-0.1.16-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 481
diff changeset
4642
5303
0fb714d80909 Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5302
diff changeset
4643 if (!u->header_sent
0fb714d80909 Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5302
diff changeset
4644 || rc == NGX_HTTP_REQUEST_TIME_OUT
7188
93abb5a855d6 Upstream: fixed "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7174
diff changeset
4645 || rc == NGX_HTTP_CLIENT_CLOSED_REQUEST)
4151
3549db8ceaf2 Cache: fix for sending of stale responses.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4143
diff changeset
4646 {
5303
0fb714d80909 Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5302
diff changeset
4647 ngx_http_finalize_request(r, rc);
0fb714d80909 Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5302
diff changeset
4648 return;
0fb714d80909 Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5302
diff changeset
4649 }
0fb714d80909 Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5302
diff changeset
4650
5304
d3eab5e2df5f Upstream: no last buffer on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5303
diff changeset
4651 flush = 0;
d3eab5e2df5f Upstream: no last buffer on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5303
diff changeset
4652
d3eab5e2df5f Upstream: no last buffer on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5303
diff changeset
4653 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) {
d3eab5e2df5f Upstream: no last buffer on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5303
diff changeset
4654 rc = NGX_ERROR;
d3eab5e2df5f Upstream: no last buffer on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5303
diff changeset
4655 flush = 1;
5303
0fb714d80909 Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5302
diff changeset
4656 }
0fb714d80909 Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5302
diff changeset
4657
7188
93abb5a855d6 Upstream: fixed "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7174
diff changeset
4658 if (r->header_only
93abb5a855d6 Upstream: fixed "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7174
diff changeset
4659 || (u->pipe && u->pipe->downstream_error))
93abb5a855d6 Upstream: fixed "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7174
diff changeset
4660 {
5303
0fb714d80909 Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5302
diff changeset
4661 ngx_http_finalize_request(r, rc);
0fb714d80909 Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5302
diff changeset
4662 return;
0fb714d80909 Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5302
diff changeset
4663 }
0fb714d80909 Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5302
diff changeset
4664
0fb714d80909 Upstream: request finalization rework.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5302
diff changeset
4665 if (rc == 0) {
7230
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
4666
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
4667 if (ngx_http_upstream_process_trailers(r, u) != NGX_OK) {
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
4668 ngx_http_finalize_request(r, NGX_ERROR);
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
4669 return;
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
4670 }
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
4671
2377
87b8c44906b5 *) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents: 2360
diff changeset
4672 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
4673
d3eab5e2df5f Upstream: no last buffer on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5303
diff changeset
4674 } else if (flush) {
d3eab5e2df5f Upstream: no last buffer on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5303
diff changeset
4675 r->keepalive = 0;
d3eab5e2df5f Upstream: no last buffer on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5303
diff changeset
4676 rc = ngx_http_send_special(r, NGX_HTTP_FLUSH);
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4677 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4678
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4679 ngx_http_finalize_request(r, rc);
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4680 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4681
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4682
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
4683 static ngx_int_t
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
4684 ngx_http_upstream_process_header_line(ngx_http_request_t *r, ngx_table_elt_t *h,
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
4685 ngx_uint_t offset)
577
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
4686 {
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
4687 ngx_table_elt_t **ph;
577
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
4688
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
4689 ph = (ngx_table_elt_t **) ((char *) &r->upstream->headers_in + offset);
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
4690
8034
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
4691 if (*ph) {
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
4692 ngx_log_error(NGX_LOG_WARN, r->connection->log, 0,
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
4693 "upstream sent duplicate header line: \"%V: %V\", "
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
4694 "previous value: \"%V: %V\", ignored",
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
4695 &h->key, &h->value,
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
4696 &(*ph)->key, &(*ph)->value);
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
4697 h->hash = 0;
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
4698 return NGX_OK;
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
4699 }
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
4700
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
4701 *ph = h;
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
4702 h->next = NULL;
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
4703
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
4704 return NGX_OK;
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
4705 }
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
4706
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
4707
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
4708 static ngx_int_t
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
4709 ngx_http_upstream_process_multi_header_lines(ngx_http_request_t *r,
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
4710 ngx_table_elt_t *h, ngx_uint_t offset)
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
4711 {
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
4712 ngx_table_elt_t **ph;
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
4713
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
4714 ph = (ngx_table_elt_t **) ((char *) &r->upstream->headers_in + offset);
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
4715
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
4716 while (*ph) { ph = &(*ph)->next; }
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
4717
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
4718 *ph = h;
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
4719 h->next = NULL;
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
4720
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
4721 return NGX_OK;
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
4722 }
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
4723
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
4724
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
4725 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
4726 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
4727 ngx_uint_t offset)
5e4d8bd4486c support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2667
diff changeset
4728 {
5e4d8bd4486c support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2667
diff changeset
4729 return NGX_OK;
5e4d8bd4486c support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2667
diff changeset
4730 }
5e4d8bd4486c support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2667
diff changeset
4731
5e4d8bd4486c support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2667
diff changeset
4732
5e4d8bd4486c support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2667
diff changeset
4733 static ngx_int_t
4117
103b0d9afe07 Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4116
diff changeset
4734 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
4735 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
4736 {
103b0d9afe07 Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4116
diff changeset
4737 ngx_http_upstream_t *u;
103b0d9afe07 Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4116
diff changeset
4738
103b0d9afe07 Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4116
diff changeset
4739 u = r->upstream;
103b0d9afe07 Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4116
diff changeset
4740
8033
2bf7792c262e Upstream: header handlers can now return parsing errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8032
diff changeset
4741 if (u->headers_in.content_length) {
2bf7792c262e Upstream: header handlers can now return parsing errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8032
diff changeset
4742 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
2bf7792c262e Upstream: header handlers can now return parsing errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8032
diff changeset
4743 "upstream sent duplicate header line: \"%V: %V\", "
2bf7792c262e Upstream: header handlers can now return parsing errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8032
diff changeset
4744 "previous value: \"%V: %V\"",
2bf7792c262e Upstream: header handlers can now return parsing errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8032
diff changeset
4745 &h->key, &h->value,
2bf7792c262e Upstream: header handlers can now return parsing errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8032
diff changeset
4746 &u->headers_in.content_length->key,
2bf7792c262e Upstream: header handlers can now return parsing errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8032
diff changeset
4747 &u->headers_in.content_length->value);
2bf7792c262e Upstream: header handlers can now return parsing errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8032
diff changeset
4748 return NGX_HTTP_UPSTREAM_INVALID_HEADER;
2bf7792c262e Upstream: header handlers can now return parsing errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8032
diff changeset
4749 }
2bf7792c262e Upstream: header handlers can now return parsing errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8032
diff changeset
4750
2bf7792c262e Upstream: header handlers can now return parsing errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8032
diff changeset
4751 if (u->headers_in.transfer_encoding) {
2bf7792c262e Upstream: header handlers can now return parsing errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8032
diff changeset
4752 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
2bf7792c262e Upstream: header handlers can now return parsing errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8032
diff changeset
4753 "upstream sent \"Content-Length\" and "
2bf7792c262e Upstream: header handlers can now return parsing errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8032
diff changeset
4754 "\"Transfer-Encoding\" headers at the same time");
2bf7792c262e Upstream: header handlers can now return parsing errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8032
diff changeset
4755 return NGX_HTTP_UPSTREAM_INVALID_HEADER;
2bf7792c262e Upstream: header handlers can now return parsing errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8032
diff changeset
4756 }
2bf7792c262e Upstream: header handlers can now return parsing errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8032
diff changeset
4757
8032
2025aae94739 Upstream: all known headers in u->headers_in are linked lists now.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8031
diff changeset
4758 h->next = NULL;
4117
103b0d9afe07 Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4116
diff changeset
4759 u->headers_in.content_length = h;
103b0d9afe07 Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4116
diff changeset
4760 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
4761
8033
2bf7792c262e Upstream: header handlers can now return parsing errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8032
diff changeset
4762 if (u->headers_in.content_length_n == NGX_ERROR) {
2bf7792c262e Upstream: header handlers can now return parsing errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8032
diff changeset
4763 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
2bf7792c262e Upstream: header handlers can now return parsing errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8032
diff changeset
4764 "upstream sent invalid \"Content-Length\" header: "
2bf7792c262e Upstream: header handlers can now return parsing errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8032
diff changeset
4765 "\"%V: %V\"", &h->key, &h->value);
2bf7792c262e Upstream: header handlers can now return parsing errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8032
diff changeset
4766 return NGX_HTTP_UPSTREAM_INVALID_HEADER;
2bf7792c262e Upstream: header handlers can now return parsing errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8032
diff changeset
4767 }
2bf7792c262e Upstream: header handlers can now return parsing errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8032
diff changeset
4768
4117
103b0d9afe07 Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4116
diff changeset
4769 return NGX_OK;
103b0d9afe07 Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4116
diff changeset
4770 }
103b0d9afe07 Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4116
diff changeset
4771
103b0d9afe07 Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4116
diff changeset
4772
103b0d9afe07 Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4116
diff changeset
4773 static ngx_int_t
5732
d0ce06cb9be1 Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5731
diff changeset
4774 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
4775 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
4776 {
d0ce06cb9be1 Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5731
diff changeset
4777 ngx_http_upstream_t *u;
d0ce06cb9be1 Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5731
diff changeset
4778
d0ce06cb9be1 Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5731
diff changeset
4779 u = r->upstream;
d0ce06cb9be1 Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5731
diff changeset
4780
8034
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
4781 if (u->headers_in.last_modified) {
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
4782 ngx_log_error(NGX_LOG_WARN, r->connection->log, 0,
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
4783 "upstream sent duplicate header line: \"%V: %V\", "
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
4784 "previous value: \"%V: %V\", ignored",
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
4785 &h->key, &h->value,
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
4786 &u->headers_in.last_modified->key,
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
4787 &u->headers_in.last_modified->value);
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
4788 h->hash = 0;
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
4789 return NGX_OK;
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
4790 }
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
4791
8032
2025aae94739 Upstream: all known headers in u->headers_in are linked lists now.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8031
diff changeset
4792 h->next = NULL;
5732
d0ce06cb9be1 Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5731
diff changeset
4793 u->headers_in.last_modified = h;
7093
acc2cddc7b45 Upstream: unconditional parsing of last_modified_time.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7077
diff changeset
4794 u->headers_in.last_modified_time = ngx_parse_http_time(h->value.data,
acc2cddc7b45 Upstream: unconditional parsing of last_modified_time.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7077
diff changeset
4795 h->value.len);
5732
d0ce06cb9be1 Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5731
diff changeset
4796
d0ce06cb9be1 Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5731
diff changeset
4797 return NGX_OK;
d0ce06cb9be1 Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5731
diff changeset
4798 }
d0ce06cb9be1 Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5731
diff changeset
4799
d0ce06cb9be1 Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5731
diff changeset
4800
d0ce06cb9be1 Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5731
diff changeset
4801 static ngx_int_t
3669
1f5841b1fcd7 treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents: 3667
diff changeset
4802 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
4803 ngx_uint_t offset)
1f5841b1fcd7 treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents: 3667
diff changeset
4804 {
5677
3a48775f1535 Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents: 5667
diff changeset
4805 ngx_table_elt_t **ph;
3a48775f1535 Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents: 5667
diff changeset
4806 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
4807
1f5841b1fcd7 treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents: 3667
diff changeset
4808 u = r->upstream;
8024
ef6a3a99a81a Reworked multi headers to use linked lists.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8023
diff changeset
4809 ph = &u->headers_in.set_cookie;
ef6a3a99a81a Reworked multi headers to use linked lists.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8023
diff changeset
4810
ef6a3a99a81a Reworked multi headers to use linked lists.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8023
diff changeset
4811 while (*ph) { ph = &(*ph)->next; }
5677
3a48775f1535 Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents: 5667
diff changeset
4812
3a48775f1535 Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents: 5667
diff changeset
4813 *ph = h;
8024
ef6a3a99a81a Reworked multi headers to use linked lists.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8023
diff changeset
4814 h->next = NULL;
5677
3a48775f1535 Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents: 5667
diff changeset
4815
3a48775f1535 Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents: 5667
diff changeset
4816 #if (NGX_HTTP_CACHE)
3669
1f5841b1fcd7 treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents: 3667
diff changeset
4817 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
4818 u->cacheable = 0;
1f5841b1fcd7 treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents: 3667
diff changeset
4819 }
1f5841b1fcd7 treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents: 3667
diff changeset
4820 #endif
1f5841b1fcd7 treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents: 3667
diff changeset
4821
1f5841b1fcd7 treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents: 3667
diff changeset
4822 return NGX_OK;
1f5841b1fcd7 treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents: 3667
diff changeset
4823 }
1f5841b1fcd7 treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents: 3667
diff changeset
4824
1f5841b1fcd7 treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents: 3667
diff changeset
4825
1f5841b1fcd7 treat Set-Cookie as a header that forbids caching
Igor Sysoev <igor@sysoev.ru>
parents: 3667
diff changeset
4826 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
4827 ngx_http_upstream_process_cache_control(ngx_http_request_t *r,
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
4828 ngx_table_elt_t *h, ngx_uint_t offset)
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
4829 {
8028
27d12017f300 Upstream: style.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8024
diff changeset
4830 ngx_table_elt_t **ph;
27d12017f300 Upstream: style.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8024
diff changeset
4831 ngx_http_upstream_t *u;
2786
4e002555652d proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents: 2757
diff changeset
4832
4e002555652d proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents: 2757
diff changeset
4833 u = r->upstream;
8024
ef6a3a99a81a Reworked multi headers to use linked lists.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8023
diff changeset
4834 ph = &u->headers_in.cache_control;
ef6a3a99a81a Reworked multi headers to use linked lists.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8023
diff changeset
4835
ef6a3a99a81a Reworked multi headers to use linked lists.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8023
diff changeset
4836 while (*ph) { ph = &(*ph)->next; }
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
4837
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
4838 *ph = h;
8024
ef6a3a99a81a Reworked multi headers to use linked lists.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8023
diff changeset
4839 h->next = NULL;
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
4840
2708
4c658be4ab63 fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents: 2704
diff changeset
4841 #if (NGX_HTTP_CACHE)
4c658be4ab63 fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents: 2704
diff changeset
4842 {
5911
88d55e5934f7 Cache: add support for Cache-Control's s-maxage response directive.
Piotr Sikora <piotr@cloudflare.com>
parents: 5905
diff changeset
4843 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
4844 ngx_int_t n;
4c658be4ab63 fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents: 2704
diff changeset
4845
2786
4e002555652d proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents: 2757
diff changeset
4846 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
4847 return NGX_OK;
4e002555652d proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents: 2757
diff changeset
4848 }
4e002555652d proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents: 2757
diff changeset
4849
2669
5e4d8bd4486c support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2667
diff changeset
4850 if (r->cache == NULL) {
5e4d8bd4486c support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2667
diff changeset
4851 return NGX_OK;
5e4d8bd4486c support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2667
diff changeset
4852 }
5e4d8bd4486c support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2667
diff changeset
4853
5911
88d55e5934f7 Cache: add support for Cache-Control's s-maxage response directive.
Piotr Sikora <piotr@cloudflare.com>
parents: 5905
diff changeset
4854 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
4855 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
4856
8041
0784ab86ad08 Upstream: fixed X-Accel-Expires/Cache-Control/Expires handling.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8040
diff changeset
4857 if (r->cache->valid_sec != 0 && u->headers_in.x_accel_expires != NULL) {
0784ab86ad08 Upstream: fixed X-Accel-Expires/Cache-Control/Expires handling.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8040
diff changeset
4858 goto extensions;
0784ab86ad08 Upstream: fixed X-Accel-Expires/Cache-Control/Expires handling.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8040
diff changeset
4859 }
0784ab86ad08 Upstream: fixed X-Accel-Expires/Cache-Control/Expires handling.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8040
diff changeset
4860
5911
88d55e5934f7 Cache: add support for Cache-Control's s-maxage response directive.
Piotr Sikora <piotr@cloudflare.com>
parents: 5905
diff changeset
4861 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
4862 || 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
4863 || 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
4864 {
8041
0784ab86ad08 Upstream: fixed X-Accel-Expires/Cache-Control/Expires handling.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8040
diff changeset
4865 u->headers_in.no_cache = 1;
2669
5e4d8bd4486c support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2667
diff changeset
4866 return NGX_OK;
5e4d8bd4486c support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2667
diff changeset
4867 }
5e4d8bd4486c support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2667
diff changeset
4868
5911
88d55e5934f7 Cache: add support for Cache-Control's s-maxage response directive.
Piotr Sikora <piotr@cloudflare.com>
parents: 5905
diff changeset
4869 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
4870 offset = 9;
88d55e5934f7 Cache: add support for Cache-Control's s-maxage response directive.
Piotr Sikora <piotr@cloudflare.com>
parents: 5905
diff changeset
4871
88d55e5934f7 Cache: add support for Cache-Control's s-maxage response directive.
Piotr Sikora <piotr@cloudflare.com>
parents: 5905
diff changeset
4872 if (p == NULL) {
88d55e5934f7 Cache: add support for Cache-Control's s-maxage response directive.
Piotr Sikora <piotr@cloudflare.com>
parents: 5905
diff changeset
4873 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
4874 offset = 8;
88d55e5934f7 Cache: add support for Cache-Control's s-maxage response directive.
Piotr Sikora <piotr@cloudflare.com>
parents: 5905
diff changeset
4875 }
2669
5e4d8bd4486c support Cache-Control no-cache and max-age in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2667
diff changeset
4876
6905
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6899
diff changeset
4877 if (p) {
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6899
diff changeset
4878 n = 0;
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6899
diff changeset
4879
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6899
diff changeset
4880 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
4881 if (*p == ',' || *p == ';' || *p == ' ') {
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6899
diff changeset
4882 break;
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6899
diff changeset
4883 }
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6899
diff changeset
4884
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6899
diff changeset
4885 if (*p >= '0' && *p <= '9') {
7067
e3723f2a11b7 Parenthesized ASCII-related calculations.
Valentin Bartenev <vbart@nginx.com>
parents: 7042
diff changeset
4886 n = n * 10 + (*p - '0');
6905
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6899
diff changeset
4887 continue;
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6899
diff changeset
4888 }
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6899
diff changeset
4889
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6899
diff changeset
4890 u->cacheable = 0;
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6899
diff changeset
4891 return NGX_OK;
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6899
diff changeset
4892 }
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6899
diff changeset
4893
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6899
diff changeset
4894 if (n == 0) {
8041
0784ab86ad08 Upstream: fixed X-Accel-Expires/Cache-Control/Expires handling.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8040
diff changeset
4895 u->headers_in.no_cache = 1;
6905
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6899
diff changeset
4896 return NGX_OK;
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6899
diff changeset
4897 }
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6899
diff changeset
4898
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6899
diff changeset
4899 r->cache->valid_sec = ngx_time() + n;
8041
0784ab86ad08 Upstream: fixed X-Accel-Expires/Cache-Control/Expires handling.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8040
diff changeset
4900 u->headers_in.expired = 0;
0784ab86ad08 Upstream: fixed X-Accel-Expires/Cache-Control/Expires handling.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8040
diff changeset
4901 }
0784ab86ad08 Upstream: fixed X-Accel-Expires/Cache-Control/Expires handling.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8040
diff changeset
4902
0784ab86ad08 Upstream: fixed X-Accel-Expires/Cache-Control/Expires handling.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8040
diff changeset
4903 extensions:
6905
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6899
diff changeset
4904
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6899
diff changeset
4905 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
4906 23 - 1);
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6899
diff changeset
4907
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6899
diff changeset
4908 if (p) {
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6899
diff changeset
4909 n = 0;
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6899
diff changeset
4910
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6899
diff changeset
4911 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
4912 if (*p == ',' || *p == ';' || *p == ' ') {
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6899
diff changeset
4913 break;
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6899
diff changeset
4914 }
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6899
diff changeset
4915
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6899
diff changeset
4916 if (*p >= '0' && *p <= '9') {
7067
e3723f2a11b7 Parenthesized ASCII-related calculations.
Valentin Bartenev <vbart@nginx.com>
parents: 7042
diff changeset
4917 n = n * 10 + (*p - '0');
6905
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6899
diff changeset
4918 continue;
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6899
diff changeset
4919 }
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6899
diff changeset
4920
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6899
diff changeset
4921 u->cacheable = 0;
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6899
diff changeset
4922 return NGX_OK;
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6899
diff changeset
4923 }
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6899
diff changeset
4924
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6899
diff changeset
4925 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
4926 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
4927 }
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6899
diff changeset
4928
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6899
diff changeset
4929 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
4930
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6899
diff changeset
4931 if (p) {
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6899
diff changeset
4932 n = 0;
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6899
diff changeset
4933
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6899
diff changeset
4934 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
4935 if (*p == ',' || *p == ';' || *p == ' ') {
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6899
diff changeset
4936 break;
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6899
diff changeset
4937 }
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6899
diff changeset
4938
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6899
diff changeset
4939 if (*p >= '0' && *p <= '9') {
7067
e3723f2a11b7 Parenthesized ASCII-related calculations.
Valentin Bartenev <vbart@nginx.com>
parents: 7042
diff changeset
4940 n = n * 10 + (*p - '0');
6905
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6899
diff changeset
4941 continue;
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6899
diff changeset
4942 }
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6899
diff changeset
4943
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6899
diff changeset
4944 u->cacheable = 0;
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6899
diff changeset
4945 return NGX_OK;
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6899
diff changeset
4946 }
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6899
diff changeset
4947
9a9e13686869 Cache: support for stale-while-revalidate and stale-if-error.
Roman Arutyunyan <arut@nginx.com>
parents: 6899
diff changeset
4948 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
4949 }
2708
4c658be4ab63 fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents: 2704
diff changeset
4950 }
4c658be4ab63 fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents: 2704
diff changeset
4951 #endif
4c658be4ab63 fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents: 2704
diff changeset
4952
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
4953 return NGX_OK;
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
4954 }
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
4955
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
4956
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
4957 static ngx_int_t
2666
81556a9b6488 support Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2665
diff changeset
4958 ngx_http_upstream_process_expires(ngx_http_request_t *r, ngx_table_elt_t *h,
81556a9b6488 support Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2665
diff changeset
4959 ngx_uint_t offset)
81556a9b6488 support Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2665
diff changeset
4960 {
2786
4e002555652d proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents: 2757
diff changeset
4961 ngx_http_upstream_t *u;
4e002555652d proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents: 2757
diff changeset
4962
4e002555652d proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents: 2757
diff changeset
4963 u = r->upstream;
8034
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
4964
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
4965 if (u->headers_in.expires) {
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
4966 ngx_log_error(NGX_LOG_WARN, r->connection->log, 0,
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
4967 "upstream sent duplicate header line: \"%V: %V\", "
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
4968 "previous value: \"%V: %V\", ignored",
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
4969 &h->key, &h->value,
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
4970 &u->headers_in.expires->key,
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
4971 &u->headers_in.expires->value);
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
4972 h->hash = 0;
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
4973 return NGX_OK;
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
4974 }
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
4975
2786
4e002555652d proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents: 2757
diff changeset
4976 u->headers_in.expires = h;
8032
2025aae94739 Upstream: all known headers in u->headers_in are linked lists now.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8031
diff changeset
4977 h->next = NULL;
2708
4c658be4ab63 fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents: 2704
diff changeset
4978
4c658be4ab63 fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents: 2704
diff changeset
4979 #if (NGX_HTTP_CACHE)
4c658be4ab63 fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents: 2704
diff changeset
4980 {
2666
81556a9b6488 support Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2665
diff changeset
4981 time_t expires;
81556a9b6488 support Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2665
diff changeset
4982
2786
4e002555652d proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents: 2757
diff changeset
4983 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
4984 return NGX_OK;
4e002555652d proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents: 2757
diff changeset
4985 }
4e002555652d proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents: 2757
diff changeset
4986
2666
81556a9b6488 support Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2665
diff changeset
4987 if (r->cache == NULL) {
81556a9b6488 support Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2665
diff changeset
4988 return NGX_OK;
81556a9b6488 support Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2665
diff changeset
4989 }
81556a9b6488 support Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2665
diff changeset
4990
81556a9b6488 support Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2665
diff changeset
4991 if (r->cache->valid_sec != 0) {
81556a9b6488 support Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2665
diff changeset
4992 return NGX_OK;
81556a9b6488 support Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2665
diff changeset
4993 }
81556a9b6488 support Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2665
diff changeset
4994
6180
8b6fa4842133 Moved ngx_http_parse_time() to core, renamed accordingly.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6147
diff changeset
4995 expires = ngx_parse_http_time(h->value.data, h->value.len);
2666
81556a9b6488 support Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2665
diff changeset
4996
81556a9b6488 support Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2665
diff changeset
4997 if (expires == NGX_ERROR || expires < ngx_time()) {
8041
0784ab86ad08 Upstream: fixed X-Accel-Expires/Cache-Control/Expires handling.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8040
diff changeset
4998 u->headers_in.expired = 1;
2666
81556a9b6488 support Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2665
diff changeset
4999 return NGX_OK;
81556a9b6488 support Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2665
diff changeset
5000 }
81556a9b6488 support Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2665
diff changeset
5001
81556a9b6488 support Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2665
diff changeset
5002 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
5003 }
4c658be4ab63 fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents: 2704
diff changeset
5004 #endif
2666
81556a9b6488 support Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2665
diff changeset
5005
81556a9b6488 support Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2665
diff changeset
5006 return NGX_OK;
81556a9b6488 support Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2665
diff changeset
5007 }
81556a9b6488 support Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2665
diff changeset
5008
81556a9b6488 support Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2665
diff changeset
5009
81556a9b6488 support Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2665
diff changeset
5010 static ngx_int_t
2663
09725d69cb25 support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2662
diff changeset
5011 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
5012 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
5013 {
2786
4e002555652d proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents: 2757
diff changeset
5014 ngx_http_upstream_t *u;
4e002555652d proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents: 2757
diff changeset
5015
4e002555652d proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents: 2757
diff changeset
5016 u = r->upstream;
8034
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
5017
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
5018 if (u->headers_in.x_accel_expires) {
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
5019 ngx_log_error(NGX_LOG_WARN, r->connection->log, 0,
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
5020 "upstream sent duplicate header line: \"%V: %V\", "
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
5021 "previous value: \"%V: %V\", ignored",
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
5022 &h->key, &h->value,
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
5023 &u->headers_in.x_accel_expires->key,
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
5024 &u->headers_in.x_accel_expires->value);
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
5025 h->hash = 0;
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
5026 return NGX_OK;
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
5027 }
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
5028
2786
4e002555652d proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents: 2757
diff changeset
5029 u->headers_in.x_accel_expires = h;
8032
2025aae94739 Upstream: all known headers in u->headers_in are linked lists now.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8031
diff changeset
5030 h->next = NULL;
2708
4c658be4ab63 fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents: 2704
diff changeset
5031
4c658be4ab63 fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents: 2704
diff changeset
5032 #if (NGX_HTTP_CACHE)
4c658be4ab63 fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents: 2704
diff changeset
5033 {
2663
09725d69cb25 support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2662
diff changeset
5034 u_char *p;
09725d69cb25 support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2662
diff changeset
5035 size_t len;
09725d69cb25 support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2662
diff changeset
5036 ngx_int_t n;
09725d69cb25 support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2662
diff changeset
5037
2786
4e002555652d proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents: 2757
diff changeset
5038 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
5039 return NGX_OK;
4e002555652d proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents: 2757
diff changeset
5040 }
4e002555652d proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents: 2757
diff changeset
5041
2663
09725d69cb25 support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2662
diff changeset
5042 if (r->cache == NULL) {
09725d69cb25 support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2662
diff changeset
5043 return NGX_OK;
09725d69cb25 support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2662
diff changeset
5044 }
09725d69cb25 support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2662
diff changeset
5045
09725d69cb25 support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2662
diff changeset
5046 len = h->value.len;
09725d69cb25 support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2662
diff changeset
5047 p = h->value.data;
09725d69cb25 support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2662
diff changeset
5048
09725d69cb25 support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2662
diff changeset
5049 if (p[0] != '@') {
09725d69cb25 support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2662
diff changeset
5050 n = ngx_atoi(p, len);
09725d69cb25 support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2662
diff changeset
5051
09725d69cb25 support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2662
diff changeset
5052 switch (n) {
09725d69cb25 support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2662
diff changeset
5053 case 0:
2786
4e002555652d proxy_ignore_headers and fastcgi_ignore_headers
Igor Sysoev <igor@sysoev.ru>
parents: 2757
diff changeset
5054 u->cacheable = 0;
4546
4988fa232629 For the sake of case/switch code readability, 'fall through'
Maxim Konovalov <maxim@nginx.com>
parents: 4499
diff changeset
5055 /* fall through */
4988fa232629 For the sake of case/switch code readability, 'fall through'
Maxim Konovalov <maxim@nginx.com>
parents: 4499
diff changeset
5056
2663
09725d69cb25 support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2662
diff changeset
5057 case NGX_ERROR:
2667
c1ac00c2bc75 update r2664
Igor Sysoev <igor@sysoev.ru>
parents: 2666
diff changeset
5058 return NGX_OK;
2663
09725d69cb25 support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2662
diff changeset
5059
09725d69cb25 support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2662
diff changeset
5060 default:
09725d69cb25 support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2662
diff changeset
5061 r->cache->valid_sec = ngx_time() + n;
8041
0784ab86ad08 Upstream: fixed X-Accel-Expires/Cache-Control/Expires handling.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8040
diff changeset
5062 u->headers_in.no_cache = 0;
0784ab86ad08 Upstream: fixed X-Accel-Expires/Cache-Control/Expires handling.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8040
diff changeset
5063 u->headers_in.expired = 0;
2667
c1ac00c2bc75 update r2664
Igor Sysoev <igor@sysoev.ru>
parents: 2666
diff changeset
5064 return NGX_OK;
2663
09725d69cb25 support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2662
diff changeset
5065 }
2667
c1ac00c2bc75 update r2664
Igor Sysoev <igor@sysoev.ru>
parents: 2666
diff changeset
5066 }
c1ac00c2bc75 update r2664
Igor Sysoev <igor@sysoev.ru>
parents: 2666
diff changeset
5067
c1ac00c2bc75 update r2664
Igor Sysoev <igor@sysoev.ru>
parents: 2666
diff changeset
5068 p++;
c1ac00c2bc75 update r2664
Igor Sysoev <igor@sysoev.ru>
parents: 2666
diff changeset
5069 len--;
c1ac00c2bc75 update r2664
Igor Sysoev <igor@sysoev.ru>
parents: 2666
diff changeset
5070
c1ac00c2bc75 update r2664
Igor Sysoev <igor@sysoev.ru>
parents: 2666
diff changeset
5071 n = ngx_atoi(p, len);
c1ac00c2bc75 update r2664
Igor Sysoev <igor@sysoev.ru>
parents: 2666
diff changeset
5072
c1ac00c2bc75 update r2664
Igor Sysoev <igor@sysoev.ru>
parents: 2666
diff changeset
5073 if (n != NGX_ERROR) {
c1ac00c2bc75 update r2664
Igor Sysoev <igor@sysoev.ru>
parents: 2666
diff changeset
5074 r->cache->valid_sec = n;
8041
0784ab86ad08 Upstream: fixed X-Accel-Expires/Cache-Control/Expires handling.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8040
diff changeset
5075 u->headers_in.no_cache = 0;
0784ab86ad08 Upstream: fixed X-Accel-Expires/Cache-Control/Expires handling.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8040
diff changeset
5076 u->headers_in.expired = 0;
2663
09725d69cb25 support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2662
diff changeset
5077 }
2708
4c658be4ab63 fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents: 2704
diff changeset
5078 }
4c658be4ab63 fix building --without-http-cache, introduced in r2664 and later
Igor Sysoev <igor@sysoev.ru>
parents: 2704
diff changeset
5079 #endif
2663
09725d69cb25 support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2662
diff changeset
5080
09725d69cb25 support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2662
diff changeset
5081 return NGX_OK;
09725d69cb25 support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2662
diff changeset
5082 }
09725d69cb25 support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2662
diff changeset
5083
09725d69cb25 support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2662
diff changeset
5084
09725d69cb25 support X-Accel-Expires in cache
Igor Sysoev <igor@sysoev.ru>
parents: 2662
diff changeset
5085 static ngx_int_t
527
7fa11e5c6e96 nginx-0.1.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 525
diff changeset
5086 ngx_http_upstream_process_limit_rate(ngx_http_request_t *r, ngx_table_elt_t *h,
7fa11e5c6e96 nginx-0.1.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 525
diff changeset
5087 ngx_uint_t offset)
577
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
5088 {
4197
cf6a3467b5db Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4182
diff changeset
5089 ngx_int_t n;
cf6a3467b5db Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4182
diff changeset
5090 ngx_http_upstream_t *u;
cf6a3467b5db Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4182
diff changeset
5091
cf6a3467b5db Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4182
diff changeset
5092 u = r->upstream;
8034
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
5093
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
5094 if (u->headers_in.x_accel_limit_rate) {
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
5095 ngx_log_error(NGX_LOG_WARN, r->connection->log, 0,
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
5096 "upstream sent duplicate header line: \"%V: %V\", "
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
5097 "previous value: \"%V: %V\", ignored",
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
5098 &h->key, &h->value,
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
5099 &u->headers_in.x_accel_limit_rate->key,
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
5100 &u->headers_in.x_accel_limit_rate->value);
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
5101 h->hash = 0;
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
5102 return NGX_OK;
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
5103 }
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
5104
4197
cf6a3467b5db Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4182
diff changeset
5105 u->headers_in.x_accel_limit_rate = h;
8032
2025aae94739 Upstream: all known headers in u->headers_in are linked lists now.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8031
diff changeset
5106 h->next = NULL;
4197
cf6a3467b5db Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4182
diff changeset
5107
cf6a3467b5db Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4182
diff changeset
5108 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
5109 return NGX_OK;
cf6a3467b5db Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4182
diff changeset
5110 }
527
7fa11e5c6e96 nginx-0.1.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 525
diff changeset
5111
7fa11e5c6e96 nginx-0.1.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 525
diff changeset
5112 n = ngx_atoi(h->value.data, h->value.len);
7fa11e5c6e96 nginx-0.1.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 525
diff changeset
5113
7fa11e5c6e96 nginx-0.1.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 525
diff changeset
5114 if (n != NGX_ERROR) {
7fa11e5c6e96 nginx-0.1.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 525
diff changeset
5115 r->limit_rate = (size_t) n;
7504
c19ca381b2e6 Variables support in limit_rate and limit_rate_after (ticket #293).
Ruslan Ermilov <ru@nginx.com>
parents: 7456
diff changeset
5116 r->limit_rate_set = 1;
527
7fa11e5c6e96 nginx-0.1.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 525
diff changeset
5117 }
7fa11e5c6e96 nginx-0.1.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 525
diff changeset
5118
7fa11e5c6e96 nginx-0.1.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 525
diff changeset
5119 return NGX_OK;
7fa11e5c6e96 nginx-0.1.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 525
diff changeset
5120 }
7fa11e5c6e96 nginx-0.1.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 525
diff changeset
5121
7fa11e5c6e96 nginx-0.1.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 525
diff changeset
5122
7fa11e5c6e96 nginx-0.1.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 525
diff changeset
5123 static ngx_int_t
649
1e720b0be7ec nginx-0.3.46-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 641
diff changeset
5124 ngx_http_upstream_process_buffering(ngx_http_request_t *r, ngx_table_elt_t *h,
1e720b0be7ec nginx-0.3.46-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 641
diff changeset
5125 ngx_uint_t offset)
1e720b0be7ec nginx-0.3.46-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 641
diff changeset
5126 {
4197
cf6a3467b5db Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4182
diff changeset
5127 u_char c0, c1, c2;
cf6a3467b5db Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4182
diff changeset
5128 ngx_http_upstream_t *u;
cf6a3467b5db Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4182
diff changeset
5129
cf6a3467b5db Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4182
diff changeset
5130 u = r->upstream;
cf6a3467b5db Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4182
diff changeset
5131
cf6a3467b5db Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4182
diff changeset
5132 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
5133 return NGX_OK;
cf6a3467b5db Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4182
diff changeset
5134 }
cf6a3467b5db Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4182
diff changeset
5135
cf6a3467b5db Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4182
diff changeset
5136 if (u->conf->change_buffering) {
649
1e720b0be7ec nginx-0.3.46-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 641
diff changeset
5137
1e720b0be7ec nginx-0.3.46-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 641
diff changeset
5138 if (h->value.len == 2) {
1e720b0be7ec nginx-0.3.46-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 641
diff changeset
5139 c0 = ngx_tolower(h->value.data[0]);
1e720b0be7ec nginx-0.3.46-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 641
diff changeset
5140 c1 = ngx_tolower(h->value.data[1]);
1e720b0be7ec nginx-0.3.46-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 641
diff changeset
5141
1e720b0be7ec nginx-0.3.46-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 641
diff changeset
5142 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
5143 u->buffering = 0;
649
1e720b0be7ec nginx-0.3.46-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 641
diff changeset
5144 }
1e720b0be7ec nginx-0.3.46-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 641
diff changeset
5145
1e720b0be7ec nginx-0.3.46-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 641
diff changeset
5146 } else if (h->value.len == 3) {
1e720b0be7ec nginx-0.3.46-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 641
diff changeset
5147 c0 = ngx_tolower(h->value.data[0]);
1e720b0be7ec nginx-0.3.46-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 641
diff changeset
5148 c1 = ngx_tolower(h->value.data[1]);
1e720b0be7ec nginx-0.3.46-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 641
diff changeset
5149 c2 = ngx_tolower(h->value.data[2]);
1e720b0be7ec nginx-0.3.46-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 641
diff changeset
5150
1e720b0be7ec nginx-0.3.46-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 641
diff changeset
5151 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
5152 u->buffering = 1;
649
1e720b0be7ec nginx-0.3.46-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 641
diff changeset
5153 }
1e720b0be7ec nginx-0.3.46-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 641
diff changeset
5154 }
1e720b0be7ec nginx-0.3.46-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 641
diff changeset
5155 }
1e720b0be7ec nginx-0.3.46-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 641
diff changeset
5156
1e720b0be7ec nginx-0.3.46-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 641
diff changeset
5157 return NGX_OK;
1e720b0be7ec nginx-0.3.46-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 641
diff changeset
5158 }
1e720b0be7ec nginx-0.3.46-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 641
diff changeset
5159
1e720b0be7ec nginx-0.3.46-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 641
diff changeset
5160
1e720b0be7ec nginx-0.3.46-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 641
diff changeset
5161 static ngx_int_t
657
400711951595 nginx-0.3.50-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 653
diff changeset
5162 ngx_http_upstream_process_charset(ngx_http_request_t *r, ngx_table_elt_t *h,
400711951595 nginx-0.3.50-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 653
diff changeset
5163 ngx_uint_t offset)
400711951595 nginx-0.3.50-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 653
diff changeset
5164 {
8028
27d12017f300 Upstream: style.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8024
diff changeset
5165 ngx_http_upstream_t *u;
27d12017f300 Upstream: style.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8024
diff changeset
5166
27d12017f300 Upstream: style.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8024
diff changeset
5167 u = r->upstream;
27d12017f300 Upstream: style.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8024
diff changeset
5168
27d12017f300 Upstream: style.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8024
diff changeset
5169 if (u->conf->ignore_headers & NGX_HTTP_UPSTREAM_IGN_XA_CHARSET) {
4197
cf6a3467b5db Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4182
diff changeset
5170 return NGX_OK;
cf6a3467b5db Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4182
diff changeset
5171 }
cf6a3467b5db Additional headers for proxy/fastcgi/uwsgi/scgi_ignore_headers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4182
diff changeset
5172
657
400711951595 nginx-0.3.50-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 653
diff changeset
5173 r->headers_out.override_charset = &h->value;
400711951595 nginx-0.3.50-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 653
diff changeset
5174
400711951595 nginx-0.3.50-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 653
diff changeset
5175 return NGX_OK;
400711951595 nginx-0.3.50-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 653
diff changeset
5176 }
400711951595 nginx-0.3.50-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 653
diff changeset
5177
400711951595 nginx-0.3.50-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 653
diff changeset
5178
400711951595 nginx-0.3.50-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 653
diff changeset
5179 static ngx_int_t
4124
0c30976f5bfa Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4123
diff changeset
5180 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
5181 ngx_uint_t offset)
0c30976f5bfa Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4123
diff changeset
5182 {
8034
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
5183 ngx_table_elt_t **ph;
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
5184 ngx_http_upstream_t *u;
8028
27d12017f300 Upstream: style.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8024
diff changeset
5185
27d12017f300 Upstream: style.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8024
diff changeset
5186 u = r->upstream;
8034
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
5187 ph = &u->headers_in.connection;
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
5188
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
5189 while (*ph) { ph = &(*ph)->next; }
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
5190
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
5191 *ph = h;
8032
2025aae94739 Upstream: all known headers in u->headers_in are linked lists now.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8031
diff changeset
5192 h->next = NULL;
4124
0c30976f5bfa Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4123
diff changeset
5193
0c30976f5bfa Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4123
diff changeset
5194 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
5195 (u_char *) "close", 5 - 1)
0c30976f5bfa Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4123
diff changeset
5196 != NULL)
0c30976f5bfa Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4123
diff changeset
5197 {
8028
27d12017f300 Upstream: style.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8024
diff changeset
5198 u->headers_in.connection_close = 1;
4124
0c30976f5bfa Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4123
diff changeset
5199 }
0c30976f5bfa Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4123
diff changeset
5200
0c30976f5bfa Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4123
diff changeset
5201 return NGX_OK;
0c30976f5bfa Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4123
diff changeset
5202 }
0c30976f5bfa Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4123
diff changeset
5203
0c30976f5bfa Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4123
diff changeset
5204
0c30976f5bfa Upstream: Connection header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4123
diff changeset
5205 static ngx_int_t
4123
0ee350b5177c Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4120
diff changeset
5206 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
5207 ngx_table_elt_t *h, ngx_uint_t offset)
0ee350b5177c Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4120
diff changeset
5208 {
8028
27d12017f300 Upstream: style.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8024
diff changeset
5209 ngx_http_upstream_t *u;
27d12017f300 Upstream: style.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8024
diff changeset
5210
27d12017f300 Upstream: style.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8024
diff changeset
5211 u = r->upstream;
8033
2bf7792c262e Upstream: header handlers can now return parsing errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8032
diff changeset
5212
2bf7792c262e Upstream: header handlers can now return parsing errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8032
diff changeset
5213 if (u->headers_in.transfer_encoding) {
2bf7792c262e Upstream: header handlers can now return parsing errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8032
diff changeset
5214 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
2bf7792c262e Upstream: header handlers can now return parsing errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8032
diff changeset
5215 "upstream sent duplicate header line: \"%V: %V\", "
2bf7792c262e Upstream: header handlers can now return parsing errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8032
diff changeset
5216 "previous value: \"%V: %V\"",
2bf7792c262e Upstream: header handlers can now return parsing errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8032
diff changeset
5217 &h->key, &h->value,
2bf7792c262e Upstream: header handlers can now return parsing errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8032
diff changeset
5218 &u->headers_in.transfer_encoding->key,
2bf7792c262e Upstream: header handlers can now return parsing errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8032
diff changeset
5219 &u->headers_in.transfer_encoding->value);
2bf7792c262e Upstream: header handlers can now return parsing errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8032
diff changeset
5220 return NGX_HTTP_UPSTREAM_INVALID_HEADER;
2bf7792c262e Upstream: header handlers can now return parsing errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8032
diff changeset
5221 }
2bf7792c262e Upstream: header handlers can now return parsing errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8032
diff changeset
5222
2bf7792c262e Upstream: header handlers can now return parsing errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8032
diff changeset
5223 if (u->headers_in.content_length) {
2bf7792c262e Upstream: header handlers can now return parsing errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8032
diff changeset
5224 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
2bf7792c262e Upstream: header handlers can now return parsing errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8032
diff changeset
5225 "upstream sent \"Content-Length\" and "
2bf7792c262e Upstream: header handlers can now return parsing errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8032
diff changeset
5226 "\"Transfer-Encoding\" headers at the same time");
2bf7792c262e Upstream: header handlers can now return parsing errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8032
diff changeset
5227 return NGX_HTTP_UPSTREAM_INVALID_HEADER;
2bf7792c262e Upstream: header handlers can now return parsing errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8032
diff changeset
5228 }
2bf7792c262e Upstream: header handlers can now return parsing errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8032
diff changeset
5229
8028
27d12017f300 Upstream: style.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8024
diff changeset
5230 u->headers_in.transfer_encoding = h;
8032
2025aae94739 Upstream: all known headers in u->headers_in are linked lists now.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8031
diff changeset
5231 h->next = NULL;
4123
0ee350b5177c Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4120
diff changeset
5232
8033
2bf7792c262e Upstream: header handlers can now return parsing errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8032
diff changeset
5233 if (h->value.len == 7
2bf7792c262e Upstream: header handlers can now return parsing errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8032
diff changeset
5234 && ngx_strncasecmp(h->value.data, (u_char *) "chunked", 7) == 0)
4123
0ee350b5177c Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4120
diff changeset
5235 {
8028
27d12017f300 Upstream: style.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8024
diff changeset
5236 u->headers_in.chunked = 1;
8033
2bf7792c262e Upstream: header handlers can now return parsing errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8032
diff changeset
5237
2bf7792c262e Upstream: header handlers can now return parsing errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8032
diff changeset
5238 } else {
2bf7792c262e Upstream: header handlers can now return parsing errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8032
diff changeset
5239 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
2bf7792c262e Upstream: header handlers can now return parsing errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8032
diff changeset
5240 "upstream sent unknown \"Transfer-Encoding\": \"%V\"",
2bf7792c262e Upstream: header handlers can now return parsing errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8032
diff changeset
5241 &h->value);
2bf7792c262e Upstream: header handlers can now return parsing errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8032
diff changeset
5242 return NGX_HTTP_UPSTREAM_INVALID_HEADER;
4123
0ee350b5177c Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4120
diff changeset
5243 }
0ee350b5177c Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4120
diff changeset
5244
0ee350b5177c Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4120
diff changeset
5245 return NGX_OK;
0ee350b5177c Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4120
diff changeset
5246 }
0ee350b5177c Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4120
diff changeset
5247
0ee350b5177c Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4120
diff changeset
5248
0ee350b5177c Upstream: Transfer-Encoding header processing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4120
diff changeset
5249 static ngx_int_t
5877
60fde1bc7236 Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5874
diff changeset
5250 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
5251 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
5252 {
8034
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
5253 ngx_table_elt_t **ph;
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
5254 ngx_http_upstream_t *u;
5877
60fde1bc7236 Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5874
diff changeset
5255
60fde1bc7236 Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5874
diff changeset
5256 u = r->upstream;
8034
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
5257 ph = &u->headers_in.vary;
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
5258
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
5259 while (*ph) { ph = &(*ph)->next; }
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
5260
413dbda22f7d Upstream: duplicate headers ignored or properly linked.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8033
diff changeset
5261 *ph = h;
8032
2025aae94739 Upstream: all known headers in u->headers_in are linked lists now.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8031
diff changeset
5262 h->next = NULL;
5877
60fde1bc7236 Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5874
diff changeset
5263
60fde1bc7236 Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5874
diff changeset
5264 #if (NGX_HTTP_CACHE)
8040
e0cfab501dd1 Upstream: fixed build without http cache (broken by cd73509f21e2).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8036
diff changeset
5265 {
e0cfab501dd1 Upstream: fixed build without http cache (broken by cd73509f21e2).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8036
diff changeset
5266 u_char *p;
e0cfab501dd1 Upstream: fixed build without http cache (broken by cd73509f21e2).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8036
diff changeset
5267 size_t len;
e0cfab501dd1 Upstream: fixed build without http cache (broken by cd73509f21e2).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8036
diff changeset
5268 ngx_str_t vary;
5877
60fde1bc7236 Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5874
diff changeset
5269
60fde1bc7236 Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5874
diff changeset
5270 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
5271 return NGX_OK;
60fde1bc7236 Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5874
diff changeset
5272 }
60fde1bc7236 Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5874
diff changeset
5273
8035
cd73509f21e2 Upstream: handling of multiple Vary headers (ticket #1423).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8034
diff changeset
5274 if (r->cache == NULL || !u->cacheable) {
cd73509f21e2 Upstream: handling of multiple Vary headers (ticket #1423).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8034
diff changeset
5275 return NGX_OK;
cd73509f21e2 Upstream: handling of multiple Vary headers (ticket #1423).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8034
diff changeset
5276 }
cd73509f21e2 Upstream: handling of multiple Vary headers (ticket #1423).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8034
diff changeset
5277
cd73509f21e2 Upstream: handling of multiple Vary headers (ticket #1423).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8034
diff changeset
5278 if (h->value.len == 1 && h->value.data[0] == '*') {
cd73509f21e2 Upstream: handling of multiple Vary headers (ticket #1423).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8034
diff changeset
5279 u->cacheable = 0;
5878
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5877
diff changeset
5280 return NGX_OK;
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5877
diff changeset
5281 }
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5877
diff changeset
5282
8035
cd73509f21e2 Upstream: handling of multiple Vary headers (ticket #1423).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8034
diff changeset
5283 if (u->headers_in.vary->next) {
cd73509f21e2 Upstream: handling of multiple Vary headers (ticket #1423).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8034
diff changeset
5284
cd73509f21e2 Upstream: handling of multiple Vary headers (ticket #1423).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8034
diff changeset
5285 len = 0;
cd73509f21e2 Upstream: handling of multiple Vary headers (ticket #1423).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8034
diff changeset
5286
cd73509f21e2 Upstream: handling of multiple Vary headers (ticket #1423).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8034
diff changeset
5287 for (h = u->headers_in.vary; h; h = h->next) {
cd73509f21e2 Upstream: handling of multiple Vary headers (ticket #1423).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8034
diff changeset
5288 len += h->value.len + 2;
cd73509f21e2 Upstream: handling of multiple Vary headers (ticket #1423).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8034
diff changeset
5289 }
cd73509f21e2 Upstream: handling of multiple Vary headers (ticket #1423).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8034
diff changeset
5290
cd73509f21e2 Upstream: handling of multiple Vary headers (ticket #1423).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8034
diff changeset
5291 len -= 2;
cd73509f21e2 Upstream: handling of multiple Vary headers (ticket #1423).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8034
diff changeset
5292
cd73509f21e2 Upstream: handling of multiple Vary headers (ticket #1423).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8034
diff changeset
5293 p = ngx_pnalloc(r->pool, len);
cd73509f21e2 Upstream: handling of multiple Vary headers (ticket #1423).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8034
diff changeset
5294 if (p == NULL) {
cd73509f21e2 Upstream: handling of multiple Vary headers (ticket #1423).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8034
diff changeset
5295 return NGX_ERROR;
cd73509f21e2 Upstream: handling of multiple Vary headers (ticket #1423).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8034
diff changeset
5296 }
cd73509f21e2 Upstream: handling of multiple Vary headers (ticket #1423).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8034
diff changeset
5297
cd73509f21e2 Upstream: handling of multiple Vary headers (ticket #1423).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8034
diff changeset
5298 vary.len = len;
cd73509f21e2 Upstream: handling of multiple Vary headers (ticket #1423).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8034
diff changeset
5299 vary.data = p;
cd73509f21e2 Upstream: handling of multiple Vary headers (ticket #1423).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8034
diff changeset
5300
cd73509f21e2 Upstream: handling of multiple Vary headers (ticket #1423).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8034
diff changeset
5301 for (h = u->headers_in.vary; h; h = h->next) {
cd73509f21e2 Upstream: handling of multiple Vary headers (ticket #1423).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8034
diff changeset
5302 p = ngx_copy(p, h->value.data, h->value.len);
cd73509f21e2 Upstream: handling of multiple Vary headers (ticket #1423).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8034
diff changeset
5303
cd73509f21e2 Upstream: handling of multiple Vary headers (ticket #1423).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8034
diff changeset
5304 if (h->next == NULL) {
cd73509f21e2 Upstream: handling of multiple Vary headers (ticket #1423).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8034
diff changeset
5305 break;
cd73509f21e2 Upstream: handling of multiple Vary headers (ticket #1423).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8034
diff changeset
5306 }
cd73509f21e2 Upstream: handling of multiple Vary headers (ticket #1423).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8034
diff changeset
5307
cd73509f21e2 Upstream: handling of multiple Vary headers (ticket #1423).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8034
diff changeset
5308 *p++ = ','; *p++ = ' ';
cd73509f21e2 Upstream: handling of multiple Vary headers (ticket #1423).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8034
diff changeset
5309 }
cd73509f21e2 Upstream: handling of multiple Vary headers (ticket #1423).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8034
diff changeset
5310
cd73509f21e2 Upstream: handling of multiple Vary headers (ticket #1423).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8034
diff changeset
5311 } else {
cd73509f21e2 Upstream: handling of multiple Vary headers (ticket #1423).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8034
diff changeset
5312 vary = h->value;
cd73509f21e2 Upstream: handling of multiple Vary headers (ticket #1423).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8034
diff changeset
5313 }
cd73509f21e2 Upstream: handling of multiple Vary headers (ticket #1423).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8034
diff changeset
5314
cd73509f21e2 Upstream: handling of multiple Vary headers (ticket #1423).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8034
diff changeset
5315 if (vary.len > NGX_HTTP_CACHE_VARY_LEN) {
5878
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5877
diff changeset
5316 u->cacheable = 0;
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5877
diff changeset
5317 }
2c89956b6a76 Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5877
diff changeset
5318
8035
cd73509f21e2 Upstream: handling of multiple Vary headers (ticket #1423).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8034
diff changeset
5319 r->cache->vary = vary;
8040
e0cfab501dd1 Upstream: fixed build without http cache (broken by cd73509f21e2).
Maxim Dounin <mdounin@mdounin.ru>
parents: 8036
diff changeset
5320 }
5877
60fde1bc7236 Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5874
diff changeset
5321 #endif
60fde1bc7236 Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5874
diff changeset
5322
60fde1bc7236 Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5874
diff changeset
5323 return NGX_OK;
60fde1bc7236 Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5874
diff changeset
5324 }
60fde1bc7236 Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5874
diff changeset
5325
60fde1bc7236 Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5874
diff changeset
5326
60fde1bc7236 Cache: disable caching of responses with Vary (ticket #118).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5874
diff changeset
5327 static ngx_int_t
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5328 ngx_http_upstream_copy_header_line(ngx_http_request_t *r, ngx_table_elt_t *h,
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5329 ngx_uint_t offset)
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5330 {
573
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5331 ngx_table_elt_t *ho, **ph;
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5332
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5333 ho = ngx_list_push(&r->headers_out.headers);
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5334 if (ho == NULL) {
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5335 return NGX_ERROR;
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5336 }
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5337
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5338 *ho = *h;
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5339
573
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5340 if (offset) {
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5341 ph = (ngx_table_elt_t **) ((char *) &r->headers_out + offset);
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5342 *ph = ho;
8031
d26db4f82d7d All known output headers can be linked lists now.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8030
diff changeset
5343 ho->next = NULL;
573
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5344 }
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5345
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5346 return NGX_OK;
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5347 }
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5348
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5349
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5350 static ngx_int_t
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5351 ngx_http_upstream_copy_multi_header_lines(ngx_http_request_t *r,
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5352 ngx_table_elt_t *h, ngx_uint_t offset)
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5353 {
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5354 ngx_table_elt_t *ho, **ph;
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5355
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5356 ho = ngx_list_push(&r->headers_out.headers);
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5357 if (ho == NULL) {
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5358 return NGX_ERROR;
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5359 }
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5360
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5361 *ho = *h;
6986
0cdee26605f3 Cleaned up r->headers_out.headers allocation error handling.
Sergey Kandaurov <pluknet@nginx.com>
parents: 6966
diff changeset
5362
8024
ef6a3a99a81a Reworked multi headers to use linked lists.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8023
diff changeset
5363 ph = (ngx_table_elt_t **) ((char *) &r->headers_out + offset);
ef6a3a99a81a Reworked multi headers to use linked lists.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8023
diff changeset
5364
ef6a3a99a81a Reworked multi headers to use linked lists.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8023
diff changeset
5365 while (*ph) { ph = &(*ph)->next; }
6986
0cdee26605f3 Cleaned up r->headers_out.headers allocation error handling.
Sergey Kandaurov <pluknet@nginx.com>
parents: 6966
diff changeset
5366
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5367 *ph = ho;
8024
ef6a3a99a81a Reworked multi headers to use linked lists.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8023
diff changeset
5368 ho->next = NULL;
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5369
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5370 return NGX_OK;
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5371 }
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5372
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5373
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5374 static ngx_int_t
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5375 ngx_http_upstream_copy_content_type(ngx_http_request_t *r, ngx_table_elt_t *h,
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5376 ngx_uint_t offset)
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5377 {
657
400711951595 nginx-0.3.50-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 653
diff changeset
5378 u_char *p, *last;
400711951595 nginx-0.3.50-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 653
diff changeset
5379
400711951595 nginx-0.3.50-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 653
diff changeset
5380 r->headers_out.content_type_len = h->value.len;
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5381 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
5382 r->headers_out.content_type_lowcase = NULL;
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5383
657
400711951595 nginx-0.3.50-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 653
diff changeset
5384 for (p = h->value.data; *p; p++) {
400711951595 nginx-0.3.50-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 653
diff changeset
5385
400711951595 nginx-0.3.50-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 653
diff changeset
5386 if (*p != ';') {
400711951595 nginx-0.3.50-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 653
diff changeset
5387 continue;
400711951595 nginx-0.3.50-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 653
diff changeset
5388 }
400711951595 nginx-0.3.50-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 653
diff changeset
5389
400711951595 nginx-0.3.50-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 653
diff changeset
5390 last = p;
400711951595 nginx-0.3.50-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 653
diff changeset
5391
400711951595 nginx-0.3.50-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 653
diff changeset
5392 while (*++p == ' ') { /* void */ }
400711951595 nginx-0.3.50-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 653
diff changeset
5393
1968
3c540ad3021f fix segfault
Igor Sysoev <igor@sysoev.ru>
parents: 1959
diff changeset
5394 if (*p == '\0') {
3c540ad3021f fix segfault
Igor Sysoev <igor@sysoev.ru>
parents: 1959
diff changeset
5395 return NGX_OK;
3c540ad3021f fix segfault
Igor Sysoev <igor@sysoev.ru>
parents: 1959
diff changeset
5396 }
3c540ad3021f fix segfault
Igor Sysoev <igor@sysoev.ru>
parents: 1959
diff changeset
5397
1107
db7c468c447d ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents: 1098
diff changeset
5398 if (ngx_strncasecmp(p, (u_char *) "charset=", 8) != 0) {
657
400711951595 nginx-0.3.50-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 653
diff changeset
5399 continue;
400711951595 nginx-0.3.50-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 653
diff changeset
5400 }
400711951595 nginx-0.3.50-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 653
diff changeset
5401
400711951595 nginx-0.3.50-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 653
diff changeset
5402 p += 8;
400711951595 nginx-0.3.50-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 653
diff changeset
5403
400711951595 nginx-0.3.50-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 653
diff changeset
5404 r->headers_out.content_type_len = last - h->value.data;
400711951595 nginx-0.3.50-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 653
diff changeset
5405
2244
f5a9f35e8344 strip charset name quotes
Igor Sysoev <igor@sysoev.ru>
parents: 2184
diff changeset
5406 if (*p == '"') {
f5a9f35e8344 strip charset name quotes
Igor Sysoev <igor@sysoev.ru>
parents: 2184
diff changeset
5407 p++;
f5a9f35e8344 strip charset name quotes
Igor Sysoev <igor@sysoev.ru>
parents: 2184
diff changeset
5408 }
f5a9f35e8344 strip charset name quotes
Igor Sysoev <igor@sysoev.ru>
parents: 2184
diff changeset
5409
f5a9f35e8344 strip charset name quotes
Igor Sysoev <igor@sysoev.ru>
parents: 2184
diff changeset
5410 last = h->value.data + h->value.len;
f5a9f35e8344 strip charset name quotes
Igor Sysoev <igor@sysoev.ru>
parents: 2184
diff changeset
5411
f5a9f35e8344 strip charset name quotes
Igor Sysoev <igor@sysoev.ru>
parents: 2184
diff changeset
5412 if (*(last - 1) == '"') {
f5a9f35e8344 strip charset name quotes
Igor Sysoev <igor@sysoev.ru>
parents: 2184
diff changeset
5413 last--;
f5a9f35e8344 strip charset name quotes
Igor Sysoev <igor@sysoev.ru>
parents: 2184
diff changeset
5414 }
f5a9f35e8344 strip charset name quotes
Igor Sysoev <igor@sysoev.ru>
parents: 2184
diff changeset
5415
f5a9f35e8344 strip charset name quotes
Igor Sysoev <igor@sysoev.ru>
parents: 2184
diff changeset
5416 r->headers_out.charset.len = last - p;
657
400711951595 nginx-0.3.50-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 653
diff changeset
5417 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
5418
c6c42497106c fix segfault if upstream sends trailing ";" in "charset="
Igor Sysoev <igor@sysoev.ru>
parents: 1109
diff changeset
5419 return NGX_OK;
657
400711951595 nginx-0.3.50-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 653
diff changeset
5420 }
400711951595 nginx-0.3.50-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 653
diff changeset
5421
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5422 return NGX_OK;
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5423 }
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5424
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5425
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5426 static ngx_int_t
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
5427 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
5428 ngx_uint_t offset)
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
5429 {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
5430 ngx_table_elt_t *ho;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
5431
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
5432 ho = ngx_list_push(&r->headers_out.headers);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
5433 if (ho == NULL) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
5434 return NGX_ERROR;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
5435 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
5436
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
5437 *ho = *h;
8031
d26db4f82d7d All known output headers can be linked lists now.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8030
diff changeset
5438 ho->next = NULL;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
5439
3004
4121acaf7a04 fix handling "Last-Modified" and "Accept-Ranges" for upstream responses
Igor Sysoev <igor@sysoev.ru>
parents: 3003
diff changeset
5440 r->headers_out.last_modified = ho;
7093
acc2cddc7b45 Upstream: unconditional parsing of last_modified_time.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7077
diff changeset
5441 r->headers_out.last_modified_time =
5732
d0ce06cb9be1 Upstream: fixed cache revalidation with SSI.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5731
diff changeset
5442 r->upstream->headers_in.last_modified_time;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
5443
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
5444 return NGX_OK;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
5445 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
5446
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
5447
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
5448 static ngx_int_t
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5449 ngx_http_upstream_rewrite_location(ngx_http_request_t *r, ngx_table_elt_t *h,
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5450 ngx_uint_t offset)
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5451 {
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5452 ngx_int_t rc;
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5453 ngx_table_elt_t *ho;
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5454
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5455 ho = ngx_list_push(&r->headers_out.headers);
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5456 if (ho == NULL) {
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5457 return NGX_ERROR;
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5458 }
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5459
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5460 *ho = *h;
8031
d26db4f82d7d All known output headers can be linked lists now.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8030
diff changeset
5461 ho->next = NULL;
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5462
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5463 if (r->upstream->rewrite_redirect) {
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5464 rc = r->upstream->rewrite_redirect(r, ho, 0);
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5465
529
e5d7d0334fdb nginx-0.1.39-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 527
diff changeset
5466 if (rc == NGX_DECLINED) {
e5d7d0334fdb nginx-0.1.39-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 527
diff changeset
5467 return NGX_OK;
e5d7d0334fdb nginx-0.1.39-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 527
diff changeset
5468 }
e5d7d0334fdb nginx-0.1.39-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 527
diff changeset
5469
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5470 if (rc == NGX_OK) {
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5471 r->headers_out.location = ho;
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5472
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5473 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5474 "rewritten location: \"%V\"", &ho->value);
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5475 }
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5476
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5477 return rc;
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5478 }
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5479
1653
ea681a6a0c61 set r->headers_out.location for non-local redirects
Igor Sysoev <igor@sysoev.ru>
parents: 1640
diff changeset
5480 if (ho->value.data[0] != '/') {
ea681a6a0c61 set r->headers_out.location for non-local redirects
Igor Sysoev <igor@sysoev.ru>
parents: 1640
diff changeset
5481 r->headers_out.location = ho;
ea681a6a0c61 set r->headers_out.location for non-local redirects
Igor Sysoev <igor@sysoev.ru>
parents: 1640
diff changeset
5482 }
ea681a6a0c61 set r->headers_out.location for non-local redirects
Igor Sysoev <igor@sysoev.ru>
parents: 1640
diff changeset
5483
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5484 /*
6853
c85dfd99a2dd Fixed missing "Location" field with some relative redirects.
Ruslan Ermilov <ru@nginx.com>
parents: 6799
diff changeset
5485 * 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
5486 * relative redirects in ngx_http_header_filter()
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5487 */
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5488
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5489 return NGX_OK;
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5490 }
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5491
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5492
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5493 static ngx_int_t
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5494 ngx_http_upstream_rewrite_refresh(ngx_http_request_t *r, ngx_table_elt_t *h,
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5495 ngx_uint_t offset)
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5496 {
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5497 u_char *p;
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5498 ngx_int_t rc;
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5499 ngx_table_elt_t *ho;
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5500
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5501 ho = ngx_list_push(&r->headers_out.headers);
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5502 if (ho == NULL) {
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5503 return NGX_ERROR;
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5504 }
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5505
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5506 *ho = *h;
8031
d26db4f82d7d All known output headers can be linked lists now.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8030
diff changeset
5507 ho->next = NULL;
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5508
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5509 if (r->upstream->rewrite_redirect) {
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5510
1549
099d8470e6c3 pass length clearly
Igor Sysoev <igor@sysoev.ru>
parents: 1543
diff changeset
5511 p = ngx_strcasestrn(ho->value.data, "url=", 4 - 1);
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5512
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5513 if (p) {
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5514 rc = r->upstream->rewrite_redirect(r, ho, p + 4 - ho->value.data);
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5515
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5516 } else {
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5517 return NGX_OK;
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5518 }
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5519
529
e5d7d0334fdb nginx-0.1.39-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 527
diff changeset
5520 if (rc == NGX_DECLINED) {
e5d7d0334fdb nginx-0.1.39-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 527
diff changeset
5521 return NGX_OK;
e5d7d0334fdb nginx-0.1.39-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 527
diff changeset
5522 }
e5d7d0334fdb nginx-0.1.39-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 527
diff changeset
5523
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5524 if (rc == NGX_OK) {
1654
e5c547a225bd r->headers_out.refresh
Igor Sysoev <igor@sysoev.ru>
parents: 1653
diff changeset
5525 r->headers_out.refresh = ho;
e5c547a225bd r->headers_out.refresh
Igor Sysoev <igor@sysoev.ru>
parents: 1653
diff changeset
5526
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5527 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5528 "rewritten refresh: \"%V\"", &ho->value);
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5529 }
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5530
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5531 return rc;
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5532 }
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5533
1654
e5c547a225bd r->headers_out.refresh
Igor Sysoev <igor@sysoev.ru>
parents: 1653
diff changeset
5534 r->headers_out.refresh = ho;
e5c547a225bd r->headers_out.refresh
Igor Sysoev <igor@sysoev.ru>
parents: 1653
diff changeset
5535
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5536 return NGX_OK;
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5537 }
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5538
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5539
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
5540 static ngx_int_t
4464
7bf3b68239a3 Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents: 4460
diff changeset
5541 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
5542 ngx_uint_t offset)
7bf3b68239a3 Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents: 4460
diff changeset
5543 {
4650
b38fea6f9a15 Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents: 4572
diff changeset
5544 ngx_int_t rc;
4464
7bf3b68239a3 Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents: 4460
diff changeset
5545 ngx_table_elt_t *ho;
7bf3b68239a3 Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents: 4460
diff changeset
5546
7bf3b68239a3 Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents: 4460
diff changeset
5547 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
5548 if (ho == NULL) {
7bf3b68239a3 Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents: 4460
diff changeset
5549 return NGX_ERROR;
7bf3b68239a3 Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents: 4460
diff changeset
5550 }
7bf3b68239a3 Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents: 4460
diff changeset
5551
7bf3b68239a3 Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents: 4460
diff changeset
5552 *ho = *h;
8031
d26db4f82d7d All known output headers can be linked lists now.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8030
diff changeset
5553 ho->next = NULL;
4464
7bf3b68239a3 Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents: 4460
diff changeset
5554
7bf3b68239a3 Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents: 4460
diff changeset
5555 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
5556 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
5557
b38fea6f9a15 Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents: 4572
diff changeset
5558 if (rc == NGX_DECLINED) {
b38fea6f9a15 Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents: 4572
diff changeset
5559 return NGX_OK;
b38fea6f9a15 Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents: 4572
diff changeset
5560 }
b38fea6f9a15 Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents: 4572
diff changeset
5561
b38fea6f9a15 Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents: 4572
diff changeset
5562 #if (NGX_DEBUG)
b38fea6f9a15 Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents: 4572
diff changeset
5563 if (rc == NGX_OK) {
b38fea6f9a15 Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents: 4572
diff changeset
5564 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
5565 "rewritten cookie: \"%V\"", &ho->value);
b38fea6f9a15 Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents: 4572
diff changeset
5566 }
b38fea6f9a15 Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents: 4572
diff changeset
5567 #endif
b38fea6f9a15 Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents: 4572
diff changeset
5568
b38fea6f9a15 Fixed returned value handling from the cookie rewrite handler.
Valentin Bartenev <vbart@nginx.com>
parents: 4572
diff changeset
5569 return rc;
4464
7bf3b68239a3 Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents: 4460
diff changeset
5570 }
7bf3b68239a3 Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents: 4460
diff changeset
5571
7bf3b68239a3 Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents: 4460
diff changeset
5572 return NGX_OK;
7bf3b68239a3 Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents: 4460
diff changeset
5573 }
7bf3b68239a3 Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents: 4460
diff changeset
5574
7bf3b68239a3 Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents: 4460
diff changeset
5575
7bf3b68239a3 Upstream: added callback hook for the "Set-Cookie" header.
Valentin Bartenev <vbart@nginx.com>
parents: 4460
diff changeset
5576 static ngx_int_t
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
5577 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
5578 ngx_table_elt_t *h, ngx_uint_t offset)
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
5579 {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
5580 ngx_table_elt_t *ho;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
5581
5874
2aff40b3dea2 Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5869
diff changeset
5582 if (r->upstream->conf->force_ranges) {
2aff40b3dea2 Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5869
diff changeset
5583 return NGX_OK;
2aff40b3dea2 Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5869
diff changeset
5584 }
2aff40b3dea2 Upstream: proxy_force_ranges and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 5869
diff changeset
5585
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
5586 #if (NGX_HTTP_CACHE)
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
5587
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
5588 if (r->cached) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
5589 r->allow_ranges = 1;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
5590 return NGX_OK;
5621
345e4fd4bb64 Range filter: single_range flag in request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5581
diff changeset
5591 }
345e4fd4bb64 Range filter: single_range flag in request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5581
diff changeset
5592
345e4fd4bb64 Range filter: single_range flag in request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5581
diff changeset
5593 if (r->upstream->cacheable) {
345e4fd4bb64 Range filter: single_range flag in request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5581
diff changeset
5594 r->allow_ranges = 1;
345e4fd4bb64 Range filter: single_range flag in request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5581
diff changeset
5595 r->single_range = 1;
345e4fd4bb64 Range filter: single_range flag in request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5581
diff changeset
5596 return NGX_OK;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
5597 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
5598
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
5599 #endif
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
5600
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
5601 ho = ngx_list_push(&r->headers_out.headers);
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
5602 if (ho == NULL) {
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
5603 return NGX_ERROR;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
5604 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
5605
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
5606 *ho = *h;
8031
d26db4f82d7d All known output headers can be linked lists now.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8030
diff changeset
5607 ho->next = NULL;
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
5608
3004
4121acaf7a04 fix handling "Last-Modified" and "Accept-Ranges" for upstream responses
Igor Sysoev <igor@sysoev.ru>
parents: 3003
diff changeset
5609 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
5610
2592
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
5611 return NGX_OK;
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
5612 }
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
5613
3a8a53c0c42f a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents: 2536
diff changeset
5614
487
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 485
diff changeset
5615 static ngx_int_t
573
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5616 ngx_http_upstream_add_variables(ngx_conf_t *cf)
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
5617 {
880
3b763d36e055 axe old % log format
Igor Sysoev <igor@sysoev.ru>
parents: 850
diff changeset
5618 ngx_http_variable_t *var, *v;
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
5619
573
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5620 for (v = ngx_http_upstream_vars; v->name.len; v++) {
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5621 var = ngx_http_add_variable(cf, &v->name, v->flags);
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5622 if (var == NULL) {
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5623 return NGX_ERROR;
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5624 }
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5625
637
e60fe4cf1d4e nginx-0.3.40-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 629
diff changeset
5626 var->get_handler = v->get_handler;
573
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5627 var->data = v->data;
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5628 }
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5629
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
5630 return NGX_OK;
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
5631 }
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5632
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
5633
573
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5634 static ngx_int_t
1181
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5635 ngx_http_upstream_addr_variable(ngx_http_request_t *r,
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5636 ngx_http_variable_value_t *v, uintptr_t data)
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5637 {
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5638 u_char *p;
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5639 size_t len;
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5640 ngx_uint_t i;
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5641 ngx_http_upstream_state_t *state;
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5642
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5643 v->valid = 1;
1565
4c43e25d11ea fix English grammar
Igor Sysoev <igor@sysoev.ru>
parents: 1559
diff changeset
5644 v->no_cacheable = 0;
1181
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5645 v->not_found = 0;
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5646
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5647 if (r->upstream_states == NULL || r->upstream_states->nelts == 0) {
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5648 v->not_found = 1;
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5649 return NGX_OK;
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5650 }
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5651
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5652 len = 0;
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5653 state = r->upstream_states->elts;
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5654
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5655 for (i = 0; i < r->upstream_states->nelts; i++) {
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5656 if (state[i].peer) {
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5657 len += state[i].peer->len + 2;
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5658
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5659 } else {
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5660 len += 3;
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5661 }
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5662 }
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5663
2049
2a92804f4109 *) back out r2040
Igor Sysoev <igor@sysoev.ru>
parents: 1973
diff changeset
5664 p = ngx_pnalloc(r->pool, len);
1181
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5665 if (p == NULL) {
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5666 return NGX_ERROR;
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5667 }
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5668
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5669 v->data = p;
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5670
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5671 i = 0;
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5672
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5673 for ( ;; ) {
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5674 if (state[i].peer) {
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5675 p = ngx_cpymem(p, state[i].peer->data, state[i].peer->len);
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5676 }
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5677
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5678 if (++i == r->upstream_states->nelts) {
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5679 break;
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5680 }
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5681
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5682 if (state[i].peer) {
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5683 *p++ = ',';
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5684 *p++ = ' ';
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5685
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5686 } else {
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5687 *p++ = ' ';
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5688 *p++ = ':';
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5689 *p++ = ' ';
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5690
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5691 if (++i == r->upstream_states->nelts) {
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5692 break;
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5693 }
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5694
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5695 continue;
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5696 }
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5697 }
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5698
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5699 v->len = p - v->data;
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5700
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5701 return NGX_OK;
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5702 }
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5703
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5704
ea5ecb1aae88 $upstream_addr
Igor Sysoev <igor@sysoev.ru>
parents: 1168
diff changeset
5705 static ngx_int_t
573
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5706 ngx_http_upstream_status_variable(ngx_http_request_t *r,
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5707 ngx_http_variable_value_t *v, uintptr_t data)
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5708 {
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5709 u_char *p;
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5710 size_t len;
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5711 ngx_uint_t i;
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5712 ngx_http_upstream_state_t *state;
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5713
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5714 v->valid = 1;
1565
4c43e25d11ea fix English grammar
Igor Sysoev <igor@sysoev.ru>
parents: 1559
diff changeset
5715 v->no_cacheable = 0;
573
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5716 v->not_found = 0;
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5717
1168
4d0d12446c3b store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents: 1166
diff changeset
5718 if (r->upstream_states == NULL || r->upstream_states->nelts == 0) {
573
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5719 v->not_found = 1;
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5720 return NGX_OK;
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5721 }
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5722
1168
4d0d12446c3b store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents: 1166
diff changeset
5723 len = r->upstream_states->nelts * (3 + 2);
573
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5724
2049
2a92804f4109 *) back out r2040
Igor Sysoev <igor@sysoev.ru>
parents: 1973
diff changeset
5725 p = ngx_pnalloc(r->pool, len);
573
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5726 if (p == NULL) {
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5727 return NGX_ERROR;
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5728 }
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5729
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5730 v->data = p;
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5731
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5732 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
5733 state = r->upstream_states->elts;
573
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5734
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5735 for ( ;; ) {
1168
4d0d12446c3b store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents: 1166
diff changeset
5736 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
5737 p = ngx_sprintf(p, "%ui", state[i].status);
573
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5738
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5739 } else {
1168
4d0d12446c3b store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents: 1166
diff changeset
5740 *p++ = '-';
573
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5741 }
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5742
1168
4d0d12446c3b store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents: 1166
diff changeset
5743 if (++i == r->upstream_states->nelts) {
573
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5744 break;
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5745 }
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5746
1168
4d0d12446c3b store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents: 1166
diff changeset
5747 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
5748 *p++ = ',';
4d0d12446c3b store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents: 1166
diff changeset
5749 *p++ = ' ';
4d0d12446c3b store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents: 1166
diff changeset
5750
4d0d12446c3b store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents: 1166
diff changeset
5751 } else {
4d0d12446c3b store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents: 1166
diff changeset
5752 *p++ = ' ';
4d0d12446c3b store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents: 1166
diff changeset
5753 *p++ = ':';
4d0d12446c3b store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents: 1166
diff changeset
5754 *p++ = ' ';
4d0d12446c3b store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents: 1166
diff changeset
5755
4d0d12446c3b store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents: 1166
diff changeset
5756 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
5757 break;
4d0d12446c3b store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents: 1166
diff changeset
5758 }
4d0d12446c3b store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents: 1166
diff changeset
5759
4d0d12446c3b store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents: 1166
diff changeset
5760 continue;
4d0d12446c3b store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents: 1166
diff changeset
5761 }
573
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5762 }
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5763
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5764 v->len = p - v->data;
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5765
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5766 return NGX_OK;
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5767 }
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5768
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5769
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5770 static ngx_int_t
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5771 ngx_http_upstream_response_time_variable(ngx_http_request_t *r,
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5772 ngx_http_variable_value_t *v, uintptr_t data)
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5773 {
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5774 u_char *p;
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5775 size_t len;
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5776 ngx_uint_t i;
889
a9a7e4b1a72b the previous fix does not actually fix overflow
Igor Sysoev <igor@sysoev.ru>
parents: 888
diff changeset
5777 ngx_msec_int_t ms;
573
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5778 ngx_http_upstream_state_t *state;
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5779
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5780 v->valid = 1;
1565
4c43e25d11ea fix English grammar
Igor Sysoev <igor@sysoev.ru>
parents: 1559
diff changeset
5781 v->no_cacheable = 0;
573
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5782 v->not_found = 0;
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5783
1168
4d0d12446c3b store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents: 1166
diff changeset
5784 if (r->upstream_states == NULL || r->upstream_states->nelts == 0) {
573
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5785 v->not_found = 1;
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5786 return NGX_OK;
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5787 }
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5788
1168
4d0d12446c3b store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents: 1166
diff changeset
5789 len = r->upstream_states->nelts * (NGX_TIME_T_LEN + 4 + 2);
573
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5790
2049
2a92804f4109 *) back out r2040
Igor Sysoev <igor@sysoev.ru>
parents: 1973
diff changeset
5791 p = ngx_pnalloc(r->pool, len);
573
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5792 if (p == NULL) {
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5793 return NGX_ERROR;
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5794 }
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5795
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5796 v->data = p;
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5797
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5798 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
5799 state = r->upstream_states->elts;
573
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5800
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5801 for ( ;; ) {
7397
860d3907da1c Upstream: revised upstream response time variables.
Vladimir Homutov <vl@nginx.com>
parents: 7371
diff changeset
5802
860d3907da1c Upstream: revised upstream response time variables.
Vladimir Homutov <vl@nginx.com>
parents: 7371
diff changeset
5803 if (data == 1) {
860d3907da1c Upstream: revised upstream response time variables.
Vladimir Homutov <vl@nginx.com>
parents: 7371
diff changeset
5804 ms = state[i].header_time;
860d3907da1c Upstream: revised upstream response time variables.
Vladimir Homutov <vl@nginx.com>
parents: 7371
diff changeset
5805
860d3907da1c Upstream: revised upstream response time variables.
Vladimir Homutov <vl@nginx.com>
parents: 7371
diff changeset
5806 } else if (data == 2) {
860d3907da1c Upstream: revised upstream response time variables.
Vladimir Homutov <vl@nginx.com>
parents: 7371
diff changeset
5807 ms = state[i].connect_time;
860d3907da1c Upstream: revised upstream response time variables.
Vladimir Homutov <vl@nginx.com>
parents: 7371
diff changeset
5808
860d3907da1c Upstream: revised upstream response time variables.
Vladimir Homutov <vl@nginx.com>
parents: 7371
diff changeset
5809 } else {
860d3907da1c Upstream: revised upstream response time variables.
Vladimir Homutov <vl@nginx.com>
parents: 7371
diff changeset
5810 ms = state[i].response_time;
860d3907da1c Upstream: revised upstream response time variables.
Vladimir Homutov <vl@nginx.com>
parents: 7371
diff changeset
5811 }
860d3907da1c Upstream: revised upstream response time variables.
Vladimir Homutov <vl@nginx.com>
parents: 7371
diff changeset
5812
860d3907da1c Upstream: revised upstream response time variables.
Vladimir Homutov <vl@nginx.com>
parents: 7371
diff changeset
5813 if (ms != -1) {
3515
76d252724db5 use ngx_min() and ngx_max()
Igor Sysoev <igor@sysoev.ru>
parents: 3514
diff changeset
5814 ms = ngx_max(ms, 0);
5368
cd46297325bd Upstream: fixed $upstream_response_time format specifiers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5353
diff changeset
5815 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
5816
4d0d12446c3b store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents: 1166
diff changeset
5817 } else {
4d0d12446c3b store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents: 1166
diff changeset
5818 *p++ = '-';
573
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5819 }
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5820
1168
4d0d12446c3b store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents: 1166
diff changeset
5821 if (++i == r->upstream_states->nelts) {
573
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5822 break;
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5823 }
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5824
1168
4d0d12446c3b store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents: 1166
diff changeset
5825 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
5826 *p++ = ',';
4d0d12446c3b store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents: 1166
diff changeset
5827 *p++ = ' ';
4d0d12446c3b store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents: 1166
diff changeset
5828
4d0d12446c3b store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents: 1166
diff changeset
5829 } else {
4d0d12446c3b store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents: 1166
diff changeset
5830 *p++ = ' ';
4d0d12446c3b store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents: 1166
diff changeset
5831 *p++ = ':';
4d0d12446c3b store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents: 1166
diff changeset
5832 *p++ = ' ';
4d0d12446c3b store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents: 1166
diff changeset
5833
4d0d12446c3b store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents: 1166
diff changeset
5834 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
5835 break;
4d0d12446c3b store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents: 1166
diff changeset
5836 }
4d0d12446c3b store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents: 1166
diff changeset
5837
4d0d12446c3b store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents: 1166
diff changeset
5838 continue;
4d0d12446c3b store the upstream states before X-Accel-Redirect to a next upstream
Igor Sysoev <igor@sysoev.ru>
parents: 1166
diff changeset
5839 }
573
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5840 }
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5841
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5842 v->len = p - v->data;
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5843
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5844 return NGX_OK;
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5845 }
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5846
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
5847
2402
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
5848 static ngx_int_t
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
5849 ngx_http_upstream_response_length_variable(ngx_http_request_t *r,
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
5850 ngx_http_variable_value_t *v, uintptr_t data)
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
5851 {
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
5852 u_char *p;
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
5853 size_t len;
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
5854 ngx_uint_t i;
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
5855 ngx_http_upstream_state_t *state;
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
5856
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
5857 v->valid = 1;
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
5858 v->no_cacheable = 0;
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
5859 v->not_found = 0;
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
5860
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
5861 if (r->upstream_states == NULL || r->upstream_states->nelts == 0) {
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
5862 v->not_found = 1;
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
5863 return NGX_OK;
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
5864 }
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
5865
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
5866 len = r->upstream_states->nelts * (NGX_OFF_T_LEN + 2);
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
5867
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
5868 p = ngx_pnalloc(r->pool, len);
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
5869 if (p == NULL) {
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
5870 return NGX_ERROR;
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
5871 }
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
5872
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
5873 v->data = p;
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
5874
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
5875 i = 0;
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
5876 state = r->upstream_states->elts;
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
5877
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
5878 for ( ;; ) {
6654
c131f20c9562 Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents: 6594
diff changeset
5879
c131f20c9562 Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents: 6594
diff changeset
5880 if (data == 1) {
c131f20c9562 Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents: 6594
diff changeset
5881 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
5882
7429
e573d74299a0 Upstream: implemented $upstream_bytes_sent.
Ruslan Ermilov <ru@nginx.com>
parents: 7397
diff changeset
5883 } else if (data == 2) {
e573d74299a0 Upstream: implemented $upstream_bytes_sent.
Ruslan Ermilov <ru@nginx.com>
parents: 7397
diff changeset
5884 p = ngx_sprintf(p, "%O", state[i].bytes_sent);
e573d74299a0 Upstream: implemented $upstream_bytes_sent.
Ruslan Ermilov <ru@nginx.com>
parents: 7397
diff changeset
5885
6654
c131f20c9562 Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents: 6594
diff changeset
5886 } else {
c131f20c9562 Upstream: the $upstream_bytes_received variable.
Vladimir Homutov <vl@nginx.com>
parents: 6594
diff changeset
5887 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
5888 }
2402
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
5889
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
5890 if (++i == r->upstream_states->nelts) {
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
5891 break;
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
5892 }
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
5893
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
5894 if (state[i].peer) {
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
5895 *p++ = ',';
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
5896 *p++ = ' ';
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
5897
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
5898 } else {
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
5899 *p++ = ' ';
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
5900 *p++ = ':';
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
5901 *p++ = ' ';
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
5902
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
5903 if (++i == r->upstream_states->nelts) {
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
5904 break;
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
5905 }
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
5906
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
5907 continue;
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
5908 }
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
5909 }
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
5910
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
5911 v->len = p - v->data;
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
5912
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
5913 return NGX_OK;
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
5914 }
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
5915
cd6a1abe11a7 $upstream_response_length
Igor Sysoev <igor@sysoev.ru>
parents: 2394
diff changeset
5916
6899
d2b2ff157da5 Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6876
diff changeset
5917 static ngx_int_t
1162
f59d15404269 $upstream_http_... variables
Igor Sysoev <igor@sysoev.ru>
parents: 1153
diff changeset
5918 ngx_http_upstream_header_variable(ngx_http_request_t *r,
f59d15404269 $upstream_http_... variables
Igor Sysoev <igor@sysoev.ru>
parents: 1153
diff changeset
5919 ngx_http_variable_value_t *v, uintptr_t data)
f59d15404269 $upstream_http_... variables
Igor Sysoev <igor@sysoev.ru>
parents: 1153
diff changeset
5920 {
f59d15404269 $upstream_http_... variables
Igor Sysoev <igor@sysoev.ru>
parents: 1153
diff changeset
5921 if (r->upstream == NULL) {
f59d15404269 $upstream_http_... variables
Igor Sysoev <igor@sysoev.ru>
parents: 1153
diff changeset
5922 v->not_found = 1;
f59d15404269 $upstream_http_... variables
Igor Sysoev <igor@sysoev.ru>
parents: 1153
diff changeset
5923 return NGX_OK;
f59d15404269 $upstream_http_... variables
Igor Sysoev <igor@sysoev.ru>
parents: 1153
diff changeset
5924 }
f59d15404269 $upstream_http_... variables
Igor Sysoev <igor@sysoev.ru>
parents: 1153
diff changeset
5925
8023
08b3ea81ff5f Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents: 7975
diff changeset
5926 return ngx_http_variable_unknown_header(r, v, (ngx_str_t *) data,
1162
f59d15404269 $upstream_http_... variables
Igor Sysoev <igor@sysoev.ru>
parents: 1153
diff changeset
5927 &r->upstream->headers_in.headers.part,
f59d15404269 $upstream_http_... variables
Igor Sysoev <igor@sysoev.ru>
parents: 1153
diff changeset
5928 sizeof("upstream_http_") - 1);
f59d15404269 $upstream_http_... variables
Igor Sysoev <igor@sysoev.ru>
parents: 1153
diff changeset
5929 }
f59d15404269 $upstream_http_... variables
Igor Sysoev <igor@sysoev.ru>
parents: 1153
diff changeset
5930
f59d15404269 $upstream_http_... variables
Igor Sysoev <igor@sysoev.ru>
parents: 1153
diff changeset
5931
6899
d2b2ff157da5 Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 6876
diff changeset
5932 static ngx_int_t
7230
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
5933 ngx_http_upstream_trailer_variable(ngx_http_request_t *r,
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
5934 ngx_http_variable_value_t *v, uintptr_t data)
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
5935 {
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
5936 if (r->upstream == NULL) {
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
5937 v->not_found = 1;
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
5938 return NGX_OK;
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
5939 }
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
5940
8023
08b3ea81ff5f Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents: 7975
diff changeset
5941 return ngx_http_variable_unknown_header(r, v, (ngx_str_t *) data,
7230
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
5942 &r->upstream->headers_in.trailers.part,
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
5943 sizeof("upstream_trailer_") - 1);
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
5944 }
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
5945
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
5946
098bbd076a2d Upstream: trailers support, u->conf->pass_trailers flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7220
diff changeset
5947 static ngx_int_t
5677
3a48775f1535 Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents: 5667
diff changeset
5948 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
5949 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
5950 {
3a48775f1535 Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents: 5667
diff changeset
5951 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
5952
3a48775f1535 Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents: 5667
diff changeset
5953 ngx_str_t cookie, s;
3a48775f1535 Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents: 5667
diff changeset
5954
3a48775f1535 Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents: 5667
diff changeset
5955 if (r->upstream == NULL) {
3a48775f1535 Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents: 5667
diff changeset
5956 v->not_found = 1;
3a48775f1535 Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents: 5667
diff changeset
5957 return NGX_OK;
3a48775f1535 Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents: 5667
diff changeset
5958 }
3a48775f1535 Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents: 5667
diff changeset
5959
3a48775f1535 Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents: 5667
diff changeset
5960 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
5961 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
5962
8024
ef6a3a99a81a Reworked multi headers to use linked lists.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8023
diff changeset
5963 if (ngx_http_parse_set_cookie_lines(r, r->upstream->headers_in.set_cookie,
5677
3a48775f1535 Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents: 5667
diff changeset
5964 &s, &cookie)
8024
ef6a3a99a81a Reworked multi headers to use linked lists.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8023
diff changeset
5965 == NULL)
5677
3a48775f1535 Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents: 5667
diff changeset
5966 {
3a48775f1535 Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents: 5667
diff changeset
5967 v->not_found = 1;
3a48775f1535 Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents: 5667
diff changeset
5968 return NGX_OK;
3a48775f1535 Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents: 5667
diff changeset
5969 }
3a48775f1535 Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents: 5667
diff changeset
5970
3a48775f1535 Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents: 5667
diff changeset
5971 v->len = cookie.len;
3a48775f1535 Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents: 5667
diff changeset
5972 v->valid = 1;
3a48775f1535 Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents: 5667
diff changeset
5973 v->no_cacheable = 0;
3a48775f1535 Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents: 5667
diff changeset
5974 v->not_found = 0;
3a48775f1535 Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents: 5667
diff changeset
5975 v->data = cookie.data;
3a48775f1535 Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents: 5667
diff changeset
5976
3a48775f1535 Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents: 5667
diff changeset
5977 return NGX_OK;
3a48775f1535 Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents: 5667
diff changeset
5978 }
3a48775f1535 Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents: 5667
diff changeset
5979
3a48775f1535 Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents: 5667
diff changeset
5980
2952
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2949
diff changeset
5981 #if (NGX_HTTP_CACHE)
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2949
diff changeset
5982
6923
fbdaad9b0e7b Added missing "static" specifiers found by gcc -Wtraditional.
Ruslan Ermilov <ru@nginx.com>
parents: 6922
diff changeset
5983 static ngx_int_t
2952
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2949
diff changeset
5984 ngx_http_upstream_cache_status(ngx_http_request_t *r,
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2949
diff changeset
5985 ngx_http_variable_value_t *v, uintptr_t data)
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2949
diff changeset
5986 {
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2949
diff changeset
5987 ngx_uint_t n;
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2949
diff changeset
5988
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2949
diff changeset
5989 if (r->upstream == NULL || r->upstream->cache_status == 0) {
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2949
diff changeset
5990 v->not_found = 1;
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2949
diff changeset
5991 return NGX_OK;
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2949
diff changeset
5992 }
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2949
diff changeset
5993
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2949
diff changeset
5994 n = r->upstream->cache_status - 1;
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2949
diff changeset
5995
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2949
diff changeset
5996 v->valid = 1;
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2949
diff changeset
5997 v->no_cacheable = 0;
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2949
diff changeset
5998 v->not_found = 0;
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2949
diff changeset
5999 v->len = ngx_http_cache_status[n].len;
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2949
diff changeset
6000 v->data = ngx_http_cache_status[n].data;
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2949
diff changeset
6001
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2949
diff changeset
6002 return NGX_OK;
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2949
diff changeset
6003 }
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2949
diff changeset
6004
5441
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
6005
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
6006 static ngx_int_t
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
6007 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
6008 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
6009 {
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
6010 u_char *p;
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
6011
5453
b7b8e2fa7ebd Fixed null pointer dereference with $upstream_cache_last_modified.
Ruslan Ermilov <ru@nginx.com>
parents: 5441
diff changeset
6012 if (r->upstream == NULL
b7b8e2fa7ebd Fixed null pointer dereference with $upstream_cache_last_modified.
Ruslan Ermilov <ru@nginx.com>
parents: 5441
diff changeset
6013 || !r->upstream->conf->cache_revalidate
5441
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
6014 || r->upstream->cache_status != NGX_HTTP_CACHE_EXPIRED
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
6015 || r->cache->last_modified == -1)
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
6016 {
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
6017 v->not_found = 1;
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
6018 return NGX_OK;
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
6019 }
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
6020
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
6021 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
6022 if (p == NULL) {
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
6023 return NGX_ERROR;
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
6024 }
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
6025
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
6026 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
6027 v->valid = 1;
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
6028 v->no_cacheable = 0;
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
6029 v->not_found = 0;
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
6030 v->data = p;
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
6031
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
6032 return NGX_OK;
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
6033 }
43ccaf8e8728 Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5410
diff changeset
6034
5738
c95d7882dfc9 Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5737
diff changeset
6035
c95d7882dfc9 Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5737
diff changeset
6036 static ngx_int_t
c95d7882dfc9 Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5737
diff changeset
6037 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
6038 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
6039 {
c95d7882dfc9 Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5737
diff changeset
6040 if (r->upstream == NULL
c95d7882dfc9 Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5737
diff changeset
6041 || !r->upstream->conf->cache_revalidate
c95d7882dfc9 Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5737
diff changeset
6042 || 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
6043 || r->cache->etag.len == 0)
c95d7882dfc9 Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5737
diff changeset
6044 {
c95d7882dfc9 Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5737
diff changeset
6045 v->not_found = 1;
c95d7882dfc9 Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5737
diff changeset
6046 return NGX_OK;
c95d7882dfc9 Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5737
diff changeset
6047 }
c95d7882dfc9 Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5737
diff changeset
6048
c95d7882dfc9 Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5737
diff changeset
6049 v->valid = 1;
c95d7882dfc9 Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5737
diff changeset
6050 v->no_cacheable = 0;
c95d7882dfc9 Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5737
diff changeset
6051 v->not_found = 0;
c95d7882dfc9 Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5737
diff changeset
6052 v->len = r->cache->etag.len;
c95d7882dfc9 Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5737
diff changeset
6053 v->data = r->cache->etag.data;
c95d7882dfc9 Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5737
diff changeset
6054
c95d7882dfc9 Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5737
diff changeset
6055 return NGX_OK;
c95d7882dfc9 Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5737
diff changeset
6056 }
c95d7882dfc9 Upstream: cache revalidation using If-None-Match.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5737
diff changeset
6057
2952
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2949
diff changeset
6058 #endif
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2949
diff changeset
6059
0998606fbfd4 $upstream_cache_status
Igor Sysoev <igor@sysoev.ru>
parents: 2949
diff changeset
6060
651
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6061 static char *
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6062 ngx_http_upstream(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6063 {
884
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6064 char *rv;
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6065 void *mconf;
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6066 ngx_str_t *value;
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6067 ngx_url_t u;
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6068 ngx_uint_t m;
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6069 ngx_conf_t pcf;
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6070 ngx_http_module_t *module;
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6071 ngx_http_conf_ctx_t *ctx, *http_ctx;
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6072 ngx_http_upstream_srv_conf_t *uscf;
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6073
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6074 ngx_memzero(&u, sizeof(ngx_url_t));
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6075
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6076 value = cf->args->elts;
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6077 u.host = value[1];
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6078 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
6079 u.no_port = 1;
884
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6080
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6081 uscf = ngx_http_upstream_add(cf, &u, NGX_HTTP_UPSTREAM_CREATE
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6082 |NGX_HTTP_UPSTREAM_WEIGHT
6705
29bf0dbc0a77 Upstream: max_conns.
Ruslan Ermilov <ru@nginx.com>
parents: 6703
diff changeset
6083 |NGX_HTTP_UPSTREAM_MAX_CONNS
884
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6084 |NGX_HTTP_UPSTREAM_MAX_FAILS
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6085 |NGX_HTTP_UPSTREAM_FAIL_TIMEOUT
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6086 |NGX_HTTP_UPSTREAM_DOWN
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6087 |NGX_HTTP_UPSTREAM_BACKUP);
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6088 if (uscf == NULL) {
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6089 return NGX_CONF_ERROR;
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6090 }
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6091
651
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6092
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6093 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t));
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6094 if (ctx == NULL) {
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6095 return NGX_CONF_ERROR;
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6096 }
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6097
884
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6098 http_ctx = cf->ctx;
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6099 ctx->main_conf = http_ctx->main_conf;
651
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6100
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6101 /* the upstream{}'s srv_conf */
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6102
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6103 ctx->srv_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6104 if (ctx->srv_conf == NULL) {
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6105 return NGX_CONF_ERROR;
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6106 }
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6107
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6108 ctx->srv_conf[ngx_http_upstream_module.ctx_index] = uscf;
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6109
884
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6110 uscf->srv_conf = ctx->srv_conf;
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6111
651
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6112
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6113 /* the upstream{}'s loc_conf */
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6114
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6115 ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6116 if (ctx->loc_conf == NULL) {
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6117 return NGX_CONF_ERROR;
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6118 }
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6119
6379
cf5e822cf470 Dynamic modules: changed ngx_modules to cycle->modules.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6334
diff changeset
6120 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
6121 if (cf->cycle->modules[m]->type != NGX_HTTP_MODULE) {
651
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6122 continue;
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6123 }
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6124
6379
cf5e822cf470 Dynamic modules: changed ngx_modules to cycle->modules.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6334
diff changeset
6125 module = cf->cycle->modules[m]->ctx;
651
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6126
884
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6127 if (module->create_srv_conf) {
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6128 mconf = module->create_srv_conf(cf);
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6129 if (mconf == NULL) {
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6130 return NGX_CONF_ERROR;
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6131 }
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6132
6379
cf5e822cf470 Dynamic modules: changed ngx_modules to cycle->modules.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6334
diff changeset
6133 ctx->srv_conf[cf->cycle->modules[m]->ctx_index] = mconf;
884
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6134 }
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6135
651
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6136 if (module->create_loc_conf) {
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6137 mconf = module->create_loc_conf(cf);
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6138 if (mconf == NULL) {
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6139 return NGX_CONF_ERROR;
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6140 }
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6141
6379
cf5e822cf470 Dynamic modules: changed ngx_modules to cycle->modules.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6334
diff changeset
6142 ctx->loc_conf[cf->cycle->modules[m]->ctx_index] = mconf;
651
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6143 }
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6144 }
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6145
5728
63d7d69d0fe4 Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents: 5717
diff changeset
6146 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
6147 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
6148 if (uscf->servers == NULL) {
63d7d69d0fe4 Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents: 5717
diff changeset
6149 return NGX_CONF_ERROR;
63d7d69d0fe4 Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents: 5717
diff changeset
6150 }
63d7d69d0fe4 Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents: 5717
diff changeset
6151
651
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6152
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6153 /* parse inside upstream{} */
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6154
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6155 pcf = *cf;
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6156 cf->ctx = ctx;
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6157 cf->cmd_type = NGX_HTTP_UPS_CONF;
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6158
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6159 rv = ngx_conf_parse(cf, NULL);
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6160
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6161 *cf = pcf;
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6162
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6163 if (rv != NGX_CONF_OK) {
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6164 return rv;
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6165 }
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6166
5728
63d7d69d0fe4 Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents: 5717
diff changeset
6167 if (uscf->servers->nelts == 0) {
651
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6168 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6169 "no servers are inside upstream");
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6170 return NGX_CONF_ERROR;
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6171 }
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6172
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6173 return rv;
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6174 }
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6175
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6176
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6177 static char *
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6178 ngx_http_upstream_server(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6179 {
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6180 ngx_http_upstream_srv_conf_t *uscf = conf;
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6181
884
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6182 time_t fail_timeout;
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6183 ngx_str_t *value, s;
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6184 ngx_url_t u;
6705
29bf0dbc0a77 Upstream: max_conns.
Ruslan Ermilov <ru@nginx.com>
parents: 6703
diff changeset
6185 ngx_int_t weight, max_conns, max_fails;
884
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6186 ngx_uint_t i;
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6187 ngx_http_upstream_server_t *us;
651
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6188
884
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6189 us = ngx_array_push(uscf->servers);
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6190 if (us == NULL) {
651
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6191 return NGX_CONF_ERROR;
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6192 }
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6193
884
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6194 ngx_memzero(us, sizeof(ngx_http_upstream_server_t));
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6195
651
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6196 value = cf->args->elts;
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6197
663
6d5c1535bb9d nginx-0.3.53-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 659
diff changeset
6198 weight = 1;
6705
29bf0dbc0a77 Upstream: max_conns.
Ruslan Ermilov <ru@nginx.com>
parents: 6703
diff changeset
6199 max_conns = 0;
884
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6200 max_fails = 1;
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6201 fail_timeout = 10;
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6202
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6203 for (i = 2; i < cf->args->nelts; i++) {
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6204
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6205 if (ngx_strncmp(value[i].data, "weight=", 7) == 0) {
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6206
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6207 if (!(uscf->flags & NGX_HTTP_UPSTREAM_WEIGHT)) {
5818
fe8bafab5b49 Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents: 5774
diff changeset
6208 goto not_supported;
884
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6209 }
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6210
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6211 weight = ngx_atoi(&value[i].data[7], value[i].len - 7);
663
6d5c1535bb9d nginx-0.3.53-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 659
diff changeset
6212
6d5c1535bb9d nginx-0.3.53-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 659
diff changeset
6213 if (weight == NGX_ERROR || weight == 0) {
6d5c1535bb9d nginx-0.3.53-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 659
diff changeset
6214 goto invalid;
6d5c1535bb9d nginx-0.3.53-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 659
diff changeset
6215 }
6d5c1535bb9d nginx-0.3.53-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 659
diff changeset
6216
884
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6217 continue;
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6218 }
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6219
6705
29bf0dbc0a77 Upstream: max_conns.
Ruslan Ermilov <ru@nginx.com>
parents: 6703
diff changeset
6220 if (ngx_strncmp(value[i].data, "max_conns=", 10) == 0) {
29bf0dbc0a77 Upstream: max_conns.
Ruslan Ermilov <ru@nginx.com>
parents: 6703
diff changeset
6221
29bf0dbc0a77 Upstream: max_conns.
Ruslan Ermilov <ru@nginx.com>
parents: 6703
diff changeset
6222 if (!(uscf->flags & NGX_HTTP_UPSTREAM_MAX_CONNS)) {
29bf0dbc0a77 Upstream: max_conns.
Ruslan Ermilov <ru@nginx.com>
parents: 6703
diff changeset
6223 goto not_supported;
29bf0dbc0a77 Upstream: max_conns.
Ruslan Ermilov <ru@nginx.com>
parents: 6703
diff changeset
6224 }
29bf0dbc0a77 Upstream: max_conns.
Ruslan Ermilov <ru@nginx.com>
parents: 6703
diff changeset
6225
29bf0dbc0a77 Upstream: max_conns.
Ruslan Ermilov <ru@nginx.com>
parents: 6703
diff changeset
6226 max_conns = ngx_atoi(&value[i].data[10], value[i].len - 10);
29bf0dbc0a77 Upstream: max_conns.
Ruslan Ermilov <ru@nginx.com>
parents: 6703
diff changeset
6227
29bf0dbc0a77 Upstream: max_conns.
Ruslan Ermilov <ru@nginx.com>
parents: 6703
diff changeset
6228 if (max_conns == NGX_ERROR) {
29bf0dbc0a77 Upstream: max_conns.
Ruslan Ermilov <ru@nginx.com>
parents: 6703
diff changeset
6229 goto invalid;
29bf0dbc0a77 Upstream: max_conns.
Ruslan Ermilov <ru@nginx.com>
parents: 6703
diff changeset
6230 }
29bf0dbc0a77 Upstream: max_conns.
Ruslan Ermilov <ru@nginx.com>
parents: 6703
diff changeset
6231
29bf0dbc0a77 Upstream: max_conns.
Ruslan Ermilov <ru@nginx.com>
parents: 6703
diff changeset
6232 continue;
29bf0dbc0a77 Upstream: max_conns.
Ruslan Ermilov <ru@nginx.com>
parents: 6703
diff changeset
6233 }
29bf0dbc0a77 Upstream: max_conns.
Ruslan Ermilov <ru@nginx.com>
parents: 6703
diff changeset
6234
884
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6235 if (ngx_strncmp(value[i].data, "max_fails=", 10) == 0) {
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6236
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6237 if (!(uscf->flags & NGX_HTTP_UPSTREAM_MAX_FAILS)) {
5818
fe8bafab5b49 Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents: 5774
diff changeset
6238 goto not_supported;
884
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6239 }
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6240
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6241 max_fails = ngx_atoi(&value[i].data[10], value[i].len - 10);
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6242
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6243 if (max_fails == NGX_ERROR) {
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6244 goto invalid;
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6245 }
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6246
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6247 continue;
663
6d5c1535bb9d nginx-0.3.53-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 659
diff changeset
6248 }
884
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6249
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6250 if (ngx_strncmp(value[i].data, "fail_timeout=", 13) == 0) {
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6251
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6252 if (!(uscf->flags & NGX_HTTP_UPSTREAM_FAIL_TIMEOUT)) {
5818
fe8bafab5b49 Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents: 5774
diff changeset
6253 goto not_supported;
884
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6254 }
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6255
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6256 s.len = value[i].len - 13;
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6257 s.data = &value[i].data[13];
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6258
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6259 fail_timeout = ngx_parse_time(&s, 1);
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6260
4474
41f640a693de Time parsing cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4469
diff changeset
6261 if (fail_timeout == (time_t) NGX_ERROR) {
884
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6262 goto invalid;
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6263 }
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6264
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6265 continue;
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6266 }
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6267
5410
16b68c724438 Upstream: fixed "down" and "backup" parsing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5392
diff changeset
6268 if (ngx_strcmp(value[i].data, "backup") == 0) {
1378
0be898896d1a backup upstream servers
Igor Sysoev <igor@sysoev.ru>
parents: 1340
diff changeset
6269
0be898896d1a backup upstream servers
Igor Sysoev <igor@sysoev.ru>
parents: 1340
diff changeset
6270 if (!(uscf->flags & NGX_HTTP_UPSTREAM_BACKUP)) {
5818
fe8bafab5b49 Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents: 5774
diff changeset
6271 goto not_supported;
1378
0be898896d1a backup upstream servers
Igor Sysoev <igor@sysoev.ru>
parents: 1340
diff changeset
6272 }
0be898896d1a backup upstream servers
Igor Sysoev <igor@sysoev.ru>
parents: 1340
diff changeset
6273
0be898896d1a backup upstream servers
Igor Sysoev <igor@sysoev.ru>
parents: 1340
diff changeset
6274 us->backup = 1;
0be898896d1a backup upstream servers
Igor Sysoev <igor@sysoev.ru>
parents: 1340
diff changeset
6275
0be898896d1a backup upstream servers
Igor Sysoev <igor@sysoev.ru>
parents: 1340
diff changeset
6276 continue;
0be898896d1a backup upstream servers
Igor Sysoev <igor@sysoev.ru>
parents: 1340
diff changeset
6277 }
0be898896d1a backup upstream servers
Igor Sysoev <igor@sysoev.ru>
parents: 1340
diff changeset
6278
5410
16b68c724438 Upstream: fixed "down" and "backup" parsing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5392
diff changeset
6279 if (ngx_strcmp(value[i].data, "down") == 0) {
884
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6280
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6281 if (!(uscf->flags & NGX_HTTP_UPSTREAM_DOWN)) {
5818
fe8bafab5b49 Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents: 5774
diff changeset
6282 goto not_supported;
884
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6283 }
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6284
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6285 us->down = 1;
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6286
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6287 continue;
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6288 }
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6289
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6290 goto invalid;
663
6d5c1535bb9d nginx-0.3.53-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 659
diff changeset
6291 }
6d5c1535bb9d nginx-0.3.53-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 659
diff changeset
6292
5728
63d7d69d0fe4 Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents: 5717
diff changeset
6293 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
6294
63d7d69d0fe4 Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents: 5717
diff changeset
6295 u.url = value[1];
63d7d69d0fe4 Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents: 5717
diff changeset
6296 u.default_port = 80;
63d7d69d0fe4 Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents: 5717
diff changeset
6297
63d7d69d0fe4 Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents: 5717
diff changeset
6298 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
6299 if (u.err) {
63d7d69d0fe4 Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents: 5717
diff changeset
6300 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
6301 "%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
6302 }
63d7d69d0fe4 Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents: 5717
diff changeset
6303
63d7d69d0fe4 Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents: 5717
diff changeset
6304 return NGX_CONF_ERROR;
63d7d69d0fe4 Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents: 5717
diff changeset
6305 }
63d7d69d0fe4 Upstream: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents: 5717
diff changeset
6306
5717
efc84a5723b3 Upstream: generic hash module.
Roman Arutyunyan <arut@nginx.com>
parents: 5682
diff changeset
6307 us->name = u.url;
884
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6308 us->addrs = u.addrs;
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6309 us->naddrs = u.naddrs;
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6310 us->weight = weight;
6705
29bf0dbc0a77 Upstream: max_conns.
Ruslan Ermilov <ru@nginx.com>
parents: 6703
diff changeset
6311 us->max_conns = max_conns;
884
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6312 us->max_fails = max_fails;
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6313 us->fail_timeout = fail_timeout;
651
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6314
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6315 return NGX_CONF_OK;
663
6d5c1535bb9d nginx-0.3.53-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 659
diff changeset
6316
6d5c1535bb9d nginx-0.3.53-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 659
diff changeset
6317 invalid:
6d5c1535bb9d nginx-0.3.53-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 659
diff changeset
6318
884
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6319 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6320 "invalid parameter \"%V\"", &value[i]);
663
6d5c1535bb9d nginx-0.3.53-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 659
diff changeset
6321
6d5c1535bb9d nginx-0.3.53-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 659
diff changeset
6322 return NGX_CONF_ERROR;
5818
fe8bafab5b49 Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents: 5774
diff changeset
6323
fe8bafab5b49 Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents: 5774
diff changeset
6324 not_supported:
fe8bafab5b49 Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents: 5774
diff changeset
6325
fe8bafab5b49 Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents: 5774
diff changeset
6326 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
fe8bafab5b49 Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents: 5774
diff changeset
6327 "balancing method does not support parameter \"%V\"",
fe8bafab5b49 Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents: 5774
diff changeset
6328 &value[i]);
fe8bafab5b49 Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents: 5774
diff changeset
6329
fe8bafab5b49 Upstream: improved configuration parser diagnostics.
Ruslan Ermilov <ru@nginx.com>
parents: 5774
diff changeset
6330 return NGX_CONF_ERROR;
651
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6331 }
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6332
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6333
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6334 ngx_http_upstream_srv_conf_t *
884
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6335 ngx_http_upstream_add(ngx_conf_t *cf, ngx_url_t *u, ngx_uint_t flags)
651
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6336 {
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6337 ngx_uint_t i;
884
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6338 ngx_http_upstream_server_t *us;
651
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6339 ngx_http_upstream_srv_conf_t *uscf, **uscfp;
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6340 ngx_http_upstream_main_conf_t *umcf;
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6341
884
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6342 if (!(flags & NGX_HTTP_UPSTREAM_CREATE)) {
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6343
1559
fe11e2a3946d use pool instead of ngx_conf_t
Igor Sysoev <igor@sysoev.ru>
parents: 1558
diff changeset
6344 if (ngx_parse_url(cf->pool, u) != NGX_OK) {
651
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6345 if (u->err) {
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6346 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6347 "%s in upstream \"%V\"", u->err, &u->url);
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6348 }
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6349
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6350 return NULL;
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6351 }
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6352 }
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6353
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6354 umcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_upstream_module);
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6355
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6356 uscfp = umcf->upstreams.elts;
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6357
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6358 for (i = 0; i < umcf->upstreams.nelts; i++) {
906
a0310ac2814f rewritten upstream
Igor Sysoev <igor@sysoev.ru>
parents: 901
diff changeset
6359
a0310ac2814f rewritten upstream
Igor Sysoev <igor@sysoev.ru>
parents: 901
diff changeset
6360 if (uscfp[i]->host.len != u->host.len
884
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6361 || ngx_strncasecmp(uscfp[i]->host.data, u->host.data, u->host.len)
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6362 != 0)
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6363 {
651
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6364 continue;
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6365 }
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6366
884
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6367 if ((flags & NGX_HTTP_UPSTREAM_CREATE)
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6368 && (uscfp[i]->flags & NGX_HTTP_UPSTREAM_CREATE))
651
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6369 {
884
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6370 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6371 "duplicate upstream \"%V\"", &u->host);
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6372 return NULL;
651
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6373 }
884
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6374
5005
c9059bd5445b Fixed "proxy_pass" with IP address and no port (ticket #276).
Ruslan Ermilov <ru@nginx.com>
parents: 4990
diff changeset
6375 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
6376 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
906
a0310ac2814f rewritten upstream
Igor Sysoev <igor@sysoev.ru>
parents: 901
diff changeset
6377 "upstream \"%V\" may not have port %d",
a0310ac2814f rewritten upstream
Igor Sysoev <igor@sysoev.ru>
parents: 901
diff changeset
6378 &u->host, u->port);
a0310ac2814f rewritten upstream
Igor Sysoev <igor@sysoev.ru>
parents: 901
diff changeset
6379 return NULL;
a0310ac2814f rewritten upstream
Igor Sysoev <igor@sysoev.ru>
parents: 901
diff changeset
6380 }
a0310ac2814f rewritten upstream
Igor Sysoev <igor@sysoev.ru>
parents: 901
diff changeset
6381
5005
c9059bd5445b Fixed "proxy_pass" with IP address and no port (ticket #276).
Ruslan Ermilov <ru@nginx.com>
parents: 4990
diff changeset
6382 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
6383 ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
906
a0310ac2814f rewritten upstream
Igor Sysoev <igor@sysoev.ru>
parents: 901
diff changeset
6384 "upstream \"%V\" may not have port %d in %s:%ui",
a0310ac2814f rewritten upstream
Igor Sysoev <igor@sysoev.ru>
parents: 901
diff changeset
6385 &u->host, uscfp[i]->port,
1489
56f1ea5baabb u_char* is enough to keep file name
Igor Sysoev <igor@sysoev.ru>
parents: 1469
diff changeset
6386 uscfp[i]->file_name, uscfp[i]->line);
906
a0310ac2814f rewritten upstream
Igor Sysoev <igor@sysoev.ru>
parents: 901
diff changeset
6387 return NULL;
a0310ac2814f rewritten upstream
Igor Sysoev <igor@sysoev.ru>
parents: 901
diff changeset
6388 }
a0310ac2814f rewritten upstream
Igor Sysoev <igor@sysoev.ru>
parents: 901
diff changeset
6389
5005
c9059bd5445b Fixed "proxy_pass" with IP address and no port (ticket #276).
Ruslan Ermilov <ru@nginx.com>
parents: 4990
diff changeset
6390 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
6391 && 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
6392 {
906
a0310ac2814f rewritten upstream
Igor Sysoev <igor@sysoev.ru>
parents: 901
diff changeset
6393 continue;
884
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6394 }
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6395
4152
65c1c241d70e Better handling of late upstream creation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4151
diff changeset
6396 if (flags & NGX_HTTP_UPSTREAM_CREATE) {
65c1c241d70e Better handling of late upstream creation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4151
diff changeset
6397 uscfp[i]->flags = flags;
6787
640e1e778de6 Upstream: consistently initialize explicit upstreams.
Ruslan Ermilov <ru@nginx.com>
parents: 6786
diff changeset
6398 uscfp[i]->port = 0;
4152
65c1c241d70e Better handling of late upstream creation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4151
diff changeset
6399 }
65c1c241d70e Better handling of late upstream creation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4151
diff changeset
6400
884
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6401 return uscfp[i];
651
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6402 }
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6403
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6404 uscf = ngx_pcalloc(cf->pool, sizeof(ngx_http_upstream_srv_conf_t));
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6405 if (uscf == NULL) {
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6406 return NULL;
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6407 }
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6408
884
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6409 uscf->flags = flags;
651
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6410 uscf->host = u->host;
1489
56f1ea5baabb u_char* is enough to keep file name
Igor Sysoev <igor@sysoev.ru>
parents: 1469
diff changeset
6411 uscf->file_name = cf->conf_file->file.name.data;
651
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6412 uscf->line = cf->conf_file->line;
906
a0310ac2814f rewritten upstream
Igor Sysoev <igor@sysoev.ru>
parents: 901
diff changeset
6413 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
6414 uscf->no_port = u->no_port;
884
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6415
5977
26c127bab5ef Upstream: detect port absence in fastcgi_pass with IP literal.
Ruslan Ermilov <ru@nginx.com>
parents: 5968
diff changeset
6416 if (u->naddrs == 1 && (u->port || u->family == AF_UNIX)) {
884
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6417 uscf->servers = ngx_array_create(cf->pool, 1,
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6418 sizeof(ngx_http_upstream_server_t));
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6419 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
6420 return NULL;
884
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6421 }
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6422
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6423 us = ngx_array_push(uscf->servers);
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6424 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
6425 return NULL;
884
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6426 }
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6427
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6428 ngx_memzero(us, sizeof(ngx_http_upstream_server_t));
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6429
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6430 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
6431 us->naddrs = 1;
884
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6432 }
651
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6433
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6434 uscfp = ngx_array_push(&umcf->upstreams);
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6435 if (uscfp == NULL) {
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6436 return NULL;
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6437 }
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6438
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6439 *uscfp = uscf;
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6440
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6441 return uscf;
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6442 }
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6443
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6444
3271
fcd98af88df3 proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents: 3198
diff changeset
6445 char *
3399
ac9c0380337d fix typo
Igor Sysoev <igor@sysoev.ru>
parents: 3369
diff changeset
6446 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
6447 void *conf)
fcd98af88df3 proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents: 3198
diff changeset
6448 {
fcd98af88df3 proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents: 3198
diff changeset
6449 char *p = conf;
fcd98af88df3 proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents: 3198
diff changeset
6450
5008
fd84344f1df7 Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents: 5005
diff changeset
6451 ngx_int_t rc;
fd84344f1df7 Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents: 5005
diff changeset
6452 ngx_str_t *value;
fd84344f1df7 Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents: 5005
diff changeset
6453 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
6454 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
6455 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
6456
fd84344f1df7 Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents: 5005
diff changeset
6457 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
6458
fd84344f1df7 Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents: 5005
diff changeset
6459 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
6460 return "is duplicate";
3271
fcd98af88df3 proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents: 3198
diff changeset
6461 }
fcd98af88df3 proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents: 3198
diff changeset
6462
3272
98f49b2bcae8 change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents: 3271
diff changeset
6463 value = cf->args->elts;
98f49b2bcae8 change ngx_parse_addr() interface
Igor Sysoev <igor@sysoev.ru>
parents: 3271
diff changeset
6464
6530
1d0e03db9f8e Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 6528
diff changeset
6465 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
6466 *plocal = NULL;
fd84344f1df7 Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents: 5005
diff changeset
6467 return NGX_CONF_OK;
fd84344f1df7 Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents: 5005
diff changeset
6468 }
fd84344f1df7 Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents: 5005
diff changeset
6469
fd84344f1df7 Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents: 5005
diff changeset
6470 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
6471
fd84344f1df7 Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents: 5005
diff changeset
6472 ccv.cf = cf;
fd84344f1df7 Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents: 5005
diff changeset
6473 ccv.value = &value[1];
fd84344f1df7 Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents: 5005
diff changeset
6474 ccv.complex_value = &cv;
fd84344f1df7 Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents: 5005
diff changeset
6475
fd84344f1df7 Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents: 5005
diff changeset
6476 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
6477 return NGX_CONF_ERROR;
fd84344f1df7 Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents: 5005
diff changeset
6478 }
fd84344f1df7 Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents: 5005
diff changeset
6479
fd84344f1df7 Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents: 5005
diff changeset
6480 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
6481 if (local == NULL) {
fd84344f1df7 Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents: 5005
diff changeset
6482 return NGX_CONF_ERROR;
fd84344f1df7 Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents: 5005
diff changeset
6483 }
fd84344f1df7 Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents: 5005
diff changeset
6484
fd84344f1df7 Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents: 5005
diff changeset
6485 *plocal = local;
fd84344f1df7 Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents: 5005
diff changeset
6486
fd84344f1df7 Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents: 5005
diff changeset
6487 if (cv.lengths) {
fd84344f1df7 Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents: 5005
diff changeset
6488 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
6489 if (local->value == NULL) {
fd84344f1df7 Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents: 5005
diff changeset
6490 return NGX_CONF_ERROR;
fd84344f1df7 Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents: 5005
diff changeset
6491 }
fd84344f1df7 Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents: 5005
diff changeset
6492
fd84344f1df7 Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents: 5005
diff changeset
6493 *local->value = cv;
fd84344f1df7 Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents: 5005
diff changeset
6494
6528
88f012eee7d8 Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents: 6474
diff changeset
6495 } else {
88f012eee7d8 Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents: 6474
diff changeset
6496 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
6497 if (local->addr == NULL) {
88f012eee7d8 Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents: 6474
diff changeset
6498 return NGX_CONF_ERROR;
88f012eee7d8 Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents: 6474
diff changeset
6499 }
88f012eee7d8 Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents: 6474
diff changeset
6500
6594
3c87b82b17d4 Upstream: support for port in proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 6536
diff changeset
6501 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
6502 value[1].len);
6528
88f012eee7d8 Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents: 6474
diff changeset
6503
88f012eee7d8 Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents: 6474
diff changeset
6504 switch (rc) {
88f012eee7d8 Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents: 6474
diff changeset
6505 case NGX_OK:
88f012eee7d8 Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents: 6474
diff changeset
6506 local->addr->name = value[1];
88f012eee7d8 Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents: 6474
diff changeset
6507 break;
88f012eee7d8 Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents: 6474
diff changeset
6508
88f012eee7d8 Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents: 6474
diff changeset
6509 case NGX_DECLINED:
88f012eee7d8 Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents: 6474
diff changeset
6510 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
6511 "invalid address \"%V\"", &value[1]);
88f012eee7d8 Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents: 6474
diff changeset
6512 /* fall through */
88f012eee7d8 Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents: 6474
diff changeset
6513
88f012eee7d8 Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents: 6474
diff changeset
6514 default:
88f012eee7d8 Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents: 6474
diff changeset
6515 return NGX_CONF_ERROR;
88f012eee7d8 Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents: 6474
diff changeset
6516 }
88f012eee7d8 Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents: 6474
diff changeset
6517 }
88f012eee7d8 Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents: 6474
diff changeset
6518
6530
1d0e03db9f8e Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 6528
diff changeset
6519 if (cf->args->nelts > 2) {
1d0e03db9f8e Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 6528
diff changeset
6520 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
6521 #if (NGX_HAVE_TRANSPARENT_PROXY)
7174
84e53e4735a4 Retain CAP_NET_RAW capability for transparent proxying.
Roman Arutyunyan <arut@nginx.com>
parents: 7166
diff changeset
6522 ngx_core_conf_t *ccf;
84e53e4735a4 Retain CAP_NET_RAW capability for transparent proxying.
Roman Arutyunyan <arut@nginx.com>
parents: 7166
diff changeset
6523
84e53e4735a4 Retain CAP_NET_RAW capability for transparent proxying.
Roman Arutyunyan <arut@nginx.com>
parents: 7166
diff changeset
6524 ccf = (ngx_core_conf_t *) ngx_get_conf(cf->cycle->conf_ctx,
84e53e4735a4 Retain CAP_NET_RAW capability for transparent proxying.
Roman Arutyunyan <arut@nginx.com>
parents: 7166
diff changeset
6525 ngx_core_module);
84e53e4735a4 Retain CAP_NET_RAW capability for transparent proxying.
Roman Arutyunyan <arut@nginx.com>
parents: 7166
diff changeset
6526
84e53e4735a4 Retain CAP_NET_RAW capability for transparent proxying.
Roman Arutyunyan <arut@nginx.com>
parents: 7166
diff changeset
6527 ccf->transparent = 1;
6530
1d0e03db9f8e Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 6528
diff changeset
6528 local->transparent = 1;
1d0e03db9f8e Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 6528
diff changeset
6529 #else
1d0e03db9f8e Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 6528
diff changeset
6530 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
6531 "transparent proxying is not supported "
1d0e03db9f8e Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 6528
diff changeset
6532 "on this platform, ignored");
1d0e03db9f8e Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 6528
diff changeset
6533 #endif
1d0e03db9f8e Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 6528
diff changeset
6534 } else {
1d0e03db9f8e Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 6528
diff changeset
6535 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
6536 "invalid parameter \"%V\"", &value[2]);
1d0e03db9f8e Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 6528
diff changeset
6537 return NGX_CONF_ERROR;
1d0e03db9f8e Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 6528
diff changeset
6538 }
1d0e03db9f8e Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 6528
diff changeset
6539 }
1d0e03db9f8e Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 6528
diff changeset
6540
6528
88f012eee7d8 Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents: 6474
diff changeset
6541 return NGX_CONF_OK;
3271
fcd98af88df3 proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents: 3198
diff changeset
6542 }
fcd98af88df3 proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents: 3198
diff changeset
6543
fcd98af88df3 proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents: 3198
diff changeset
6544
6528
88f012eee7d8 Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents: 6474
diff changeset
6545 static ngx_int_t
88f012eee7d8 Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents: 6474
diff changeset
6546 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
6547 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
6548 {
fd84344f1df7 Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents: 5005
diff changeset
6549 ngx_int_t rc;
fd84344f1df7 Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents: 5005
diff changeset
6550 ngx_str_t val;
fd84344f1df7 Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents: 5005
diff changeset
6551 ngx_addr_t *addr;
fd84344f1df7 Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents: 5005
diff changeset
6552
fd84344f1df7 Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents: 5005
diff changeset
6553 if (local == NULL) {
6528
88f012eee7d8 Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents: 6474
diff changeset
6554 u->peer.local = NULL;
88f012eee7d8 Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents: 6474
diff changeset
6555 return NGX_OK;
5008
fd84344f1df7 Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents: 5005
diff changeset
6556 }
fd84344f1df7 Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents: 5005
diff changeset
6557
6530
1d0e03db9f8e Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 6528
diff changeset
6558 #if (NGX_HAVE_TRANSPARENT_PROXY)
1d0e03db9f8e Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 6528
diff changeset
6559 u->peer.transparent = local->transparent;
1d0e03db9f8e Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 6528
diff changeset
6560 #endif
1d0e03db9f8e Upstream: the "transparent" parameter of proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 6528
diff changeset
6561
5008
fd84344f1df7 Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents: 5005
diff changeset
6562 if (local->value == NULL) {
6528
88f012eee7d8 Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents: 6474
diff changeset
6563 u->peer.local = local->addr;
88f012eee7d8 Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents: 6474
diff changeset
6564 return NGX_OK;
5008
fd84344f1df7 Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents: 5005
diff changeset
6565 }
fd84344f1df7 Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents: 5005
diff changeset
6566
fd84344f1df7 Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents: 5005
diff changeset
6567 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
6568 return NGX_ERROR;
5008
fd84344f1df7 Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents: 5005
diff changeset
6569 }
fd84344f1df7 Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents: 5005
diff changeset
6570
fd84344f1df7 Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents: 5005
diff changeset
6571 if (val.len == 0) {
6528
88f012eee7d8 Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents: 6474
diff changeset
6572 return NGX_OK;
5008
fd84344f1df7 Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents: 5005
diff changeset
6573 }
fd84344f1df7 Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents: 5005
diff changeset
6574
fd84344f1df7 Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents: 5005
diff changeset
6575 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
6576 if (addr == NULL) {
6528
88f012eee7d8 Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents: 6474
diff changeset
6577 return NGX_ERROR;
5008
fd84344f1df7 Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents: 5005
diff changeset
6578 }
fd84344f1df7 Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents: 5005
diff changeset
6579
6594
3c87b82b17d4 Upstream: support for port in proxy_bind and friends.
Roman Arutyunyan <arut@nginx.com>
parents: 6536
diff changeset
6580 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
6581 if (rc == NGX_ERROR) {
88f012eee7d8 Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents: 6474
diff changeset
6582 return NGX_ERROR;
88f012eee7d8 Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents: 6474
diff changeset
6583 }
88f012eee7d8 Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents: 6474
diff changeset
6584
88f012eee7d8 Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents: 6474
diff changeset
6585 if (rc != NGX_OK) {
5008
fd84344f1df7 Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents: 5005
diff changeset
6586 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
6587 "invalid local address \"%V\"", &val);
6528
88f012eee7d8 Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents: 6474
diff changeset
6588 return NGX_OK;
88f012eee7d8 Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents: 6474
diff changeset
6589 }
88f012eee7d8 Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents: 6474
diff changeset
6590
88f012eee7d8 Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents: 6474
diff changeset
6591 addr->name = val;
88f012eee7d8 Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents: 6474
diff changeset
6592 u->peer.local = addr;
88f012eee7d8 Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents: 6474
diff changeset
6593
88f012eee7d8 Upstream: prepared proxy_bind to accept parameters.
Roman Arutyunyan <arut@nginx.com>
parents: 6474
diff changeset
6594 return NGX_OK;
5008
fd84344f1df7 Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents: 5005
diff changeset
6595 }
fd84344f1df7 Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents: 5005
diff changeset
6596
fd84344f1df7 Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents: 5005
diff changeset
6597
4328
d15a00e6d9e6 Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents: 4298
diff changeset
6598 char *
d15a00e6d9e6 Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents: 4298
diff changeset
6599 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
6600 void *conf)
d15a00e6d9e6 Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents: 4298
diff changeset
6601 {
d15a00e6d9e6 Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents: 4298
diff changeset
6602 char *p = conf;
d15a00e6d9e6 Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents: 4298
diff changeset
6603
d15a00e6d9e6 Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents: 4298
diff changeset
6604 ngx_str_t *value;
d15a00e6d9e6 Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents: 4298
diff changeset
6605 ngx_array_t **a;
d15a00e6d9e6 Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents: 4298
diff changeset
6606 ngx_http_upstream_param_t *param;
d15a00e6d9e6 Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents: 4298
diff changeset
6607
d15a00e6d9e6 Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents: 4298
diff changeset
6608 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
6609
d15a00e6d9e6 Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents: 4298
diff changeset
6610 if (*a == NULL) {
d15a00e6d9e6 Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents: 4298
diff changeset
6611 *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
6612 if (*a == NULL) {
d15a00e6d9e6 Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents: 4298
diff changeset
6613 return NGX_CONF_ERROR;
d15a00e6d9e6 Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents: 4298
diff changeset
6614 }
d15a00e6d9e6 Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents: 4298
diff changeset
6615 }
d15a00e6d9e6 Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents: 4298
diff changeset
6616
d15a00e6d9e6 Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents: 4298
diff changeset
6617 param = ngx_array_push(*a);
d15a00e6d9e6 Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents: 4298
diff changeset
6618 if (param == NULL) {
d15a00e6d9e6 Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents: 4298
diff changeset
6619 return NGX_CONF_ERROR;
d15a00e6d9e6 Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents: 4298
diff changeset
6620 }
d15a00e6d9e6 Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents: 4298
diff changeset
6621
d15a00e6d9e6 Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents: 4298
diff changeset
6622 value = cf->args->elts;
d15a00e6d9e6 Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents: 4298
diff changeset
6623
d15a00e6d9e6 Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents: 4298
diff changeset
6624 param->key = value[1];
d15a00e6d9e6 Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents: 4298
diff changeset
6625 param->value = value[2];
d15a00e6d9e6 Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents: 4298
diff changeset
6626 param->skip_empty = 0;
d15a00e6d9e6 Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents: 4298
diff changeset
6627
d15a00e6d9e6 Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents: 4298
diff changeset
6628 if (cf->args->nelts == 4) {
d15a00e6d9e6 Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents: 4298
diff changeset
6629 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
6630 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
6631 "invalid parameter \"%V\"", &value[3]);
d15a00e6d9e6 Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents: 4298
diff changeset
6632 return NGX_CONF_ERROR;
d15a00e6d9e6 Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents: 4298
diff changeset
6633 }
d15a00e6d9e6 Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents: 4298
diff changeset
6634
d15a00e6d9e6 Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents: 4298
diff changeset
6635 param->skip_empty = 1;
d15a00e6d9e6 Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents: 4298
diff changeset
6636 }
d15a00e6d9e6 Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents: 4298
diff changeset
6637
d15a00e6d9e6 Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents: 4298
diff changeset
6638 return NGX_CONF_OK;
d15a00e6d9e6 Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents: 4298
diff changeset
6639 }
d15a00e6d9e6 Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents: 4298
diff changeset
6640
d15a00e6d9e6 Added the ngx_http_upstream_param_set_slot().
Valentin Bartenev <vbart@nginx.com>
parents: 4298
diff changeset
6641
1701
40d004d95d88 *) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents: 1699
diff changeset
6642 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
6643 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
6644 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
6645 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
6646 {
40d004d95d88 *) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents: 1699
diff changeset
6647 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
6648 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
6649 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
6650 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
6651
40d004d95d88 *) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents: 1699
diff changeset
6652 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
6653 && 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
6654 {
4769
f88555d76886 Upstream: hide_headers/pass_headers inheritance fix.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4766
diff changeset
6655 conf->hide_headers = prev->hide_headers;
f88555d76886 Upstream: hide_headers/pass_headers inheritance fix.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4766
diff changeset
6656 conf->pass_headers = prev->pass_headers;
f88555d76886 Upstream: hide_headers/pass_headers inheritance fix.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4766
diff changeset
6657
1701
40d004d95d88 *) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents: 1699
diff changeset
6658 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
6659
6744
7e5199f172fb Upstream: hide_headers_hash inherited regardless of cache settings.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6705
diff changeset
6660 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
6661 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
6662 }
40d004d95d88 *) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents: 1699
diff changeset
6663
40d004d95d88 *) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents: 1699
diff changeset
6664 } else {
40d004d95d88 *) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents: 1699
diff changeset
6665 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
6666 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
6667 }
40d004d95d88 *) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents: 1699
diff changeset
6668
40d004d95d88 *) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents: 1699
diff changeset
6669 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
6670 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
6671 }
40d004d95d88 *) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents: 1699
diff changeset
6672 }
40d004d95d88 *) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents: 1699
diff changeset
6673
40d004d95d88 *) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents: 1699
diff changeset
6674 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
6675 != NGX_OK)
40d004d95d88 *) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents: 1699
diff changeset
6676 {
40d004d95d88 *) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents: 1699
diff changeset
6677 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
6678 }
40d004d95d88 *) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents: 1699
diff changeset
6679
40d004d95d88 *) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents: 1699
diff changeset
6680 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
6681 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
6682 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
6683 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
6684 }
40d004d95d88 *) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents: 1699
diff changeset
6685
40d004d95d88 *) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents: 1699
diff changeset
6686 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
6687 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
6688 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
6689 }
40d004d95d88 *) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents: 1699
diff changeset
6690
40d004d95d88 *) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents: 1699
diff changeset
6691 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
6692
40d004d95d88 *) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents: 1699
diff changeset
6693 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
6694
40d004d95d88 *) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents: 1699
diff changeset
6695 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
6696
40d004d95d88 *) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents: 1699
diff changeset
6697 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
6698
40d004d95d88 *) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents: 1699
diff changeset
6699 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
6700 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
6701 goto exist;
40d004d95d88 *) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents: 1699
diff changeset
6702 }
40d004d95d88 *) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents: 1699
diff changeset
6703 }
40d004d95d88 *) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents: 1699
diff changeset
6704
40d004d95d88 *) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents: 1699
diff changeset
6705 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
6706 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
6707 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
6708 }
40d004d95d88 *) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents: 1699
diff changeset
6709
40d004d95d88 *) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents: 1699
diff changeset
6710 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
6711 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
6712 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
6713
40d004d95d88 *) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents: 1699
diff changeset
6714 exist:
40d004d95d88 *) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents: 1699
diff changeset
6715
40d004d95d88 *) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents: 1699
diff changeset
6716 continue;
40d004d95d88 *) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents: 1699
diff changeset
6717 }
40d004d95d88 *) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents: 1699
diff changeset
6718 }
40d004d95d88 *) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents: 1699
diff changeset
6719
40d004d95d88 *) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents: 1699
diff changeset
6720 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
6721
40d004d95d88 *) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents: 1699
diff changeset
6722 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
6723 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
6724
40d004d95d88 *) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents: 1699
diff changeset
6725 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
6726 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
6727
40d004d95d88 *) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents: 1699
diff changeset
6728 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
6729 continue;
40d004d95d88 *) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents: 1699
diff changeset
6730 }
40d004d95d88 *) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents: 1699
diff changeset
6731
40d004d95d88 *) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents: 1699
diff changeset
6732 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
6733 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
6734 break;
40d004d95d88 *) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents: 1699
diff changeset
6735 }
40d004d95d88 *) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents: 1699
diff changeset
6736 }
40d004d95d88 *) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents: 1699
diff changeset
6737 }
40d004d95d88 *) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents: 1699
diff changeset
6738 }
40d004d95d88 *) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents: 1699
diff changeset
6739
40d004d95d88 *) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents: 1699
diff changeset
6740 hash->hash = &conf->hide_headers_hash;
1706
9242e21d2f8d style fix: remove trailing spaces
Igor Sysoev <igor@sysoev.ru>
parents: 1705
diff changeset
6741 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
6742 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
6743 hash->temp_pool = NULL;
1706
9242e21d2f8d style fix: remove trailing spaces
Igor Sysoev <igor@sysoev.ru>
parents: 1705
diff changeset
6744
6745
93121485c39b Upstream: hide_headers_hash handling at http level.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6744
diff changeset
6745 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
6746 return NGX_ERROR;
93121485c39b Upstream: hide_headers_hash handling at http level.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6744
diff changeset
6747 }
93121485c39b Upstream: hide_headers_hash handling at http level.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6744
diff changeset
6748
93121485c39b Upstream: hide_headers_hash handling at http level.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6744
diff changeset
6749 /*
93121485c39b Upstream: hide_headers_hash handling at http level.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6744
diff changeset
6750 * 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
6751 * 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
6752 */
93121485c39b Upstream: hide_headers_hash handling at http level.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6744
diff changeset
6753
93121485c39b Upstream: hide_headers_hash handling at http level.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6744
diff changeset
6754 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
6755 && conf->hide_headers == prev->hide_headers
93121485c39b Upstream: hide_headers_hash handling at http level.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6744
diff changeset
6756 && conf->pass_headers == prev->pass_headers)
93121485c39b Upstream: hide_headers_hash handling at http level.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6744
diff changeset
6757 {
93121485c39b Upstream: hide_headers_hash handling at http level.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6744
diff changeset
6758 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
6759 }
93121485c39b Upstream: hide_headers_hash handling at http level.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6744
diff changeset
6760
93121485c39b Upstream: hide_headers_hash handling at http level.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6744
diff changeset
6761 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
6762 }
40d004d95d88 *) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents: 1699
diff changeset
6763
40d004d95d88 *) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents: 1699
diff changeset
6764
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
6765 static void *
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
6766 ngx_http_upstream_create_main_conf(ngx_conf_t *cf)
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
6767 {
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
6768 ngx_http_upstream_main_conf_t *umcf;
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
6769
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
6770 umcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_upstream_main_conf_t));
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
6771 if (umcf == NULL) {
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
6772 return NULL;
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
6773 }
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
6774
651
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6775 if (ngx_array_init(&umcf->upstreams, cf->pool, 4,
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6776 sizeof(ngx_http_upstream_srv_conf_t *))
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6777 != NGX_OK)
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6778 {
2912
c7d57b539248 return NULL instead of NGX_CONF_ERROR on a create conf failure
Igor Sysoev <igor@sysoev.ru>
parents: 2882
diff changeset
6779 return NULL;
651
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6780 }
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6781
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
6782 return umcf;
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
6783 }
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
6784
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
6785
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
6786 static char *
651
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6787 ngx_http_upstream_init_main_conf(ngx_conf_t *cf, void *conf)
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
6788 {
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
6789 ngx_http_upstream_main_conf_t *umcf = conf;
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
6790
651
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6791 ngx_uint_t i;
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6792 ngx_array_t headers_in;
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6793 ngx_hash_key_t *hk;
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6794 ngx_hash_init_t hash;
884
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6795 ngx_http_upstream_init_pt init;
651
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6796 ngx_http_upstream_header_t *header;
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6797 ngx_http_upstream_srv_conf_t **uscfp;
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6798
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6799 uscfp = umcf->upstreams.elts;
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6800
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6801 for (i = 0; i < umcf->upstreams.nelts; i++) {
884
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6802
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6803 init = uscfp[i]->peer.init_upstream ? uscfp[i]->peer.init_upstream:
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6804 ngx_http_upstream_init_round_robin;
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6805
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6806 if (init(cf, uscfp[i]) != NGX_OK) {
651
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6807 return NGX_CONF_ERROR;
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6808 }
39b7d7b33c91 nginx-0.3.47-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 649
diff changeset
6809 }
649
1e720b0be7ec nginx-0.3.46-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 641
diff changeset
6810
663
6d5c1535bb9d nginx-0.3.53-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 659
diff changeset
6811
884
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6812 /* upstream_headers_in_hash */
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 880
diff changeset
6813
649
1e720b0be7ec nginx-0.3.46-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 641
diff changeset
6814 if (ngx_array_init(&headers_in, cf->temp_pool, 32, sizeof(ngx_hash_key_t))
1e720b0be7ec nginx-0.3.46-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 641
diff changeset
6815 != NGX_OK)
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
6816 {
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
6817 return NGX_CONF_ERROR;
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
6818 }
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
6819
649
1e720b0be7ec nginx-0.3.46-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 641
diff changeset
6820 for (header = ngx_http_upstream_headers_in; header->name.len; header++) {
1e720b0be7ec nginx-0.3.46-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 641
diff changeset
6821 hk = ngx_array_push(&headers_in);
1e720b0be7ec nginx-0.3.46-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 641
diff changeset
6822 if (hk == NULL) {
1e720b0be7ec nginx-0.3.46-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 641
diff changeset
6823 return NGX_CONF_ERROR;
1e720b0be7ec nginx-0.3.46-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 641
diff changeset
6824 }
1e720b0be7ec nginx-0.3.46-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 641
diff changeset
6825
1e720b0be7ec nginx-0.3.46-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 641
diff changeset
6826 hk->key = header->name;
1e720b0be7ec nginx-0.3.46-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 641
diff changeset
6827 hk->key_hash = ngx_hash_key_lc(header->name.data, header->name.len);
1e720b0be7ec nginx-0.3.46-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 641
diff changeset
6828 hk->value = header;
1e720b0be7ec nginx-0.3.46-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 641
diff changeset
6829 }
1e720b0be7ec nginx-0.3.46-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 641
diff changeset
6830
1e720b0be7ec nginx-0.3.46-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 641
diff changeset
6831 hash.hash = &umcf->headers_in_hash;
1e720b0be7ec nginx-0.3.46-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 641
diff changeset
6832 hash.key = ngx_hash_key_lc;
1e720b0be7ec nginx-0.3.46-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 641
diff changeset
6833 hash.max_size = 512;
751
bae59a740c40 align hash bucket size to cache line
Igor Sysoev <igor@sysoev.ru>
parents: 750
diff changeset
6834 hash.bucket_size = ngx_align(64, ngx_cacheline_size);
649
1e720b0be7ec nginx-0.3.46-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 641
diff changeset
6835 hash.name = "upstream_headers_in_hash";
1e720b0be7ec nginx-0.3.46-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 641
diff changeset
6836 hash.pool = cf->pool;
1e720b0be7ec nginx-0.3.46-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 641
diff changeset
6837 hash.temp_pool = NULL;
1e720b0be7ec nginx-0.3.46-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 641
diff changeset
6838
1e720b0be7ec nginx-0.3.46-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 641
diff changeset
6839 if (ngx_hash_init(&hash, headers_in.elts, headers_in.nelts) != NGX_OK) {
1e720b0be7ec nginx-0.3.46-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 641
diff changeset
6840 return NGX_CONF_ERROR;
1e720b0be7ec nginx-0.3.46-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 641
diff changeset
6841 }
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
6842
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
6843 return NGX_CONF_OK;
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
6844 }