blob: 8c2a90193172a6c02b53228abedaf61b0927ea8c [file] [log] [blame]
Igor Sysoev02025fd2005-01-18 13:03:58 +00001
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
Igor Sysoevbb28b6d2006-07-11 13:20:19 +000019#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_503 0x00000020
24#define NGX_HTTP_UPSTREAM_FT_HTTP_404 0x00000040
25#define NGX_HTTP_UPSTREAM_FT_BUSY_LOCK 0x00000080
26#define NGX_HTTP_UPSTREAM_FT_MAX_WAITING 0x00000100
27#define NGX_HTTP_UPSTREAM_FT_OFF 0x80000000
Igor Sysoev02025fd2005-01-18 13:03:58 +000028
29
30#define NGX_HTTP_UPSTREAM_INVALID_HEADER 40
31
32
33typedef struct {
Igor Sysoevc2068d02005-10-19 12:33:58 +000034 ngx_msec_t bl_time;
Igor Sysoev899b44e2005-05-12 14:58:06 +000035 ngx_uint_t bl_state;
Igor Sysoev02025fd2005-01-18 13:03:58 +000036
Igor Sysoev899b44e2005-05-12 14:58:06 +000037 ngx_uint_t status;
Igor Sysoevc2068d02005-10-19 12:33:58 +000038 ngx_msec_t response_time;
39
Igor Sysoev899b44e2005-05-12 14:58:06 +000040 ngx_str_t *peer;
Igor Sysoev02025fd2005-01-18 13:03:58 +000041} ngx_http_upstream_state_t;
42
43
44typedef struct {
Igor Sysoev3338cfd2006-05-11 14:43:47 +000045 ngx_hash_t headers_in_hash;
Igor Sysoev6f134cc2006-05-23 14:54:58 +000046 ngx_array_t upstreams;
47 /* ngx_http_upstream_srv_conf_t */
Igor Sysoev899b44e2005-05-12 14:58:06 +000048} ngx_http_upstream_main_conf_t;
Igor Sysoev02025fd2005-01-18 13:03:58 +000049
Igor Sysoev02025fd2005-01-18 13:03:58 +000050
Igor Sysoev899b44e2005-05-12 14:58:06 +000051typedef struct {
Igor Sysoev6f134cc2006-05-23 14:54:58 +000052 ngx_peers_t *peers;
53
54 ngx_array_t *servers;
55
56 ngx_str_t host;
57 ngx_str_t file_name;
58 ngx_uint_t line;
59 in_port_t port;
Igor Sysoev6f134cc2006-05-23 14:54:58 +000060} ngx_http_upstream_srv_conf_t;
61
62
63typedef struct {
Igor Sysoev899b44e2005-05-12 14:58:06 +000064 ngx_msec_t connect_timeout;
65 ngx_msec_t send_timeout;
66 ngx_msec_t read_timeout;
Igor Sysoev5192b362005-07-08 14:34:20 +000067 ngx_msec_t timeout;
Igor Sysoev02025fd2005-01-18 13:03:58 +000068
Igor Sysoev899b44e2005-05-12 14:58:06 +000069 size_t send_lowat;
Igor Sysoevc31a9bb2005-11-26 10:11:11 +000070 size_t buffer_size;
Igor Sysoev187b7d92005-07-14 12:51:53 +000071
Igor Sysoev899b44e2005-05-12 14:58:06 +000072 size_t busy_buffers_size;
73 size_t max_temp_file_size;
74 size_t temp_file_write_size;
Igor Sysoev02025fd2005-01-18 13:03:58 +000075
Igor Sysoev187b7d92005-07-14 12:51:53 +000076 size_t busy_buffers_size_conf;
77 size_t max_temp_file_size_conf;
78 size_t temp_file_write_size_conf;
79
Igor Sysoev899b44e2005-05-12 14:58:06 +000080 ngx_uint_t next_upstream;
Igor Sysoev78452232005-10-12 13:50:36 +000081 ngx_uint_t max_fails;
82
83 time_t fail_timeout;
Igor Sysoev02025fd2005-01-18 13:03:58 +000084
Igor Sysoev899b44e2005-05-12 14:58:06 +000085 ngx_bufs_t bufs;
86
Igor Sysoevc31a9bb2005-11-26 10:11:11 +000087 ngx_flag_t buffering;
Igor Sysoev899b44e2005-05-12 14:58:06 +000088 ngx_flag_t pass_request_headers;
89 ngx_flag_t pass_request_body;
90
Igor Sysoev6d16e1e2006-04-05 13:40:54 +000091 ngx_flag_t ignore_client_abort;
Igor Sysoevef809b82006-06-28 16:00:26 +000092 ngx_flag_t intercept_errors;
Igor Sysoev899b44e2005-05-12 14:58:06 +000093 ngx_flag_t cyclic_temp_file;
94
Igor Sysoev899b44e2005-05-12 14:58:06 +000095 ngx_path_t *temp_path;
96
Igor Sysoev3338cfd2006-05-11 14:43:47 +000097 ngx_hash_t hide_headers_hash;
98 ngx_array_t *hide_headers;
99 ngx_array_t *pass_headers;
100
Igor Sysoev899b44e2005-05-12 14:58:06 +0000101 ngx_str_t schema;
102 ngx_str_t uri;
Igor Sysoev09c684b2005-11-09 17:25:55 +0000103 ngx_str_t location;
Igor Sysoev899b44e2005-05-12 14:58:06 +0000104 ngx_str_t url; /* used in proxy_rewrite_location */
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +0000105
Igor Sysoev3338cfd2006-05-11 14:43:47 +0000106 unsigned redirect_404:1;
107 unsigned change_buffering:1;
Igor Sysoevc31a9bb2005-11-26 10:11:11 +0000108
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +0000109#if (NGX_HTTP_SSL)
110 ngx_ssl_t *ssl;
111#endif
112
Igor Sysoev02025fd2005-01-18 13:03:58 +0000113} ngx_http_upstream_conf_t;
114
115
Igor Sysoev899b44e2005-05-12 14:58:06 +0000116typedef struct {
117 ngx_str_t name;
118 ngx_http_header_handler_pt handler;
119 ngx_uint_t offset;
120 ngx_http_header_handler_pt copy_handler;
121 ngx_uint_t conf;
Igor Sysoeve31e90b2005-05-19 13:25:22 +0000122 ngx_uint_t redirect; /* unsigned redirect:1; */
Igor Sysoev899b44e2005-05-12 14:58:06 +0000123} ngx_http_upstream_header_t;
124
125
126typedef struct {
127 ngx_list_t headers;
128
Igor Sysoev187b7d92005-07-14 12:51:53 +0000129 ngx_uint_t status_n;
130 ngx_str_t status_line;
131
Igor Sysoev899b44e2005-05-12 14:58:06 +0000132 ngx_table_elt_t *status;
133 ngx_table_elt_t *date;
134 ngx_table_elt_t *server;
135 ngx_table_elt_t *connection;
136
137 ngx_table_elt_t *expires;
138 ngx_table_elt_t *etag;
139 ngx_table_elt_t *x_accel_expires;
Igor Sysoeve31e90b2005-05-19 13:25:22 +0000140 ngx_table_elt_t *x_accel_redirect;
Igor Sysoev5192b362005-07-08 14:34:20 +0000141 ngx_table_elt_t *x_accel_limit_rate;
Igor Sysoev899b44e2005-05-12 14:58:06 +0000142
143 ngx_table_elt_t *content_type;
144 ngx_table_elt_t *content_length;
145
146 ngx_table_elt_t *last_modified;
147 ngx_table_elt_t *location;
148 ngx_table_elt_t *accept_ranges;
Igor Sysoev187b7d92005-07-14 12:51:53 +0000149 ngx_table_elt_t *www_authenticate;
Igor Sysoev899b44e2005-05-12 14:58:06 +0000150
151#if (NGX_HTTP_GZIP)
152 ngx_table_elt_t *content_encoding;
153#endif
154
155 ngx_array_t cache_control;
156} ngx_http_upstream_headers_in_t;
157
Igor Sysoev02025fd2005-01-18 13:03:58 +0000158
159struct ngx_http_upstream_s {
Igor Sysoev899b44e2005-05-12 14:58:06 +0000160 ngx_peer_connection_t peer;
Igor Sysoev02025fd2005-01-18 13:03:58 +0000161
Igor Sysoevc31a9bb2005-11-26 10:11:11 +0000162 ngx_event_pipe_t *pipe;
Igor Sysoev02025fd2005-01-18 13:03:58 +0000163
Igor Sysoev899b44e2005-05-12 14:58:06 +0000164 ngx_chain_t *request_bufs;
Igor Sysoev02025fd2005-01-18 13:03:58 +0000165
Igor Sysoev899b44e2005-05-12 14:58:06 +0000166 ngx_output_chain_ctx_t output;
167 ngx_chain_writer_ctx_t writer;
Igor Sysoev02025fd2005-01-18 13:03:58 +0000168
Igor Sysoev899b44e2005-05-12 14:58:06 +0000169 ngx_http_upstream_conf_t *conf;
Igor Sysoev02025fd2005-01-18 13:03:58 +0000170
Igor Sysoev899b44e2005-05-12 14:58:06 +0000171 ngx_http_upstream_headers_in_t headers_in;
Igor Sysoev02025fd2005-01-18 13:03:58 +0000172
Igor Sysoevc31a9bb2005-11-26 10:11:11 +0000173 ngx_buf_t buffer;
174 size_t length;
175
176 ngx_chain_t *out_bufs;
177 ngx_chain_t *busy_bufs;
178 ngx_chain_t *free_bufs;
179
180 ngx_int_t (*input_filter_init)(void *data);
181 ngx_int_t (*input_filter)(void *data, ssize_t bytes);
182 void *input_filter_ctx;
Igor Sysoev02025fd2005-01-18 13:03:58 +0000183
Igor Sysoev899b44e2005-05-12 14:58:06 +0000184 ngx_int_t (*create_request)(ngx_http_request_t *r);
185 ngx_int_t (*reinit_request)(ngx_http_request_t *r);
186 ngx_int_t (*process_header)(ngx_http_request_t *r);
187 void (*abort_request)(ngx_http_request_t *r);
188 void (*finalize_request)(ngx_http_request_t *r,
189 ngx_int_t rc);
190 ngx_int_t (*rewrite_redirect)(ngx_http_request_t *r,
191 ngx_table_elt_t *h, size_t prefix);
Igor Sysoev02025fd2005-01-18 13:03:58 +0000192
Igor Sysoev5192b362005-07-08 14:34:20 +0000193 ngx_msec_t timeout;
194
Igor Sysoev78452232005-10-12 13:50:36 +0000195 ngx_str_t method;
Igor Sysoev02025fd2005-01-18 13:03:58 +0000196
Igor Sysoev899b44e2005-05-12 14:58:06 +0000197 ngx_http_upstream_state_t *state;
198 ngx_array_t states; /* of ngx_http_upstream_state_t */
199
Igor Sysoeva2573672005-10-05 14:46:21 +0000200 ngx_str_t uri;
201
Igor Sysoev9ac946b2005-10-24 15:09:41 +0000202 ngx_http_cleanup_pt *cleanup;
203
Igor Sysoev899b44e2005-05-12 14:58:06 +0000204 unsigned cachable:1;
205 unsigned accel:1;
206
Igor Sysoev3338cfd2006-05-11 14:43:47 +0000207 unsigned buffering:1;
208
Igor Sysoev899b44e2005-05-12 14:58:06 +0000209 unsigned request_sent:1;
210 unsigned header_sent:1;
Igor Sysoev02025fd2005-01-18 13:03:58 +0000211};
212
213
214void ngx_http_upstream_init(ngx_http_request_t *r);
Igor Sysoev6f134cc2006-05-23 14:54:58 +0000215ngx_http_upstream_srv_conf_t *ngx_http_upstream_add(ngx_conf_t *cf,
216 ngx_url_t *u);
Igor Sysoev02025fd2005-01-18 13:03:58 +0000217
218
Igor Sysoev899b44e2005-05-12 14:58:06 +0000219extern ngx_module_t ngx_http_upstream_module;
220
Igor Sysoev02025fd2005-01-18 13:03:58 +0000221
222#endif /* _NGX_HTTP_UPSTREAM_H_INCLUDED_ */