blob: ccdcae06deb94dc3e4c625b181c446b7bc6fd398 [file] [log] [blame]
Igor Sysoeve2a31542003-04-08 15:40:10 +00001#ifndef _NGX_HTTP_PROXY_HANDLER_H_INCLUDED_
2#define _NGX_HTTP_PROXY_HANDLER_H_INCLUDED_
3
4
5#include <ngx_config.h>
6#include <ngx_array.h>
Igor Sysoev9e4920b2003-04-14 17:04:58 +00007#include <ngx_event_proxy.h>
Igor Sysoeve2a31542003-04-08 15:40:10 +00008#include <ngx_http.h>
9
10
11#define NGX_HTTP_PROXY_PARSE_NO_HEADER 20
12#define NGX_HTTP_PARSE_TOO_LONG_STATUS_LINE 21
13
14typedef struct {
Igor Sysoev183f9a62003-04-09 15:42:08 +000015 ngx_table_elt_t *date;
16 ngx_table_elt_t *server;
17 ngx_table_elt_t *connection;
18 ngx_table_elt_t *content_type;
19 ngx_table_elt_t *content_length;
20 ngx_table_elt_t *last_modified;
21
22 ngx_table_t *headers;
Igor Sysoeve2a31542003-04-08 15:40:10 +000023} ngx_http_proxy_headers_in_t;
24
25
26typedef struct {
27 u_int32_t addr;
28 ngx_str_t host;
29 int port;
30 ngx_str_t addr_port_name;
31
32 int fails;
33 time_t accessed;
34} ngx_http_proxy_upstream_t;
35
36
37typedef struct {
38 int current;
39 int number;
40 int max_fails;
41 int fail_timeout;
42
43 /* ngx_mutex_t mutex; */
44 /* ngx_connection_t *cached; ??? */
45
46 ngx_http_proxy_upstream_t u[1];
47} ngx_http_proxy_upstreams_t;
48
49
50typedef struct {
51 ngx_str_t host;
52 ngx_str_t uri;
53 ngx_str_t *location;
54 ngx_str_t host_header;
55 ngx_str_t port_name;
56 int port;
57} ngx_http_proxy_upstream_url_t;
58
59
60typedef struct {
61 ngx_http_proxy_upstreams_t *upstreams;
62 ngx_http_proxy_upstream_url_t *upstream_url;
63
Igor Sysoeva09f08d2003-04-25 14:43:13 +000064 int client_request_buffer_size;
Igor Sysoeve2a31542003-04-08 15:40:10 +000065 int rcvbuf;
66 int conn_pool_size;
67 int connect_timeout;
68 int send_timeout;
69 int read_timeout;
70 int header_size;
71 int large_header;
72
73 int block_size;
74 int max_block_size;
Igor Sysoev153d7432003-04-15 15:06:52 +000075 int max_temp_file_size;
Igor Sysoev6a7fd112003-04-17 17:59:35 +000076 int temp_file_write_size;
Igor Sysoeve2a31542003-04-08 15:40:10 +000077
Igor Sysoevfd675862003-04-11 16:01:14 +000078 ngx_path_t *temp_path;
79 int temp_file_warn;
80
Igor Sysoeve2a31542003-04-08 15:40:10 +000081 int retry_500_error;
82
83} ngx_http_proxy_loc_conf_t;
84
85
86#if 0
87/* location /one/ { proxy_pass http://localhost:9000/two/; } */
88
89typedef struct {
90 /* "/one/" */
91 /* "http://localhost:9000/two/" */
92 /* "/two/" */
93 *upstream_farm;
94} ngx_http_proxy_pass_t;
95#endif
96
97
98typedef struct ngx_http_proxy_ctx_s ngx_http_proxy_ctx_t;
99
100struct ngx_http_proxy_ctx_s {
Igor Sysoev9e4920b2003-04-14 17:04:58 +0000101 ngx_event_proxy_t *event_proxy;
102
Igor Sysoeva09f08d2003-04-25 14:43:13 +0000103
Igor Sysoevfd675862003-04-11 16:01:14 +0000104 ngx_chain_t *in_hunks;
105 ngx_chain_t *last_in_hunk;
106
Igor Sysoev9e4920b2003-04-14 17:04:58 +0000107 ngx_chain_t *shadow_hunks;
108
Igor Sysoevfd675862003-04-11 16:01:14 +0000109 ngx_chain_t *out_hunks;
110 ngx_chain_t *last_out_hunk;
111
112 ngx_chain_t *free_hunks;
113
Igor Sysoeva09f08d2003-04-25 14:43:13 +0000114
Igor Sysoevfd675862003-04-11 16:01:14 +0000115 ngx_chain_t *request_hunks;
116
Igor Sysoeva09f08d2003-04-25 14:43:13 +0000117 ngx_hunk_t *client_request_hunk;
118 ngx_hunk_t *client_first_part_hunk;
119
Igor Sysoevfd675862003-04-11 16:01:14 +0000120 ngx_connection_t *connection;
121 ngx_http_request_t *request;
122 ngx_http_proxy_headers_in_t headers_in;
123
124
125 int block_size;
126 int allocated;
127
128 ngx_file_t *temp_file;
129 off_t temp_offset;
Igor Sysoeve2a31542003-04-08 15:40:10 +0000130
131 int last_hunk;
132 ngx_array_t hunks;
Igor Sysoev183f9a62003-04-09 15:42:08 +0000133 int nhunks;
Igor Sysoeve2a31542003-04-08 15:40:10 +0000134
135 int hunk_n;
136
Igor Sysoeve2a31542003-04-08 15:40:10 +0000137 ngx_http_proxy_upstream_url_t *upstream_url;
138 ngx_http_proxy_upstreams_t *upstreams;
139 int cur_upstream;
140 int tries;
141
142 struct sockaddr *sockaddr;
143
144 ngx_http_proxy_loc_conf_t *lcf;
145
146 ngx_log_t *log;
147
148 int method;
149
150 ngx_hunk_t *header_in;
151 int status;
152 ngx_str_t status_line;
153 ngx_str_t full_status_line;
154
155 int state;
156 int status_count;
157 char *status_start;
158 char *status_end;
159 int (*state_write_upstream_handler) (ngx_http_proxy_ctx_t *p);
160 int (*state_read_upstream_handler) (ngx_http_proxy_ctx_t *p);
161 int (*state_handler)(ngx_http_proxy_ctx_t *p);
162
163 int last_error;
164
Igor Sysoev183f9a62003-04-09 15:42:08 +0000165 unsigned accel:1;
166
Igor Sysoeve2a31542003-04-08 15:40:10 +0000167 unsigned cached_connection:1;
168};
169
170
171typedef struct {
172 char *action;
173 char *upstream;
174 char *client;
175 char *url;
176} ngx_http_proxy_log_ctx_t;
177
178
179extern ngx_module_t ngx_http_proxy_module;
180
181
182static int ngx_http_proxy_error(ngx_http_request_t *r, ngx_http_proxy_ctx_t *p,
183 int error);
184
185
186#endif /* _NGX_HTTP_PROXY_HANDLER_H_INCLUDED_ */