Igor Sysoev | e2a3154 | 2003-04-08 15:40:10 +0000 | [diff] [blame] | 1 | #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 Sysoev | 9e4920b | 2003-04-14 17:04:58 +0000 | [diff] [blame] | 7 | #include <ngx_event_proxy.h> |
Igor Sysoev | e2a3154 | 2003-04-08 15:40:10 +0000 | [diff] [blame] | 8 | #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 | |
| 14 | typedef struct { |
Igor Sysoev | 183f9a6 | 2003-04-09 15:42:08 +0000 | [diff] [blame] | 15 | 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 Sysoev | e2a3154 | 2003-04-08 15:40:10 +0000 | [diff] [blame] | 23 | } ngx_http_proxy_headers_in_t; |
| 24 | |
| 25 | |
| 26 | typedef 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 | |
| 37 | typedef 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 | |
| 50 | typedef 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 | |
| 60 | typedef struct { |
| 61 | ngx_http_proxy_upstreams_t *upstreams; |
| 62 | ngx_http_proxy_upstream_url_t *upstream_url; |
| 63 | |
Igor Sysoev | a09f08d | 2003-04-25 14:43:13 +0000 | [diff] [blame] | 64 | int client_request_buffer_size; |
Igor Sysoev | e2a3154 | 2003-04-08 15:40:10 +0000 | [diff] [blame] | 65 | 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 Sysoev | 153d743 | 2003-04-15 15:06:52 +0000 | [diff] [blame] | 75 | int max_temp_file_size; |
Igor Sysoev | 6a7fd11 | 2003-04-17 17:59:35 +0000 | [diff] [blame] | 76 | int temp_file_write_size; |
Igor Sysoev | e2a3154 | 2003-04-08 15:40:10 +0000 | [diff] [blame] | 77 | |
Igor Sysoev | fd67586 | 2003-04-11 16:01:14 +0000 | [diff] [blame] | 78 | ngx_path_t *temp_path; |
| 79 | int temp_file_warn; |
| 80 | |
Igor Sysoev | e2a3154 | 2003-04-08 15:40:10 +0000 | [diff] [blame] | 81 | 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 | |
| 89 | typedef struct { |
| 90 | /* "/one/" */ |
| 91 | /* "http://localhost:9000/two/" */ |
| 92 | /* "/two/" */ |
| 93 | *upstream_farm; |
| 94 | } ngx_http_proxy_pass_t; |
| 95 | #endif |
| 96 | |
| 97 | |
| 98 | typedef struct ngx_http_proxy_ctx_s ngx_http_proxy_ctx_t; |
| 99 | |
| 100 | struct ngx_http_proxy_ctx_s { |
Igor Sysoev | 9e4920b | 2003-04-14 17:04:58 +0000 | [diff] [blame] | 101 | ngx_event_proxy_t *event_proxy; |
| 102 | |
Igor Sysoev | a09f08d | 2003-04-25 14:43:13 +0000 | [diff] [blame] | 103 | |
Igor Sysoev | fd67586 | 2003-04-11 16:01:14 +0000 | [diff] [blame] | 104 | ngx_chain_t *in_hunks; |
| 105 | ngx_chain_t *last_in_hunk; |
| 106 | |
Igor Sysoev | 9e4920b | 2003-04-14 17:04:58 +0000 | [diff] [blame] | 107 | ngx_chain_t *shadow_hunks; |
| 108 | |
Igor Sysoev | fd67586 | 2003-04-11 16:01:14 +0000 | [diff] [blame] | 109 | ngx_chain_t *out_hunks; |
| 110 | ngx_chain_t *last_out_hunk; |
| 111 | |
| 112 | ngx_chain_t *free_hunks; |
| 113 | |
Igor Sysoev | a09f08d | 2003-04-25 14:43:13 +0000 | [diff] [blame] | 114 | |
Igor Sysoev | fd67586 | 2003-04-11 16:01:14 +0000 | [diff] [blame] | 115 | ngx_chain_t *request_hunks; |
| 116 | |
Igor Sysoev | a09f08d | 2003-04-25 14:43:13 +0000 | [diff] [blame] | 117 | ngx_hunk_t *client_request_hunk; |
| 118 | ngx_hunk_t *client_first_part_hunk; |
| 119 | |
Igor Sysoev | fd67586 | 2003-04-11 16:01:14 +0000 | [diff] [blame] | 120 | 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 Sysoev | e2a3154 | 2003-04-08 15:40:10 +0000 | [diff] [blame] | 130 | |
| 131 | int last_hunk; |
| 132 | ngx_array_t hunks; |
Igor Sysoev | 183f9a6 | 2003-04-09 15:42:08 +0000 | [diff] [blame] | 133 | int nhunks; |
Igor Sysoev | e2a3154 | 2003-04-08 15:40:10 +0000 | [diff] [blame] | 134 | |
| 135 | int hunk_n; |
| 136 | |
Igor Sysoev | e2a3154 | 2003-04-08 15:40:10 +0000 | [diff] [blame] | 137 | 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 Sysoev | 183f9a6 | 2003-04-09 15:42:08 +0000 | [diff] [blame] | 165 | unsigned accel:1; |
| 166 | |
Igor Sysoev | e2a3154 | 2003-04-08 15:40:10 +0000 | [diff] [blame] | 167 | unsigned cached_connection:1; |
| 168 | }; |
| 169 | |
| 170 | |
| 171 | typedef struct { |
| 172 | char *action; |
| 173 | char *upstream; |
| 174 | char *client; |
| 175 | char *url; |
| 176 | } ngx_http_proxy_log_ctx_t; |
| 177 | |
| 178 | |
| 179 | extern ngx_module_t ngx_http_proxy_module; |
| 180 | |
| 181 | |
| 182 | static 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_ */ |