blob: 919a0afc34a285ff19fa11461bec54f7cec9d8fa [file] [log] [blame]
Igor Sysoev04410502003-08-01 14:56:33 +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_core.h>
7#include <ngx_event.h>
Igor Sysoev65977492003-11-02 22:56:18 +00008#include <ngx_event_connect.h>
9#include <ngx_event_pipe.h>
Igor Sysoev04410502003-08-01 14:56:33 +000010#include <ngx_http.h>
11
12
Igor Sysoevcf80a702003-11-03 22:20:44 +000013typedef enum {
14 NGX_HTTP_PROXY_CACHE_PASS = 1,
15 NGX_HTTP_PROXY_CACHE_BYPASS,
16 NGX_HTTP_PROXY_CACHE_AUTH,
17 NGX_HTTP_PROXY_CACHE_PGNC,
18 NGX_HTTP_PROXY_CACHE_MISS,
19 NGX_HTTP_PROXY_CACHE_EXPR,
20 NGX_HTTP_PROXY_CACHE_AGED,
21 NGX_HTTP_PROXY_CACHE_HIT
22} ngx_http_proxy_state_e;
23
24
25typedef enum {
26 NGX_HTTP_PROXY_CACHE_BPS = 1,
27 NGX_HTTP_PROXY_CACHE_XAE,
28 NGX_HTTP_PROXY_CACHE_CTL,
29 NGX_HTTP_PROXY_CACHE_EXP,
30 NGX_HTTP_PROXY_CACHE_MVD,
31 NGX_HTTP_PROXY_CACHE_LMF,
32 NGX_HTTP_PROXY_CACHE_PDE
33} ngx_http_proxy_reason_e;
34
35
Igor Sysoevae5c59c2003-08-14 06:00:28 +000036typedef struct {
Igor Sysoeva1512b12003-11-03 17:33:31 +000037 ngx_str_t url;
38 ngx_str_t host;
39 ngx_str_t uri;
40 ngx_str_t host_header;
41 ngx_str_t port_text;
42 ngx_str_t *location;
43 int port;
44} ngx_http_proxy_upstream_conf_t;
Igor Sysoevd404c972003-10-16 20:19:16 +000045
46
47typedef struct {
Igor Sysoeva1512b12003-11-03 17:33:31 +000048 ssize_t request_buffer_size;
49 ngx_msec_t connect_timeout;
50 ngx_msec_t send_timeout;
51 ssize_t header_buffer_size;
52 ngx_msec_t read_timeout;
Igor Sysoevd404c972003-10-16 20:19:16 +000053
Igor Sysoeva1512b12003-11-03 17:33:31 +000054 ngx_bufs_t bufs;
55 ssize_t busy_buffers_size;
Igor Sysoeve6779222003-10-03 15:50:53 +000056
Igor Sysoeva1512b12003-11-03 17:33:31 +000057 ssize_t max_temp_file_size;
58 ssize_t temp_file_write_size;
59 int cyclic_temp_file;
Igor Sysoev931a4002003-10-07 15:30:05 +000060
Igor Sysoeva1512b12003-11-03 17:33:31 +000061 int cache;
Igor Sysoevcf80a702003-11-03 22:20:44 +000062
Igor Sysoeva1512b12003-11-03 17:33:31 +000063 int pass_server;
Igor Sysoevcf80a702003-11-03 22:20:44 +000064 int pass_x_accel_expires;
65
66 int ignore_expires;
67 int lm_factor;
68 int default_expires;
Igor Sysoevab0c4f52003-10-28 15:45:41 +000069
Igor Sysoeva1512b12003-11-03 17:33:31 +000070 int next_upstream;
71 int use_stale;
Igor Sysoev10fc9ef2003-10-27 08:53:49 +000072
Igor Sysoeva1512b12003-11-03 17:33:31 +000073 ngx_path_t *cache_path;
74 ngx_path_t *temp_path;
Igor Sysoev931a4002003-10-07 15:30:05 +000075
Igor Sysoev9cc1ace2003-11-04 22:12:39 +000076 ngx_http_busy_lock_t *busy_lock;
77
Igor Sysoeva1512b12003-11-03 17:33:31 +000078 ngx_http_proxy_upstream_conf_t *upstream;
79 ngx_peers_t *peers;
Igor Sysoevae5c59c2003-08-14 06:00:28 +000080} ngx_http_proxy_loc_conf_t;
81
82
Igor Sysoeve6779222003-10-03 15:50:53 +000083typedef struct {
Igor Sysoevcf80a702003-11-03 22:20:44 +000084 ngx_http_proxy_state_e cache;
85 ngx_http_proxy_reason_e reason;
Igor Sysoeva1512b12003-11-03 17:33:31 +000086 int status;
87 ngx_str_t *peer;
Igor Sysoevfe0f5cc2003-10-31 16:05:33 +000088} ngx_http_proxy_state_t;
89
90
91typedef struct {
Igor Sysoeva1512b12003-11-03 17:33:31 +000092 ngx_table_t *headers; /* it must be first field */
Igor Sysoevb5faed22003-10-29 08:30:44 +000093
Igor Sysoeva1512b12003-11-03 17:33:31 +000094 ngx_table_elt_t *date;
95 ngx_table_elt_t *server;
Igor Sysoeve6779222003-10-03 15:50:53 +000096
Igor Sysoeva1512b12003-11-03 17:33:31 +000097 ngx_table_elt_t *expires;
98 ngx_table_elt_t *cache_control;
99 ngx_table_elt_t *x_accel_expires;
100
101 ngx_table_elt_t *connection;
102 ngx_table_elt_t *content_type;
103 ngx_table_elt_t *content_length;
104 ngx_table_elt_t *last_modified;
105 ngx_table_elt_t *accept_ranges;
106
107 off_t content_length_n;
Igor Sysoeve6779222003-10-03 15:50:53 +0000108} ngx_http_proxy_headers_in_t;
109
110
Igor Sysoev65977492003-11-02 22:56:18 +0000111typedef struct {
Igor Sysoeva1512b12003-11-03 17:33:31 +0000112 ngx_http_cache_ctx_t ctx;
113 int status;
114 ngx_str_t status_line;
115
116 ngx_http_proxy_headers_in_t headers_in;
Igor Sysoev65977492003-11-02 22:56:18 +0000117} ngx_http_proxy_cache_t;
118
119
Igor Sysoeva1512b12003-11-03 17:33:31 +0000120typedef struct {
121 ngx_peer_connection_t peer;
122 int status;
123 ngx_str_t status_line;
124 int method;
125
126 ngx_output_chain_ctx_t *output_chain_ctx;
127 ngx_event_pipe_t *event_pipe;
128
129 ngx_http_proxy_headers_in_t headers_in;
130} ngx_http_proxy_upstream_t;
131
132
Igor Sysoev04410502003-08-01 14:56:33 +0000133typedef struct ngx_http_proxy_ctx_s ngx_http_proxy_ctx_t;
134
135struct ngx_http_proxy_ctx_s {
Igor Sysoeve6779222003-10-03 15:50:53 +0000136 ngx_http_request_t *request;
137 ngx_http_proxy_loc_conf_t *lcf;
Igor Sysoeva1512b12003-11-03 17:33:31 +0000138 ngx_http_proxy_upstream_t *upstream;
Igor Sysoev65977492003-11-02 22:56:18 +0000139 ngx_http_proxy_cache_t *cache;
Igor Sysoev04410502003-08-01 14:56:33 +0000140
Igor Sysoev65977492003-11-02 22:56:18 +0000141 ngx_hunk_t *header_in;
Igor Sysoevae5c59c2003-08-14 06:00:28 +0000142
Igor Sysoeve8732b02003-11-05 17:03:41 +0000143 time_t busy_lock_time;
Igor Sysoev931a4002003-10-07 15:30:05 +0000144
Igor Sysoev65977492003-11-02 22:56:18 +0000145 unsigned accel:1;
146
147 unsigned cachable:1;
148 unsigned stale:1;
Igor Sysoev9cc1ace2003-11-04 22:12:39 +0000149 unsigned valid_header_in:1;
Igor Sysoev65977492003-11-02 22:56:18 +0000150
151 unsigned request_sent:1;
152 unsigned header_sent:1;
Igor Sysoev931a4002003-10-07 15:30:05 +0000153
Igor Sysoeva1512b12003-11-03 17:33:31 +0000154
Igor Sysoev1dd4ac82003-10-06 03:56:42 +0000155 /* used to parse an upstream HTTP header */
Igor Sysoeva1512b12003-11-03 17:33:31 +0000156 int status;
Igor Sysoev65977492003-11-02 22:56:18 +0000157 char *status_start;
158 char *status_end;
159 int status_count;
Igor Sysoevcf80a702003-11-03 22:20:44 +0000160 int parse_state;
Igor Sysoeve6779222003-10-03 15:50:53 +0000161
Igor Sysoevcf80a702003-11-03 22:20:44 +0000162 ngx_http_proxy_state_t *state;
Igor Sysoev65977492003-11-02 22:56:18 +0000163 ngx_array_t states; /* of ngx_http_proxy_state_t */
Igor Sysoevfe0f5cc2003-10-31 16:05:33 +0000164
Igor Sysoev65977492003-11-02 22:56:18 +0000165 char *action;
166 ngx_http_log_ctx_t *saved_ctx;
167 ngx_log_handler_pt saved_handler;
Igor Sysoev04410502003-08-01 14:56:33 +0000168};
169
170
Igor Sysoev65977492003-11-02 22:56:18 +0000171#define NGX_HTTP_PROXY_PARSE_NO_HEADER 20
172
Igor Sysoevcf80a702003-11-03 22:20:44 +0000173
Igor Sysoev65977492003-11-02 22:56:18 +0000174#define NGX_HTTP_PROXY_FT_ERROR 2
175#define NGX_HTTP_PROXY_FT_TIMEOUT 4
176#define NGX_HTTP_PROXY_FT_INVALID_HEADER 8
177#define NGX_HTTP_PROXY_FT_HTTP_500 16
178#define NGX_HTTP_PROXY_FT_HTTP_404 32
179#define NGX_HTTP_PROXY_FT_BUSY_LOCK 64
180#define NGX_HTTP_PROXY_FT_MAX_WAITING 128
181
182
Igor Sysoeva1512b12003-11-03 17:33:31 +0000183int ngx_http_proxy_request_upstream(ngx_http_proxy_ctx_t *p);
Igor Sysoev65977492003-11-02 22:56:18 +0000184
185int ngx_http_proxy_get_cached_response(ngx_http_proxy_ctx_t *p);
Igor Sysoev65977492003-11-02 22:56:18 +0000186int ngx_http_proxy_send_cached_response(ngx_http_proxy_ctx_t *p);
Igor Sysoevcf80a702003-11-03 22:20:44 +0000187int ngx_http_proxy_is_cachable(ngx_http_proxy_ctx_t *p);
Igor Sysoeva1512b12003-11-03 17:33:31 +0000188int ngx_http_proxy_update_cache(ngx_http_proxy_ctx_t *p);
189
Igor Sysoeva1512b12003-11-03 17:33:31 +0000190size_t ngx_http_proxy_log_error(void *data, char *buf, size_t len);
191void ngx_http_proxy_finalize_request(ngx_http_proxy_ctx_t *p, int rc);
Igor Sysoeve8732b02003-11-05 17:03:41 +0000192void ngx_http_proxy_close_connection(ngx_http_proxy_ctx_t *p);
Igor Sysoev65977492003-11-02 22:56:18 +0000193
194int ngx_http_proxy_parse_status_line(ngx_http_proxy_ctx_t *p);
195int ngx_http_proxy_copy_header(ngx_http_proxy_ctx_t *p,
196 ngx_http_proxy_headers_in_t *headers_in);
197
198
199
200extern ngx_module_t ngx_http_proxy_module;
201extern ngx_http_header_t ngx_http_proxy_headers_in[];
202
Igor Sysoev10fc9ef2003-10-27 08:53:49 +0000203
Igor Sysoeve6779222003-10-03 15:50:53 +0000204
Igor Sysoev04410502003-08-01 14:56:33 +0000205#endif /* _NGX_HTTP_PROXY_HANDLER_H_INCLUDED_ */