1e18a033bSKonstantin Ananyev
2e18a033bSKonstantin Ananyev/*
3e18a033bSKonstantin Ananyev * Copyright (C) Igor Sysoev
4e18a033bSKonstantin Ananyev * Copyright (C) Nginx, Inc.
5e18a033bSKonstantin Ananyev */
6e18a033bSKonstantin Ananyev
7e18a033bSKonstantin Ananyev
8e18a033bSKonstantin Ananyev#include <ngx_config.h>
9e18a033bSKonstantin Ananyev#include <ngx_core.h>
10e18a033bSKonstantin Ananyev#include <ngx_http.h>
11e18a033bSKonstantin Ananyev
12e18a033bSKonstantin Ananyev
13e18a033bSKonstantin Ananyev#if (NGX_HTTP_CACHE)
14e18a033bSKonstantin Ananyevstatic ngx_int_t ngx_http_upstream_cache(ngx_http_request_t *r,
15e18a033bSKonstantin Ananyev    ngx_http_upstream_t *u);
16e18a033bSKonstantin Ananyevstatic ngx_int_t ngx_http_upstream_cache_get(ngx_http_request_t *r,
17e18a033bSKonstantin Ananyev    ngx_http_upstream_t *u, ngx_http_file_cache_t **cache);
18e18a033bSKonstantin Ananyevstatic ngx_int_t ngx_http_upstream_cache_send(ngx_http_request_t *r,
19e18a033bSKonstantin Ananyev    ngx_http_upstream_t *u);
20e18a033bSKonstantin Ananyevstatic ngx_int_t ngx_http_upstream_cache_background_update(
21e18a033bSKonstantin Ananyev    ngx_http_request_t *r, ngx_http_upstream_t *u);
22e18a033bSKonstantin Ananyevstatic ngx_int_t ngx_http_upstream_cache_check_range(ngx_http_request_t *r,
23e18a033bSKonstantin Ananyev    ngx_http_upstream_t *u);
24e18a033bSKonstantin Ananyevstatic ngx_int_t ngx_http_upstream_cache_status(ngx_http_request_t *r,
25e18a033bSKonstantin Ananyev    ngx_http_variable_value_t *v, uintptr_t data);
26e18a033bSKonstantin Ananyevstatic ngx_int_t ngx_http_upstream_cache_last_modified(ngx_http_request_t *r,
27e18a033bSKonstantin Ananyev    ngx_http_variable_value_t *v, uintptr_t data);
28e18a033bSKonstantin Ananyevstatic ngx_int_t ngx_http_upstream_cache_etag(ngx_http_request_t *r,
29e18a033bSKonstantin Ananyev    ngx_http_variable_value_t *v, uintptr_t data);
30e18a033bSKonstantin Ananyev#endif
31e18a033bSKonstantin Ananyev
32e18a033bSKonstantin Ananyevstatic void ngx_http_upstream_init_request(ngx_http_request_t *r);
33e18a033bSKonstantin Ananyevstatic void ngx_http_upstream_resolve_handler(ngx_resolver_ctx_t *ctx);
34e18a033bSKonstantin Ananyevstatic void ngx_http_upstream_rd_check_broken_connection(ngx_http_request_t *r);
35e18a033bSKonstantin Ananyevstatic void ngx_http_upstream_wr_check_broken_connection(ngx_http_request_t *r);
36e18a033bSKonstantin Ananyevstatic void ngx_http_upstream_check_broken_connection(ngx_http_request_t *r,
37e18a033bSKonstantin Ananyev    ngx_event_t *ev);
38e18a033bSKonstantin Ananyevstatic void ngx_http_upstream_connect(ngx_http_request_t *r,
39e18a033bSKonstantin Ananyev    ngx_http_upstream_t *u);
40e18a033bSKonstantin Ananyevstatic ngx_int_t ngx_http_upstream_reinit(ngx_http_request_t *r,
41e18a033bSKonstantin Ananyev    ngx_http_upstream_t *u);
42e18a033bSKonstantin Ananyevstatic void ngx_http_upstream_send_request(ngx_http_request_t *r,
43e18a033bSKonstantin Ananyev    ngx_http_upstream_t *u, ngx_uint_t do_write);
44e18a033bSKonstantin Ananyevstatic ngx_int_t ngx_http_upstream_send_request_body(ngx_http_request_t *r,
45e18a033bSKonstantin Ananyev    ngx_http_upstream_t *u, ngx_uint_t do_write);
46e18a033bSKonstantin Ananyevstatic void ngx_http_upstream_send_request_handler(ngx_http_request_t *r,
47e18a033bSKonstantin Ananyev    ngx_http_upstream_t *u);
48e18a033bSKonstantin Ananyevstatic void ngx_http_upstream_read_request_handler(ngx_http_request_t *r);
49e18a033bSKonstantin Ananyevstatic void ngx_http_upstream_process_header(ngx_http_request_t *r,
50e18a033bSKonstantin Ananyev    ngx_http_upstream_t *u);
51e18a033bSKonstantin Ananyevstatic ngx_int_t ngx_http_upstream_test_next(ngx_http_request_t *r,
52e18a033bSKonstantin Ananyev    ngx_http_upstream_t *u);
53e18a033bSKonstantin Ananyevstatic ngx_int_t ngx_http_upstream_intercept_errors(ngx_http_request_t *r,
54e18a033bSKonstantin Ananyev    ngx_http_upstream_t *u);
55e18a033bSKonstantin Ananyevstatic ngx_int_t ngx_http_upstream_test_connect(ngx_connection_t *c);
56e18a033bSKonstantin Ananyevstatic ngx_int_t ngx_http_upstream_process_headers(ngx_http_request_t *r,
57e18a033bSKonstantin Ananyev    ngx_http_upstream_t *u);
58e18a033bSKonstantin Ananyevstatic void ngx_http_upstream_process_body_in_memory(ngx_http_request_t *r,
59e18a033bSKonstantin Ananyev    ngx_http_upstream_t *u);
60e18a033bSKonstantin Ananyevstatic void ngx_http_upstream_send_response(ngx_http_request_t *r,
61e18a033bSKonstantin Ananyev    ngx_http_upstream_t *u);
62e18a033bSKonstantin Ananyevstatic void ngx_http_upstream_upgrade(ngx_http_request_t *r,
63e18a033bSKonstantin Ananyev    ngx_http_upstream_t *u);
64e18a033bSKonstantin Ananyevstatic void ngx_http_upstream_upgraded_read_downstream(ngx_http_request_t *r);
65e18a033bSKonstantin Ananyevstatic void ngx_http_upstream_upgraded_write_downstream(ngx_http_request_t *r);
66e18a033bSKonstantin Ananyevstatic void ngx_http_upstream_upgraded_read_upstream(ngx_http_request_t *r,
67e18a033bSKonstantin Ananyev    ngx_http_upstream_t *u);
68e18a033bSKonstantin Ananyevstatic void ngx_http_upstream_upgraded_write_upstream(ngx_http_request_t *r,
69e18a033bSKonstantin Ananyev    ngx_http_upstream_t *u);
70e18a033bSKonstantin Ananyevstatic void ngx_http_upstream_process_upgraded(ngx_http_request_t *r,
71e18a033bSKonstantin Ananyev    ngx_uint_t from_upstream, ngx_uint_t do_write);
72e18a033bSKonstantin Ananyevstatic void
73e18a033bSKonstantin Ananyev    ngx_http_upstream_process_non_buffered_downstream(ngx_http_request_t *r);
74e18a033bSKonstantin Ananyevstatic void
75e18a033bSKonstantin Ananyev    ngx_http_upstream_process_non_buffered_upstream(ngx_http_request_t *r,
76e18a033bSKonstantin Ananyev    ngx_http_upstream_t *u);
77e18a033bSKonstantin Ananyevstatic void
78e18a033bSKonstantin Ananyev    ngx_http_upstream_process_non_buffered_request(ngx_http_request_t *r,
79e18a033bSKonstantin Ananyev    ngx_uint_t do_write);
80e18a033bSKonstantin Ananyevstatic ngx_int_t ngx_http_upstream_non_buffered_filter_init(void *data);
81e18a033bSKonstantin Ananyevstatic ngx_int_t ngx_http_upstream_non_buffered_filter(void *data,
82e18a033bSKonstantin Ananyev    ssize_t bytes);
83e18a033bSKonstantin Ananyev#if (NGX_THREADS)
84e18a033bSKonstantin Ananyevstatic ngx_int_t ngx_http_upstream_thread_handler(ngx_thread_task_t *task,
85e18a033bSKonstantin Ananyev    ngx_file_t *file);
86e18a033bSKonstantin Ananyevstatic void ngx_http_upstream_thread_event_handler(ngx_event_t *ev);
87e18a033bSKonstantin Ananyev#endif
88e18a033bSKonstantin Ananyevstatic ngx_int_t ngx_http_upstream_output_filter(void *data,
89e18a033bSKonstantin Ananyev    ngx_chain_t *chain);
90e18a033bSKonstantin Ananyevstatic void ngx_http_upstream_process_downstream(ngx_http_request_t *r);
91e18a033bSKonstantin Ananyevstatic void ngx_http_upstream_process_upstream(ngx_http_request_t *r,
92e18a033bSKonstantin Ananyev    ngx_http_upstream_t *u);
93e18a033bSKonstantin Ananyevstatic void ngx_http_upstream_process_request(ngx_http_request_t *r,
94e18a033bSKonstantin Ananyev    ngx_http_upstream_t *u);
95e18a033bSKonstantin Ananyevstatic void ngx_http_upstream_store(ngx_http_request_t *r,
96e18a033bSKonstantin Ananyev    ngx_http_upstream_t *u);
97e18a033bSKonstantin Ananyevstatic void ngx_http_upstream_dummy_handler(ngx_http_request_t *r,
98e18a033bSKonstantin Ananyev    ngx_http_upstream_t *u);
99e18a033bSKonstantin Ananyevstatic void ngx_http_upstream_next(ngx_http_request_t *r,
100e18a033bSKonstantin Ananyev    ngx_http_upstream_t *u, ngx_uint_t ft_type);
101e18a033bSKonstantin Ananyevstatic void ngx_http_upstream_cleanup(void *data);
102e18a033bSKonstantin Ananyevstatic void ngx_http_upstream_finalize_request(ngx_http_request_t *r,
103e18a033bSKonstantin Ananyev    ngx_http_upstream_t *u, ngx_int_t rc);
104e18a033bSKonstantin Ananyev
105e18a033bSKonstantin Ananyevstatic ngx_int_t ngx_http_upstream_process_header_line(ngx_http_request_t *r,
106e18a033bSKonstantin Ananyev    ngx_table_elt_t *h, ngx_uint_t offset);
107e18a033bSKonstantin Ananyevstatic ngx_int_t ngx_http_upstream_process_content_length(ngx_http_request_t *r,
108e18a033bSKonstantin Ananyev    ngx_table_elt_t *h, ngx_uint_t offset);
109e18a033bSKonstantin Ananyevstatic ngx_int_t ngx_http_upstream_process_last_modified(ngx_http_request_t *r,
110e18a033bSKonstantin Ananyev    ngx_table_elt_t *h, ngx_uint_t offset);
111e18a033bSKonstantin Ananyevstatic ngx_int_t ngx_http_upstream_process_set_cookie(ngx_http_request_t *r,
112e18a033bSKonstantin Ananyev    ngx_table_elt_t *h, ngx_uint_t offset);
113e18a033bSKonstantin Ananyevstatic ngx_int_t
114e18a033bSKonstantin Ananyev    ngx_http_upstream_process_cache_control(ngx_http_request_t *r,
115e18a033bSKonstantin Ananyev    ngx_table_elt_t *h, ngx_uint_t offset);
116e18a033bSKonstantin Ananyevstatic ngx_int_t ngx_http_upstream_ignore_header_line(ngx_http_request_t *r,
117e18a033bSKonstantin Ananyev    ngx_table_elt_t *h, ngx_uint_t offset);
118e18a033bSKonstantin Ananyevstatic ngx_int_t ngx_http_upstream_process_expires(ngx_http_request_t *r,
119e18a033bSKonstantin Ananyev    ngx_table_elt_t *h, ngx_uint_t offset);
120e18a033bSKonstantin Ananyevstatic ngx_int_t ngx_http_upstream_process_accel_expires(ngx_http_request_t *r,
121e18a033bSKonstantin Ananyev    ngx_table_elt_t *h, ngx_uint_t offset);
122e18a033bSKonstantin Ananyevstatic ngx_int_t ngx_http_upstream_process_limit_rate(ngx_http_request_t *r,
123e18a033bSKonstantin Ananyev    ngx_table_elt_t *h, ngx_uint_t offset);
124e18a033bSKonstantin Ananyevstatic ngx_int_t ngx_http_upstream_process_buffering(ngx_http_request_t *r,
125e18a033bSKonstantin Ananyev    ngx_table_elt_t *h, ngx_uint_t offset);
126e18a033bSKonstantin Ananyevstatic ngx_int_t ngx_http_upstream_process_charset(ngx_http_request_t *r,
127e18a033bSKonstantin Ananyev    ngx_table_elt_t *h, ngx_uint_t offset);
128e18a033bSKonstantin Ananyevstatic ngx_int_t ngx_http_upstream_process_connection(ngx_http_request_t *r,
129e18a033bSKonstantin Ananyev    ngx_table_elt_t *h, ngx_uint_t offset);
130e18a033bSKonstantin Ananyevstatic ngx_int_t
131e18a033bSKonstantin Ananyev    ngx_http_upstream_process_transfer_encoding(ngx_http_request_t *r,
132e18a033bSKonstantin Ananyev    ngx_table_elt_t *h, ngx_uint_t offset);
133e18a033bSKonstantin Ananyevstatic ngx_int_t ngx_http_upstream_process_vary(ngx_http_request_t *r,
134e18a033bSKonstantin Ananyev    ngx_table_elt_t *h, ngx_uint_t offset);
135e18a033bSKonstantin Ananyevstatic ngx_int_t ngx_http_upstream_copy_header_line(ngx_http_request_t *r,
136e18a033bSKonstantin Ananyev    ngx_table_elt_t *h, ngx_uint_t offset);
137e18a033bSKonstantin Ananyevstatic ngx_int_t
138e18a033bSKonstantin Ananyev    ngx_http_upstream_copy_multi_header_lines(ngx_http_request_t *r,
139e18a033bSKonstantin Ananyev    ngx_table_elt_t *h, ngx_uint_t offset);
140e18a033bSKonstantin Ananyevstatic ngx_int_t ngx_http_upstream_copy_content_type(ngx_http_request_t *r,
141e18a033bSKonstantin Ananyev    ngx_table_elt_t *h, ngx_uint_t offset);
142e18a033bSKonstantin Ananyevstatic ngx_int_t ngx_http_upstream_copy_last_modified(ngx_http_request_t *r,
143e18a033bSKonstantin Ananyev    ngx_table_elt_t *h, ngx_uint_t offset);
144e18a033bSKonstantin Ananyevstatic ngx_int_t ngx_http_upstream_rewrite_location(ngx_http_request_t *r,
145e18a033bSKonstantin Ananyev    ngx_table_elt_t *h, ngx_uint_t offset);
146e18a033bSKonstantin Ananyevstatic ngx_int_t ngx_http_upstream_rewrite_refresh(ngx_http_request_t *r,
147e18a033bSKonstantin Ananyev    ngx_table_elt_t *h, ngx_uint_t offset);
148e18a033bSKonstantin Ananyevstatic ngx_int_t ngx_http_upstream_rewrite_set_cookie(ngx_http_request_t *r,
149e18a033bSKonstantin Ananyev    ngx_table_elt_t *h, ngx_uint_t offset);
150e18a033bSKonstantin Ananyevstatic ngx_int_t ngx_http_upstream_copy_allow_ranges(ngx_http_request_t *r,
151e18a033bSKonstantin Ananyev    ngx_table_elt_t *h, ngx_uint_t offset);
152e18a033bSKonstantin Ananyev
153e18a033bSKonstantin Ananyev#if (NGX_HTTP_GZIP)
154e18a033bSKonstantin Ananyevstatic ngx_int_t ngx_http_upstream_copy_content_encoding(ngx_http_request_t *r,
155e18a033bSKonstantin Ananyev    ngx_table_elt_t *h, ngx_uint_t offset);
156e18a033bSKonstantin Ananyev#endif
157e18a033bSKonstantin Ananyev
158e18a033bSKonstantin Ananyevstatic ngx_int_t ngx_http_upstream_add_variables(ngx_conf_t *cf);
159e18a033bSKonstantin Ananyevstatic ngx_int_t ngx_http_upstream_addr_variable(ngx_http_request_t *r,
160e18a033bSKonstantin Ananyev    ngx_http_variable_value_t *v, uintptr_t data);
161e18a033bSKonstantin Ananyevstatic ngx_int_t ngx_http_upstream_status_variable(ngx_http_request_t *r,
162e18a033bSKonstantin Ananyev    ngx_http_variable_value_t *v, uintptr_t data);
163e18a033bSKonstantin Ananyevstatic ngx_int_t ngx_http_upstream_response_time_variable(ngx_http_request_t *r,
164e18a033bSKonstantin Ananyev    ngx_http_variable_value_t *v, uintptr_t data);
165e18a033bSKonstantin Ananyevstatic ngx_int_t ngx_http_upstream_response_length_variable(
166e18a033bSKonstantin Ananyev    ngx_http_request_t *r, ngx_http_variable_value_t *v, uintptr_t data);
167e18a033bSKonstantin Ananyevstatic ngx_int_t ngx_http_upstream_header_variable(ngx_http_request_t *r,
168e18a033bSKonstantin Ananyev    ngx_http_variable_value_t *v, uintptr_t data);
169e18a033bSKonstantin Ananyevstatic ngx_int_t ngx_http_upstream_cookie_variable(ngx_http_request_t *r,
170e18a033bSKonstantin Ananyev    ngx_http_variable_value_t *v, uintptr_t data);
171e18a033bSKonstantin Ananyev
172e18a033bSKonstantin Ananyevstatic char *ngx_http_upstream(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy);
173e18a033bSKonstantin Ananyevstatic char *ngx_http_upstream_server(ngx_conf_t *cf, ngx_command_t *cmd,
174e18a033bSKonstantin Ananyev    void *conf);
175e18a033bSKonstantin Ananyev
176e18a033bSKonstantin Ananyevstatic ngx_int_t ngx_http_upstream_set_local(ngx_http_request_t *r,
177e18a033bSKonstantin Ananyev  ngx_http_upstream_t *u, ngx_http_upstream_local_t *local);
178e18a033bSKonstantin Ananyev
179e18a033bSKonstantin Ananyevstatic void *ngx_http_upstream_create_main_conf(ngx_conf_t *cf);
180e18a033bSKonstantin Ananyevstatic char *ngx_http_upstream_init_main_conf(ngx_conf_t *cf, void *conf);
181e18a033bSKonstantin Ananyev
182e18a033bSKonstantin Ananyev#if (NGX_HTTP_SSL)
183e18a033bSKonstantin Ananyevstatic void ngx_http_upstream_ssl_init_connection(ngx_http_request_t *,
184e18a033bSKonstantin Ananyev    ngx_http_upstream_t *u, ngx_connection_t *c);
185e18a033bSKonstantin Ananyevstatic void ngx_http_upstream_ssl_handshake(ngx_connection_t *c);
186e18a033bSKonstantin Ananyevstatic ngx_int_t ngx_http_upstream_ssl_name(ngx_http_request_t *r,
187e18a033bSKonstantin Ananyev    ngx_http_upstream_t *u, ngx_connection_t *c);
188e18a033bSKonstantin Ananyev#endif
189e18a033bSKonstantin Ananyev
190e18a033bSKonstantin Ananyev
191e18a033bSKonstantin Ananyevstatic ngx_http_upstream_header_t  ngx_http_upstream_headers_in[] = {
192e18a033bSKonstantin Ananyev
193e18a033bSKonstantin Ananyev    { ngx_string("Status"),
194e18a033bSKonstantin Ananyev                 ngx_http_upstream_process_header_line,
195e18a033bSKonstantin Ananyev                 offsetof(ngx_http_upstream_headers_in_t, status),
196e18a033bSKonstantin Ananyev                 ngx_http_upstream_copy_header_line, 0, 0 },
197e18a033bSKonstantin Ananyev
198e18a033bSKonstantin Ananyev    { ngx_string("Content-Type"),
199e18a033bSKonstantin Ananyev                 ngx_http_upstream_process_header_line,
200e18a033bSKonstantin Ananyev                 offsetof(ngx_http_upstream_headers_in_t, content_type),
201e18a033bSKonstantin Ananyev                 ngx_http_upstream_copy_content_type, 0, 1 },
202e18a033bSKonstantin Ananyev
203e18a033bSKonstantin Ananyev    { ngx_string("Content-Length"),
204e18a033bSKonstantin Ananyev                 ngx_http_upstream_process_content_length, 0,
205e18a033bSKonstantin Ananyev                 ngx_http_upstream_ignore_header_line, 0, 0 },
206e18a033bSKonstantin Ananyev
207e18a033bSKonstantin Ananyev    { ngx_string("Date"),
208e18a033bSKonstantin Ananyev                 ngx_http_upstream_process_header_line,
209e18a033bSKonstantin Ananyev                 offsetof(ngx_http_upstream_headers_in_t, date),
210e18a033bSKonstantin Ananyev                 ngx_http_upstream_copy_header_line,
211e18a033bSKonstantin Ananyev                 offsetof(ngx_http_headers_out_t, date), 0 },
212e18a033bSKonstantin Ananyev
213e18a033bSKonstantin Ananyev    { ngx_string("Last-Modified"),
214e18a033bSKonstantin Ananyev                 ngx_http_upstream_process_last_modified, 0,
215e18a033bSKonstantin Ananyev                 ngx_http_upstream_copy_last_modified, 0, 0 },
216e18a033bSKonstantin Ananyev
217e18a033bSKonstantin Ananyev    { ngx_string("ETag"),
218e18a033bSKonstantin Ananyev                 ngx_http_upstream_process_header_line,
219e18a033bSKonstantin Ananyev                 offsetof(ngx_http_upstream_headers_in_t, etag),
220e18a033bSKonstantin Ananyev                 ngx_http_upstream_copy_header_line,
221e18a033bSKonstantin Ananyev                 offsetof(ngx_http_headers_out_t, etag), 0 },
222e18a033bSKonstantin Ananyev
223e18a033bSKonstantin Ananyev    { ngx_string("Server"),
224e18a033bSKonstantin Ananyev                 ngx_http_upstream_process_header_line,
225e18a033bSKonstantin Ananyev                 offsetof(ngx_http_upstream_headers_in_t, server),
226e18a033bSKonstantin Ananyev                 ngx_http_upstream_copy_header_line,
227e18a033bSKonstantin Ananyev                 offsetof(ngx_http_headers_out_t, server), 0 },
228e18a033bSKonstantin Ananyev
229e18a033bSKonstantin Ananyev    { ngx_string("WWW-Authenticate"),
230e18a033bSKonstantin Ananyev                 ngx_http_upstream_process_header_line,
231e18a033bSKonstantin Ananyev                 offsetof(ngx_http_upstream_headers_in_t, www_authenticate),
232e18a033bSKonstantin Ananyev                 ngx_http_upstream_copy_header_line, 0, 0 },
233e18a033bSKonstantin Ananyev
234e18a033bSKonstantin Ananyev    { ngx_string("Location"),
235e18a033bSKonstantin Ananyev                 ngx_http_upstream_process_header_line,
236e18a033bSKonstantin Ananyev                 offsetof(ngx_http_upstream_headers_in_t, location),
237e18a033bSKonstantin Ananyev                 ngx_http_upstream_rewrite_location, 0, 0 },
238e18a033bSKonstantin Ananyev
239e18a033bSKonstantin Ananyev    { ngx_string("Refresh"),
240e18a033bSKonstantin Ananyev                 ngx_http_upstream_ignore_header_line, 0,
241e18a033bSKonstantin Ananyev                 ngx_http_upstream_rewrite_refresh, 0, 0 },
242e18a033bSKonstantin Ananyev
243e18a033bSKonstantin Ananyev    { ngx_string("Set-Cookie"),
244e18a033bSKonstantin Ananyev                 ngx_http_upstream_process_set_cookie,
245e18a033bSKonstantin Ananyev                 offsetof(ngx_http_upstream_headers_in_t, cookies),
246e18a033bSKonstantin Ananyev                 ngx_http_upstream_rewrite_set_cookie, 0, 1 },
247e18a033bSKonstantin Ananyev
248e18a033bSKonstantin Ananyev    { ngx_string("Content-Disposition"),
249e18a033bSKonstantin Ananyev                 ngx_http_upstream_ignore_header_line, 0,
250e18a033bSKonstantin Ananyev                 ngx_http_upstream_copy_header_line, 0, 1 },
251e18a033bSKonstantin Ananyev
252e18a033bSKonstantin Ananyev    { ngx_string("Cache-Control"),
253e18a033bSKonstantin Ananyev                 ngx_http_upstream_process_cache_control, 0,
254e18a033bSKonstantin Ananyev                 ngx_http_upstream_copy_multi_header_lines,
255e18a033bSKonstantin Ananyev                 offsetof(ngx_http_headers_out_t, cache_control), 1 },
256e18a033bSKonstantin Ananyev
257e18a033bSKonstantin Ananyev    { ngx_string("Expires"),
258e18a033bSKonstantin Ananyev                 ngx_http_upstream_process_expires, 0,
259e18a033bSKonstantin Ananyev                 ngx_http_upstream_copy_header_line,
260e18a033bSKonstantin Ananyev                 offsetof(ngx_http_headers_out_t, expires), 1 },
261e18a033bSKonstantin Ananyev
262e18a033bSKonstantin Ananyev    { ngx_string("Accept-Ranges"),
263e18a033bSKonstantin Ananyev                 ngx_http_upstream_process_header_line,
264e18a033bSKonstantin Ananyev                 offsetof(ngx_http_upstream_headers_in_t, accept_ranges),
265e18a033bSKonstantin Ananyev                 ngx_http_upstream_copy_allow_ranges,
266e18a033bSKonstantin Ananyev                 offsetof(ngx_http_headers_out_t, accept_ranges), 1 },
267e18a033bSKonstantin Ananyev
268e18a033bSKonstantin Ananyev    { ngx_string("Content-Range"),
269e18a033bSKonstantin Ananyev                 ngx_http_upstream_ignore_header_line, 0,
270e18a033bSKonstantin Ananyev                 ngx_http_upstream_copy_header_line,
271e18a033bSKonstantin Ananyev                 offsetof(ngx_http_headers_out_t, content_range), 0 },
272e18a033bSKonstantin Ananyev
273e18a033bSKonstantin Ananyev    { ngx_string("Connection"),
274e18a033bSKonstantin Ananyev                 ngx_http_upstream_process_connection, 0,
275e18a033bSKonstantin Ananyev                 ngx_http_upstream_ignore_header_line, 0, 0 },
276e18a033bSKonstantin Ananyev
277e18a033bSKonstantin Ananyev    { ngx_string("Keep-Alive"),
278e18a033bSKonstantin Ananyev                 ngx_http_upstream_ignore_header_line, 0,
279e18a033bSKonstantin Ananyev                 ngx_http_upstream_ignore_header_line, 0, 0 },
280e18a033bSKonstantin Ananyev
281e18a033bSKonstantin Ananyev    { ngx_string("Vary"),
282e18a033bSKonstantin Ananyev                 ngx_http_upstream_process_vary, 0,
283e18a033bSKonstantin Ananyev                 ngx_http_upstream_copy_header_line, 0, 0 },
284e18a033bSKonstantin Ananyev
285e18a033bSKonstantin Ananyev    { ngx_string("X-Powered-By"),
286e18a033bSKonstantin Ananyev                 ngx_http_upstream_ignore_header_line, 0,
287e18a033bSKonstantin Ananyev                 ngx_http_upstream_copy_header_line, 0, 0 },
288e18a033bSKonstantin Ananyev
289e18a033bSKonstantin Ananyev    { ngx_string("X-Accel-Expires"),
290e18a033bSKonstantin Ananyev                 ngx_http_upstream_process_accel_expires, 0,
291e18a033bSKonstantin Ananyev                 ngx_http_upstream_copy_header_line, 0, 0 },
292e18a033bSKonstantin Ananyev
293e18a033bSKonstantin Ananyev    { ngx_string("X-Accel-Redirect"),
294e18a033bSKonstantin Ananyev                 ngx_http_upstream_process_header_line,
295e18a033bSKonstantin Ananyev                 offsetof(ngx_http_upstream_headers_in_t, x_accel_redirect),
296e18a033bSKonstantin Ananyev                 ngx_http_upstream_copy_header_line, 0, 0 },
297e18a033bSKonstantin Ananyev
298e18a033bSKonstantin Ananyev    { ngx_string("X-Accel-Limit-Rate"),
299e18a033bSKonstantin Ananyev                 ngx_http_upstream_process_limit_rate, 0,
300e18a033bSKonstantin Ananyev                 ngx_http_upstream_copy_header_line, 0, 0 },
301e18a033bSKonstantin Ananyev
302e18a033bSKonstantin Ananyev    { ngx_string("X-Accel-Buffering"),
303e18a033bSKonstantin Ananyev                 ngx_http_upstream_process_buffering, 0,
304e18a033bSKonstantin Ananyev                 ngx_http_upstream_copy_header_line, 0, 0 },
305e18a033bSKonstantin Ananyev
306e18a033bSKonstantin Ananyev    { ngx_string("X-Accel-Charset"),
307e18a033bSKonstantin Ananyev                 ngx_http_upstream_process_charset, 0,
308e18a033bSKonstantin Ananyev                 ngx_http_upstream_copy_header_line, 0, 0 },
309e18a033bSKonstantin Ananyev
310e18a033bSKonstantin Ananyev    { ngx_string("Transfer-Encoding"),
311e18a033bSKonstantin Ananyev                 ngx_http_upstream_process_transfer_encoding, 0,
312e18a033bSKonstantin Ananyev                 ngx_http_upstream_ignore_header_line, 0, 0 },
313e18a033bSKonstantin Ananyev
314e18a033bSKonstantin Ananyev#if (NGX_HTTP_GZIP)
315e18a033bSKonstantin Ananyev    { ngx_string("Content-Encoding"),
316e18a033bSKonstantin Ananyev                 ngx_http_upstream_process_header_line,
317e18a033bSKonstantin Ananyev                 offsetof(ngx_http_upstream_headers_in_t, content_encoding),
318e18a033bSKonstantin Ananyev                 ngx_http_upstream_copy_content_encoding, 0, 0 },
319e18a033bSKonstantin Ananyev#endif
320e18a033bSKonstantin Ananyev
321e18a033bSKonstantin Ananyev    { ngx_null_string, NULL, 0, NULL, 0, 0 }
322e18a033bSKonstantin Ananyev};
323e18a033bSKonstantin Ananyev
324e18a033bSKonstantin Ananyev
325e18a033bSKonstantin Ananyevstatic ngx_command_t  ngx_http_upstream_commands[] = {
326e18a033bSKonstantin Ananyev
327e18a033bSKonstantin Ananyev    { ngx_string("upstream"),
328e18a033bSKonstantin Ananyev      NGX_HTTP_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_TAKE1,
329e18a033bSKonstantin Ananyev      ngx_http_upstream,
330e18a033bSKonstantin Ananyev      0,
331e18a033bSKonstantin Ananyev      0,
332e18a033bSKonstantin Ananyev      NULL },
333e18a033bSKonstantin Ananyev
334e18a033bSKonstantin Ananyev    { ngx_string("server"),
335e18a033bSKonstantin Ananyev      NGX_HTTP_UPS_CONF|NGX_CONF_1MORE,
336e18a033bSKonstantin Ananyev      ngx_http_upstream_server,
337e18a033bSKonstantin Ananyev      NGX_HTTP_SRV_CONF_OFFSET,
338e18a033bSKonstantin Ananyev      0,
339e18a033bSKonstantin Ananyev      NULL },
340e18a033bSKonstantin Ananyev
341e18a033bSKonstantin Ananyev      ngx_null_command
342e18a033bSKonstantin Ananyev};
343e18a033bSKonstantin Ananyev
344e18a033bSKonstantin Ananyev
345e18a033bSKonstantin Ananyevstatic ngx_http_module_t  ngx_http_upstream_module_ctx = {
346e18a033bSKonstantin Ananyev    ngx_http_upstream_add_variables,       /* preconfiguration */
347e18a033bSKonstantin Ananyev    NULL,                                  /* postconfiguration */
348e18a033bSKonstantin Ananyev
349e18a033bSKonstantin Ananyev    ngx_http_upstream_create_main_conf,    /* create main configuration */
350e18a033bSKonstantin Ananyev    ngx_http_upstream_init_main_conf,      /* init main configuration */
351e18a033bSKonstantin Ananyev
352e18a033bSKonstantin Ananyev    NULL,                                  /* create server configuration */
353e18a033bSKonstantin Ananyev    NULL,                                  /* merge server configuration */
354e18a033bSKonstantin Ananyev
355e18a033bSKonstantin Ananyev    NULL,                                  /* create location configuration */
356e18a033bSKonstantin Ananyev    NULL                                   /* merge location configuration */
357e18a033bSKonstantin Ananyev};
358e18a033bSKonstantin Ananyev
359e18a033bSKonstantin Ananyev
360e18a033bSKonstantin Ananyevngx_module_t  ngx_http_upstream_module = {
361e18a033bSKonstantin Ananyev    NGX_MODULE_V1,
362e18a033bSKonstantin Ananyev    &ngx_http_upstream_module_ctx,         /* module context */
363e18a033bSKonstantin Ananyev    ngx_http_upstream_commands,            /* module directives */
364e18a033bSKonstantin Ananyev    NGX_HTTP_MODULE,                       /* module type */
365e18a033bSKonstantin Ananyev    NULL,                                  /* init master */
366e18a033bSKonstantin Ananyev    NULL,                                  /* init module */
367e18a033bSKonstantin Ananyev    NULL,                                  /* init process */
368e18a033bSKonstantin Ananyev    NULL,                                  /* init thread */
369e18a033bSKonstantin Ananyev    NULL,                                  /* exit thread */
370e18a033bSKonstantin Ananyev    NULL,                                  /* exit process */
371e18a033bSKonstantin Ananyev    NULL,                                  /* exit master */
372e18a033bSKonstantin Ananyev    NGX_MODULE_V1_PADDING
373e18a033bSKonstantin Ananyev};
374e18a033bSKonstantin Ananyev
375e18a033bSKonstantin Ananyev
376e18a033bSKonstantin Ananyevstatic ngx_http_variable_t  ngx_http_upstream_vars[] = {
377e18a033bSKonstantin Ananyev
378e18a033bSKonstantin Ananyev    { ngx_string("upstream_addr"), NULL,
379e18a033bSKonstantin Ananyev      ngx_http_upstream_addr_variable, 0,
380e18a033bSKonstantin Ananyev      NGX_HTTP_VAR_NOCACHEABLE, 0 },
381e18a033bSKonstantin Ananyev
382e18a033bSKonstantin Ananyev    { ngx_string("upstream_status"), NULL,
383e18a033bSKonstantin Ananyev      ngx_http_upstream_status_variable, 0,
384e18a033bSKonstantin Ananyev      NGX_HTTP_VAR_NOCACHEABLE, 0 },
385e18a033bSKonstantin Ananyev
386e18a033bSKonstantin Ananyev    { ngx_string("upstream_connect_time"), NULL,
387e18a033bSKonstantin Ananyev      ngx_http_upstream_response_time_variable, 2,
388e18a033bSKonstantin Ananyev      NGX_HTTP_VAR_NOCACHEABLE, 0 },
389e18a033bSKonstantin Ananyev
390e18a033bSKonstantin Ananyev    { ngx_string("upstream_header_time"), NULL,
391e18a033bSKonstantin Ananyev      ngx_http_upstream_response_time_variable, 1,
392e18a033bSKonstantin Ananyev      NGX_HTTP_VAR_NOCACHEABLE, 0 },
393e18a033bSKonstantin Ananyev
394e18a033bSKonstantin Ananyev    { ngx_string("upstream_response_time"), NULL,
395e18a033bSKonstantin Ananyev      ngx_http_upstream_response_time_variable, 0,
396e18a033bSKonstantin Ananyev      NGX_HTTP_VAR_NOCACHEABLE, 0 },
397e18a033bSKonstantin Ananyev
398e18a033bSKonstantin Ananyev    { ngx_string("upstream_response_length"), NULL,
399e18a033bSKonstantin Ananyev      ngx_http_upstream_response_length_variable, 0,
400e18a033bSKonstantin Ananyev      NGX_HTTP_VAR_NOCACHEABLE, 0 },
401e18a033bSKonstantin Ananyev
402e18a033bSKonstantin Ananyev    { ngx_string("upstream_bytes_received"), NULL,
403e18a033bSKonstantin Ananyev      ngx_http_upstream_response_length_variable, 1,
404e18a033bSKonstantin Ananyev      NGX_HTTP_VAR_NOCACHEABLE, 0 },
405e18a033bSKonstantin Ananyev
406e18a033bSKonstantin Ananyev#if (NGX_HTTP_CACHE)
407e18a033bSKonstantin Ananyev
408e18a033bSKonstantin Ananyev    { ngx_string("upstream_cache_status"), NULL,
409e18a033bSKonstantin Ananyev      ngx_http_upstream_cache_status, 0,
410e18a033bSKonstantin Ananyev      NGX_HTTP_VAR_NOCACHEABLE, 0 },
411