3 * Copyright (C) Igor Sysoev
7 #ifndef _NGX_HTTP_UPSTREAM_H_INCLUDED_
8 #define _NGX_HTTP_UPSTREAM_H_INCLUDED_
11 #include <ngx_config.h>
13 #include <ngx_event.h>
14 #include <ngx_event_connect.h>
15 #include <ngx_event_pipe.h>
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
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_UPDATING 0x00000200
28 #define NGX_HTTP_UPSTREAM_FT_BUSY_LOCK 0x00000400
29 #define NGX_HTTP_UPSTREAM_FT_MAX_WAITING 0x00000800
30 #define NGX_HTTP_UPSTREAM_FT_NOLIVE 0x40000000
31 #define NGX_HTTP_UPSTREAM_FT_OFF 0x80000000
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)
39 #define NGX_HTTP_UPSTREAM_INVALID_HEADER 40
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
54 ngx_uint_t response_msec
;
55 off_t response_length
;
58 } ngx_http_upstream_state_t
;
62 ngx_hash_t headers_in_hash
;
63 ngx_array_t upstreams
;
64 /* ngx_http_upstream_srv_conf_t */
65 } ngx_http_upstream_main_conf_t
;
67 typedef struct ngx_http_upstream_srv_conf_s ngx_http_upstream_srv_conf_t
;
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
);
76 ngx_http_upstream_init_pt init_upstream
;
77 ngx_http_upstream_init_peer_pt init
;
79 } ngx_http_upstream_peer_t
;
83 ngx_peer_addr_t
*addrs
;
91 } ngx_http_upstream_server_t
;
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
102 struct ngx_http_upstream_srv_conf_s
{
103 ngx_http_upstream_peer_t peer
;
106 ngx_array_t
*servers
; /* ngx_http_upstream_server_t */
113 in_port_t default_port
;
118 ngx_http_upstream_srv_conf_t
*upstream
;
120 ngx_msec_t connect_timeout
;
121 ngx_msec_t send_timeout
;
122 ngx_msec_t read_timeout
;
128 size_t busy_buffers_size
;
129 size_t max_temp_file_size
;
130 size_t temp_file_write_size
;
132 size_t busy_buffers_size_conf
;
133 size_t max_temp_file_size_conf
;
134 size_t temp_file_write_size_conf
;
138 ngx_uint_t ignore_headers
;
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
;
145 ngx_flag_t ignore_client_abort
;
146 ngx_flag_t intercept_errors
;
147 ngx_flag_t cyclic_temp_file
;
149 ngx_path_t
*temp_path
;
151 ngx_hash_t hide_headers_hash
;
152 ngx_array_t
*hide_headers
;
153 ngx_array_t
*pass_headers
;
156 ngx_shm_zone_t
*cache
;
158 ngx_uint_t cache_min_uses
;
159 ngx_uint_t cache_use_stale
;
160 ngx_uint_t cache_methods
;
162 ngx_array_t
*cache_valid
;
165 ngx_array_t
*store_lengths
;
166 ngx_array_t
*store_values
;
169 unsigned intercept_404
:1;
170 unsigned change_buffering
:1;
174 ngx_flag_t ssl_session_reuse
;
177 } ngx_http_upstream_conf_t
;
182 ngx_http_header_handler_pt handler
;
184 ngx_http_header_handler_pt copy_handler
;
186 ngx_uint_t redirect
; /* unsigned redirect:1; */
187 } ngx_http_upstream_header_t
;
194 ngx_str_t status_line
;
196 ngx_table_elt_t
*status
;
197 ngx_table_elt_t
*date
;
198 ngx_table_elt_t
*server
;
199 ngx_table_elt_t
*connection
;
201 ngx_table_elt_t
*expires
;
202 ngx_table_elt_t
*etag
;
203 ngx_table_elt_t
*x_accel_expires
;
204 ngx_table_elt_t
*x_accel_redirect
;
205 ngx_table_elt_t
*x_accel_limit_rate
;
207 ngx_table_elt_t
*content_type
;
208 ngx_table_elt_t
*content_length
;
210 ngx_table_elt_t
*last_modified
;
211 ngx_table_elt_t
*location
;
212 ngx_table_elt_t
*accept_ranges
;
213 ngx_table_elt_t
*www_authenticate
;
216 ngx_table_elt_t
*content_encoding
;
219 off_t content_length_n
;
221 ngx_array_t cache_control
;
222 } ngx_http_upstream_headers_in_t
;
228 ngx_uint_t no_port
; /* unsigned no_port:1 */
233 struct sockaddr
*sockaddr
;
236 ngx_resolver_ctx_t
*ctx
;
237 } ngx_http_upstream_resolved_t
;
240 typedef void (*ngx_http_upstream_handler_pt
)(ngx_http_request_t
*r
,
241 ngx_http_upstream_t
*u
);
244 struct ngx_http_upstream_s
{
245 ngx_http_upstream_handler_pt read_event_handler
;
246 ngx_http_upstream_handler_pt write_event_handler
;
248 ngx_peer_connection_t peer
;
250 ngx_event_pipe_t
*pipe
;
252 ngx_chain_t
*request_bufs
;
254 ngx_output_chain_ctx_t output
;
255 ngx_chain_writer_ctx_t writer
;
257 ngx_http_upstream_conf_t
*conf
;
259 ngx_http_upstream_headers_in_t headers_in
;
261 ngx_http_upstream_resolved_t
*resolved
;
266 ngx_chain_t
*out_bufs
;
267 ngx_chain_t
*busy_bufs
;
268 ngx_chain_t
*free_bufs
;
270 ngx_int_t (*input_filter_init
)(void *data
);
271 ngx_int_t (*input_filter
)(void *data
, ssize_t bytes
);
272 void *input_filter_ctx
;
275 ngx_int_t (*create_key
)(ngx_http_request_t
*r
);
277 ngx_int_t (*create_request
)(ngx_http_request_t
*r
);
278 ngx_int_t (*reinit_request
)(ngx_http_request_t
*r
);
279 ngx_int_t (*process_header
)(ngx_http_request_t
*r
);
280 void (*abort_request
)(ngx_http_request_t
*r
);
281 void (*finalize_request
)(ngx_http_request_t
*r
,
283 ngx_int_t (*rewrite_redirect
)(ngx_http_request_t
*r
,
284 ngx_table_elt_t
*h
, size_t prefix
);
288 ngx_http_upstream_state_t
*state
;
294 ngx_http_cleanup_pt
*cleanup
;
297 unsigned cacheable
:1;
301 unsigned stale_cache
:1;
304 unsigned buffering
:1;
306 unsigned request_sent
:1;
307 unsigned header_sent
:1;
314 } ngx_http_upstream_next_t
;
317 ngx_int_t
ngx_http_upstream_header_variable(ngx_http_request_t
*r
,
318 ngx_http_variable_value_t
*v
, uintptr_t data
);
320 void ngx_http_upstream_init(ngx_http_request_t
*r
);
321 ngx_http_upstream_srv_conf_t
*ngx_http_upstream_add(ngx_conf_t
*cf
,
322 ngx_url_t
*u
, ngx_uint_t flags
);
323 ngx_int_t
ngx_http_upstream_hide_headers_hash(ngx_conf_t
*cf
,
324 ngx_http_upstream_conf_t
*conf
, ngx_http_upstream_conf_t
*prev
,
325 ngx_str_t
*default_hide_headers
, ngx_hash_init_t
*hash
);
328 #define ngx_http_conf_upstream_srv_conf(uscf, module) \
329 uscf->srv_conf[module.ctx_index]
332 extern ngx_module_t ngx_http_upstream_module
;
333 extern ngx_conf_bitmask_t ngx_http_upstream_cache_method_mask
[];
337 #endif /* _NGX_HTTP_UPSTREAM_H_INCLUDED_ */