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