28
|
1
|
|
2 /*
|
|
3 * Copyright (C) Igor Sysoev
|
644
|
4 * Copyright (C) Nginx, Inc.
|
28
|
5 */
|
|
6
|
|
7
|
|
8 #ifndef _NGX_HTTP_UPSTREAM_H_INCLUDED_
|
|
9 #define _NGX_HTTP_UPSTREAM_H_INCLUDED_
|
|
10
|
|
11
|
|
12 #include <ngx_config.h>
|
|
13 #include <ngx_core.h>
|
|
14 #include <ngx_event.h>
|
|
15 #include <ngx_event_connect.h>
|
|
16 #include <ngx_event_pipe.h>
|
|
17 #include <ngx_http.h>
|
|
18
|
|
19
|
214
|
20 #define NGX_HTTP_UPSTREAM_FT_ERROR 0x00000002
|
|
21 #define NGX_HTTP_UPSTREAM_FT_TIMEOUT 0x00000004
|
|
22 #define NGX_HTTP_UPSTREAM_FT_INVALID_HEADER 0x00000008
|
|
23 #define NGX_HTTP_UPSTREAM_FT_HTTP_500 0x00000010
|
412
|
24 #define NGX_HTTP_UPSTREAM_FT_HTTP_502 0x00000020
|
|
25 #define NGX_HTTP_UPSTREAM_FT_HTTP_503 0x00000040
|
|
26 #define NGX_HTTP_UPSTREAM_FT_HTTP_504 0x00000080
|
|
27 #define NGX_HTTP_UPSTREAM_FT_HTTP_404 0x00000100
|
498
|
28 #define NGX_HTTP_UPSTREAM_FT_UPDATING 0x00000200
|
|
29 #define NGX_HTTP_UPSTREAM_FT_BUSY_LOCK 0x00000400
|
|
30 #define NGX_HTTP_UPSTREAM_FT_MAX_WAITING 0x00000800
|
326
|
31 #define NGX_HTTP_UPSTREAM_FT_NOLIVE 0x40000000
|
214
|
32 #define NGX_HTTP_UPSTREAM_FT_OFF 0x80000000
|
28
|
33
|
412
|
34 #define NGX_HTTP_UPSTREAM_FT_STATUS (NGX_HTTP_UPSTREAM_FT_HTTP_500 \
|
|
35 |NGX_HTTP_UPSTREAM_FT_HTTP_502 \
|
|
36 |NGX_HTTP_UPSTREAM_FT_HTTP_503 \
|
|
37 |NGX_HTTP_UPSTREAM_FT_HTTP_504 \
|
|
38 |NGX_HTTP_UPSTREAM_FT_HTTP_404)
|
28
|
39
|
|
40 #define NGX_HTTP_UPSTREAM_INVALID_HEADER 40
|
|
41
|
|
42
|
484
|
43 #define NGX_HTTP_UPSTREAM_IGN_XA_REDIRECT 0x00000002
|
|
44 #define NGX_HTTP_UPSTREAM_IGN_XA_EXPIRES 0x00000004
|
|
45 #define NGX_HTTP_UPSTREAM_IGN_EXPIRES 0x00000008
|
|
46 #define NGX_HTTP_UPSTREAM_IGN_CACHE_CONTROL 0x00000010
|
584
|
47 #define NGX_HTTP_UPSTREAM_IGN_SET_COOKIE 0x00000020
|
638
|
48 #define NGX_HTTP_UPSTREAM_IGN_XA_LIMIT_RATE 0x00000040
|
|
49 #define NGX_HTTP_UPSTREAM_IGN_XA_BUFFERING 0x00000080
|
|
50 #define NGX_HTTP_UPSTREAM_IGN_XA_CHARSET 0x00000100
|
484
|
51
|
|
52
|
28
|
53 typedef struct {
|
464
|
54 ngx_msec_t bl_time;
|
|
55 ngx_uint_t bl_state;
|
28
|
56
|
464
|
57 ngx_uint_t status;
|
|
58 time_t response_sec;
|
|
59 ngx_uint_t response_msec;
|
604
|
60 off_t response_length;
|
112
|
61
|
464
|
62 ngx_str_t *peer;
|
28
|
63 } ngx_http_upstream_state_t;
|
|
64
|
|
65
|
|
66 typedef struct {
|
464
|
67 ngx_hash_t headers_in_hash;
|
|
68 ngx_array_t upstreams;
|
260
|
69 /* ngx_http_upstream_srv_conf_t */
|
58
|
70 } ngx_http_upstream_main_conf_t;
|
|
71
|
260
|
72 typedef struct ngx_http_upstream_srv_conf_s ngx_http_upstream_srv_conf_t;
|
|
73
|
|
74 typedef ngx_int_t (*ngx_http_upstream_init_pt)(ngx_conf_t *cf,
|
|
75 ngx_http_upstream_srv_conf_t *us);
|
|
76 typedef ngx_int_t (*ngx_http_upstream_init_peer_pt)(ngx_http_request_t *r,
|
|
77 ngx_http_upstream_srv_conf_t *us);
|
|
78
|
|
79
|
|
80 typedef struct {
|
464
|
81 ngx_http_upstream_init_pt init_upstream;
|
|
82 ngx_http_upstream_init_peer_pt init;
|
|
83 void *data;
|
260
|
84 } ngx_http_upstream_peer_t;
|
|
85
|
58
|
86
|
|
87 typedef struct {
|
540
|
88 ngx_addr_t *addrs;
|
464
|
89 ngx_uint_t naddrs;
|
|
90 ngx_uint_t weight;
|
|
91 ngx_uint_t max_fails;
|
|
92 time_t fail_timeout;
|
260
|
93
|
464
|
94 unsigned down:1;
|
|
95 unsigned backup:1;
|
260
|
96 } ngx_http_upstream_server_t;
|
|
97
|
200
|
98
|
260
|
99 #define NGX_HTTP_UPSTREAM_CREATE 0x0001
|
|
100 #define NGX_HTTP_UPSTREAM_WEIGHT 0x0002
|
|
101 #define NGX_HTTP_UPSTREAM_MAX_FAILS 0x0004
|
|
102 #define NGX_HTTP_UPSTREAM_FAIL_TIMEOUT 0x0008
|
|
103 #define NGX_HTTP_UPSTREAM_DOWN 0x0010
|
|
104 #define NGX_HTTP_UPSTREAM_BACKUP 0x0020
|
|
105
|
200
|
106
|
260
|
107 struct ngx_http_upstream_srv_conf_s {
|
464
|
108 ngx_http_upstream_peer_t peer;
|
|
109 void **srv_conf;
|
260
|
110
|
464
|
111 ngx_array_t *servers; /* ngx_http_upstream_server_t */
|
260
|
112
|
464
|
113 ngx_uint_t flags;
|
|
114 ngx_str_t host;
|
|
115 u_char *file_name;
|
|
116 ngx_uint_t line;
|
|
117 in_port_t port;
|
|
118 in_port_t default_port;
|
260
|
119 };
|
200
|
120
|
|
121
|
|
122 typedef struct {
|
464
|
123 ngx_http_upstream_srv_conf_t *upstream;
|
260
|
124
|
464
|
125 ngx_msec_t connect_timeout;
|
|
126 ngx_msec_t send_timeout;
|
|
127 ngx_msec_t read_timeout;
|
|
128 ngx_msec_t timeout;
|
28
|
129
|
464
|
130 size_t send_lowat;
|
|
131 size_t buffer_size;
|
78
|
132
|
464
|
133 size_t busy_buffers_size;
|
|
134 size_t max_temp_file_size;
|
|
135 size_t temp_file_write_size;
|
|
136
|
|
137 size_t busy_buffers_size_conf;
|
|
138 size_t max_temp_file_size_conf;
|
|
139 size_t temp_file_write_size_conf;
|
58
|
140
|
464
|
141 ngx_bufs_t bufs;
|
78
|
142
|
484
|
143 ngx_uint_t ignore_headers;
|
464
|
144 ngx_uint_t next_upstream;
|
|
145 ngx_uint_t store_access;
|
|
146 ngx_flag_t buffering;
|
|
147 ngx_flag_t pass_request_headers;
|
|
148 ngx_flag_t pass_request_body;
|
28
|
149
|
464
|
150 ngx_flag_t ignore_client_abort;
|
|
151 ngx_flag_t intercept_errors;
|
|
152 ngx_flag_t cyclic_temp_file;
|
|
153
|
|
154 ngx_path_t *temp_path;
|
28
|
155
|
464
|
156 ngx_hash_t hide_headers_hash;
|
|
157 ngx_array_t *hide_headers;
|
|
158 ngx_array_t *pass_headers;
|
58
|
159
|
540
|
160 ngx_addr_t *local;
|
|
161
|
464
|
162 #if (NGX_HTTP_CACHE)
|
|
163 ngx_shm_zone_t *cache;
|
28
|
164
|
464
|
165 ngx_uint_t cache_min_uses;
|
|
166 ngx_uint_t cache_use_stale;
|
494
|
167 ngx_uint_t cache_methods;
|
28
|
168
|
464
|
169 ngx_array_t *cache_valid;
|
588
|
170 ngx_array_t *cache_bypass;
|
|
171 ngx_array_t *no_cache;
|
464
|
172 #endif
|
58
|
173
|
464
|
174 ngx_array_t *store_lengths;
|
|
175 ngx_array_t *store_values;
|
320
|
176
|
464
|
177 signed store:2;
|
|
178 unsigned intercept_404:1;
|
|
179 unsigned change_buffering:1;
|
130
|
180
|
126
|
181 #if (NGX_HTTP_SSL)
|
464
|
182 ngx_ssl_t *ssl;
|
482
|
183 ngx_flag_t ssl_session_reuse;
|
126
|
184 #endif
|
|
185
|
632
|
186 ngx_str_t module;
|
28
|
187 } ngx_http_upstream_conf_t;
|
|
188
|
|
189
|
58
|
190 typedef struct {
|
464
|
191 ngx_str_t name;
|
|
192 ngx_http_header_handler_pt handler;
|
|
193 ngx_uint_t offset;
|
|
194 ngx_http_header_handler_pt copy_handler;
|
|
195 ngx_uint_t conf;
|
|
196 ngx_uint_t redirect; /* unsigned redirect:1; */
|
58
|
197 } ngx_http_upstream_header_t;
|
|
198
|
|
199
|
|
200 typedef struct {
|
464
|
201 ngx_list_t headers;
|
58
|
202
|
464
|
203 ngx_uint_t status_n;
|
|
204 ngx_str_t status_line;
|
78
|
205
|
464
|
206 ngx_table_elt_t *status;
|
|
207 ngx_table_elt_t *date;
|
|
208 ngx_table_elt_t *server;
|
|
209 ngx_table_elt_t *connection;
|
58
|
210
|
464
|
211 ngx_table_elt_t *expires;
|
|
212 ngx_table_elt_t *etag;
|
|
213 ngx_table_elt_t *x_accel_expires;
|
|
214 ngx_table_elt_t *x_accel_redirect;
|
|
215 ngx_table_elt_t *x_accel_limit_rate;
|
58
|
216
|
464
|
217 ngx_table_elt_t *content_type;
|
|
218 ngx_table_elt_t *content_length;
|
58
|
219
|
464
|
220 ngx_table_elt_t *last_modified;
|
|
221 ngx_table_elt_t *location;
|
|
222 ngx_table_elt_t *accept_ranges;
|
|
223 ngx_table_elt_t *www_authenticate;
|
58
|
224
|
|
225 #if (NGX_HTTP_GZIP)
|
464
|
226 ngx_table_elt_t *content_encoding;
|
58
|
227 #endif
|
|
228
|
464
|
229 off_t content_length_n;
|
364
|
230
|
464
|
231 ngx_array_t cache_control;
|
58
|
232 } ngx_http_upstream_headers_in_t;
|
|
233
|
28
|
234
|
348
|
235 typedef struct {
|
464
|
236 ngx_str_t host;
|
|
237 in_port_t port;
|
|
238 ngx_uint_t no_port; /* unsigned no_port:1 */
|
434
|
239
|
464
|
240 ngx_uint_t naddrs;
|
|
241 in_addr_t *addrs;
|
434
|
242
|
464
|
243 struct sockaddr *sockaddr;
|
|
244 socklen_t socklen;
|
434
|
245
|
464
|
246 ngx_resolver_ctx_t *ctx;
|
348
|
247 } ngx_http_upstream_resolved_t;
|
|
248
|
|
249
|
430
|
250 typedef void (*ngx_http_upstream_handler_pt)(ngx_http_request_t *r,
|
|
251 ngx_http_upstream_t *u);
|
|
252
|
|
253
|
28
|
254 struct ngx_http_upstream_s {
|
464
|
255 ngx_http_upstream_handler_pt read_event_handler;
|
|
256 ngx_http_upstream_handler_pt write_event_handler;
|
426
|
257
|
464
|
258 ngx_peer_connection_t peer;
|
28
|
259
|
464
|
260 ngx_event_pipe_t *pipe;
|
28
|
261
|
464
|
262 ngx_chain_t *request_bufs;
|
28
|
263
|
464
|
264 ngx_output_chain_ctx_t output;
|
|
265 ngx_chain_writer_ctx_t writer;
|
28
|
266
|
464
|
267 ngx_http_upstream_conf_t *conf;
|
28
|
268
|
464
|
269 ngx_http_upstream_headers_in_t headers_in;
|
58
|
270
|
464
|
271 ngx_http_upstream_resolved_t *resolved;
|
348
|
272
|
464
|
273 ngx_buf_t buffer;
|
|
274 size_t length;
|
130
|
275
|
464
|
276 ngx_chain_t *out_bufs;
|
|
277 ngx_chain_t *busy_bufs;
|
|
278 ngx_chain_t *free_bufs;
|
130
|
279
|
464
|
280 ngx_int_t (*input_filter_init)(void *data);
|
|
281 ngx_int_t (*input_filter)(void *data, ssize_t bytes);
|
|
282 void *input_filter_ctx;
|
28
|
283
|
464
|
284 #if (NGX_HTTP_CACHE)
|
|
285 ngx_int_t (*create_key)(ngx_http_request_t *r);
|
|
286 #endif
|
|
287 ngx_int_t (*create_request)(ngx_http_request_t *r);
|
|
288 ngx_int_t (*reinit_request)(ngx_http_request_t *r);
|
|
289 ngx_int_t (*process_header)(ngx_http_request_t *r);
|
|
290 void (*abort_request)(ngx_http_request_t *r);
|
|
291 void (*finalize_request)(ngx_http_request_t *r,
|
|
292 ngx_int_t rc);
|
|
293 ngx_int_t (*rewrite_redirect)(ngx_http_request_t *r,
|
|
294 ngx_table_elt_t *h, size_t prefix);
|
28
|
295
|
464
|
296 ngx_msec_t timeout;
|
76
|
297
|
464
|
298 ngx_http_upstream_state_t *state;
|
28
|
299
|
464
|
300 ngx_str_t method;
|
|
301 ngx_str_t schema;
|
|
302 ngx_str_t uri;
|
104
|
303
|
464
|
304 ngx_http_cleanup_pt *cleanup;
|
118
|
305
|
464
|
306 unsigned store:1;
|
|
307 unsigned cacheable:1;
|
|
308 unsigned accel:1;
|
|
309 unsigned ssl:1;
|
|
310 #if (NGX_HTTP_CACHE)
|
502
|
311 unsigned cache_status:3;
|
464
|
312 #endif
|
28
|
313
|
464
|
314 unsigned buffering:1;
|
198
|
315
|
464
|
316 unsigned request_sent:1;
|
|
317 unsigned header_sent:1;
|
28
|
318 };
|
|
319
|
|
320
|
412
|
321 typedef struct {
|
|
322 ngx_uint_t status;
|
|
323 ngx_uint_t mask;
|
|
324 } ngx_http_upstream_next_t;
|
|
325
|
|
326
|
296
|
327 ngx_int_t ngx_http_upstream_header_variable(ngx_http_request_t *r,
|
|
328 ngx_http_variable_value_t *v, uintptr_t data);
|
|
329
|
510
|
330 ngx_int_t ngx_http_upstream_create(ngx_http_request_t *r);
|
28
|
331 void ngx_http_upstream_init(ngx_http_request_t *r);
|
200
|
332 ngx_http_upstream_srv_conf_t *ngx_http_upstream_add(ngx_conf_t *cf,
|
260
|
333 ngx_url_t *u, ngx_uint_t flags);
|
558
|
334 char *ngx_http_upstream_bind_set_slot(ngx_conf_t *cf, ngx_command_t *cmd,
|
540
|
335 void *conf);
|
356
|
336 ngx_int_t ngx_http_upstream_hide_headers_hash(ngx_conf_t *cf,
|
|
337 ngx_http_upstream_conf_t *conf, ngx_http_upstream_conf_t *prev,
|
|
338 ngx_str_t *default_hide_headers, ngx_hash_init_t *hash);
|
260
|
339
|
|
340
|
|
341 #define ngx_http_conf_upstream_srv_conf(uscf, module) \
|
|
342 uscf->srv_conf[module.ctx_index]
|
58
|
343
|
28
|
344
|
494
|
345 extern ngx_module_t ngx_http_upstream_module;
|
|
346 extern ngx_conf_bitmask_t ngx_http_upstream_cache_method_mask[];
|
584
|
347 extern ngx_conf_bitmask_t ngx_http_upstream_ignore_headers_masks[];
|
494
|
348
|
28
|
349
|
|
350 #endif /* _NGX_HTTP_UPSTREAM_H_INCLUDED_ */
|