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