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