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_BUSY_LOCK 0x00000200
28 #define NGX_HTTP_UPSTREAM_FT_MAX_WAITING 0x00000400
29 #define NGX_HTTP_UPSTREAM_FT_NOLIVE 0x40000000
30 #define NGX_HTTP_UPSTREAM_FT_OFF 0x80000000
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)
38 #define NGX_HTTP_UPSTREAM_INVALID_HEADER 40
47 ngx_uint_t response_msec;
48 off_t response_length;
51 } ngx_http_upstream_state_t;
55 ngx_hash_t headers_in_hash;
56 ngx_array_t upstreams;
57 /* ngx_http_upstream_srv_conf_t */
58 } ngx_http_upstream_main_conf_t;
60 typedef struct ngx_http_upstream_srv_conf_s ngx_http_upstream_srv_conf_t;
62 typedef ngx_int_t (*ngx_http_upstream_init_pt)(ngx_conf_t *cf,
63 ngx_http_upstream_srv_conf_t *us);
64 typedef ngx_int_t (*ngx_http_upstream_init_peer_pt)(ngx_http_request_t *r,
65 ngx_http_upstream_srv_conf_t *us);
69 ngx_http_upstream_init_pt init_upstream;
70 ngx_http_upstream_init_peer_pt init;
72 } ngx_http_upstream_peer_t;
76 ngx_peer_addr_t *addrs;
84 } ngx_http_upstream_server_t;
87 #define NGX_HTTP_UPSTREAM_CREATE 0x0001
88 #define NGX_HTTP_UPSTREAM_WEIGHT 0x0002
89 #define NGX_HTTP_UPSTREAM_MAX_FAILS 0x0004
90 #define NGX_HTTP_UPSTREAM_FAIL_TIMEOUT 0x0008
91 #define NGX_HTTP_UPSTREAM_DOWN 0x0010
92 #define NGX_HTTP_UPSTREAM_BACKUP 0x0020
95 struct ngx_http_upstream_srv_conf_s {
96 ngx_http_upstream_peer_t peer;
99 ngx_array_t *servers; /* ngx_http_upstream_server_t */
106 in_port_t default_port;
111 ngx_http_upstream_srv_conf_t *upstream;
113 ngx_msec_t connect_timeout;
114 ngx_msec_t send_timeout;
115 ngx_msec_t read_timeout;
121 size_t busy_buffers_size;
122 size_t max_temp_file_size;
123 size_t temp_file_write_size;
125 size_t busy_buffers_size_conf;
126 size_t max_temp_file_size_conf;
127 size_t temp_file_write_size_conf;
129 ngx_uint_t next_upstream;
130 ngx_uint_t store_access;
134 ngx_flag_t buffering;
135 ngx_flag_t pass_request_headers;
136 ngx_flag_t pass_request_body;
138 ngx_flag_t ignore_client_abort;
139 ngx_flag_t intercept_errors;
140 ngx_flag_t cyclic_temp_file;
142 ngx_path_t *temp_path;
144 ngx_hash_t hide_headers_hash;
145 ngx_array_t *hide_headers;
146 ngx_array_t *pass_headers;
148 ngx_array_t *store_lengths;
149 ngx_array_t *store_values;
152 unsigned intercept_404:1;
153 unsigned change_buffering:1;
157 ngx_flag_t ssl_session_reuse;
160 } ngx_http_upstream_conf_t;
165 ngx_http_header_handler_pt handler;
167 ngx_http_header_handler_pt copy_handler;
169 ngx_uint_t redirect; /* unsigned redirect:1; */
170 } ngx_http_upstream_header_t;
177 ngx_str_t status_line;
179 ngx_table_elt_t *status;
180 ngx_table_elt_t *date;
181 ngx_table_elt_t *server;
182 ngx_table_elt_t *connection;
184 ngx_table_elt_t *expires;
185 ngx_table_elt_t *etag;
186 ngx_table_elt_t *x_accel_expires;
187 ngx_table_elt_t *x_accel_redirect;
188 ngx_table_elt_t *x_accel_limit_rate;
190 ngx_table_elt_t *content_type;
191 ngx_table_elt_t *content_length;
193 ngx_table_elt_t *last_modified;
194 ngx_table_elt_t *location;
195 ngx_table_elt_t *accept_ranges;
196 ngx_table_elt_t *www_authenticate;
199 ngx_table_elt_t *content_encoding;
202 off_t content_length_n;
204 ngx_array_t cache_control;
205 } ngx_http_upstream_headers_in_t;
211 ngx_uint_t no_port; /* unsigned no_port:1 */
216 struct sockaddr *sockaddr;
219 ngx_resolver_ctx_t *ctx;
220 } ngx_http_upstream_resolved_t;
223 typedef void (*ngx_http_upstream_handler_pt)(ngx_http_request_t *r,
224 ngx_http_upstream_t *u);
227 struct ngx_http_upstream_s {
228 ngx_http_upstream_handler_pt read_event_handler;
229 ngx_http_upstream_handler_pt write_event_handler;
231 ngx_peer_connection_t peer;
233 ngx_event_pipe_t *pipe;
235 ngx_chain_t *request_bufs;
237 ngx_output_chain_ctx_t output;
238 ngx_chain_writer_ctx_t writer;
240 ngx_http_upstream_conf_t *conf;
242 ngx_http_upstream_headers_in_t headers_in;
244 ngx_http_upstream_resolved_t *resolved;
249 ngx_chain_t *out_bufs;
250 ngx_chain_t *busy_bufs;
251 ngx_chain_t *free_bufs;
253 ngx_int_t (*input_filter_init)(void *data);
254 ngx_int_t (*input_filter)(void *data, ssize_t bytes);
255 void *input_filter_ctx;
257 ngx_int_t (*create_request)(ngx_http_request_t *r);
258 ngx_int_t (*reinit_request)(ngx_http_request_t *r);
259 ngx_int_t (*process_header)(ngx_http_request_t *r);
260 void (*abort_request)(ngx_http_request_t *r);
261 void (*finalize_request)(ngx_http_request_t *r,
263 ngx_int_t (*rewrite_redirect)(ngx_http_request_t *r,
264 ngx_table_elt_t *h, size_t prefix);
268 ngx_http_upstream_state_t *state;
274 ngx_http_cleanup_pt *cleanup;
277 unsigned cacheable:1;
281 unsigned buffering:1;
283 unsigned request_sent:1;
284 unsigned header_sent:1;
291 } ngx_http_upstream_next_t;
294 ngx_int_t ngx_http_upstream_header_variable(ngx_http_request_t *r,
295 ngx_http_variable_value_t *v, uintptr_t data);
297 void ngx_http_upstream_init(ngx_http_request_t *r);
298 ngx_http_upstream_srv_conf_t *ngx_http_upstream_add(ngx_conf_t *cf,
299 ngx_url_t *u, ngx_uint_t flags);
300 ngx_int_t ngx_http_upstream_hide_headers_hash(ngx_conf_t *cf,
301 ngx_http_upstream_conf_t *conf, ngx_http_upstream_conf_t *prev,
302 ngx_str_t *default_hide_headers, ngx_hash_init_t *hash);
305 #define ngx_http_conf_upstream_srv_conf(uscf, module) \
306 uscf->srv_conf[module.ctx_index]
309 extern ngx_module_t ngx_http_upstream_module;
312 #endif /* _NGX_HTTP_UPSTREAM_H_INCLUDED_ */