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