blob: bdb3a4a76a34ed9e61b585f8cb8be45356487b30 [file] [log] [blame]
Igor Sysoevd90282d2004-09-28 08:34:51 +00001
2/*
Igor Sysoevff8da912004-09-29 16:00:49 +00003 * Copyright (C) Igor Sysoev
Igor Sysoevd90282d2004-09-28 08:34:51 +00004 */
5
6
Igor Sysoev4e9393a2003-01-09 05:36:00 +00007#ifndef _NGX_HTTP_CORE_H_INCLUDED_
8#define _NGX_HTTP_CORE_H_INCLUDED_
9
10
11#include <ngx_string.h>
12#include <ngx_array.h>
13#include <ngx_http.h>
14
15
16typedef struct {
Igor Sysoevb145b062005-06-15 18:33:41 +000017 unsigned default_server:1;
18 unsigned bind:1;
19
20 int backlog;
Igor Sysoevc2068d02005-10-19 12:33:58 +000021 int rcvbuf;
22 int sndbuf;
Igor Sysoevb145b062005-06-15 18:33:41 +000023
24#if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER)
25 char *accept_filter;
26#endif
27#if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT)
28 ngx_uint_t deferred_accept;
29#endif
30
Igor Sysoev94e32ce2006-04-07 14:08:04 +000031 u_char addr[INET_ADDRSTRLEN + 6];
32
Igor Sysoevb145b062005-06-15 18:33:41 +000033} ngx_http_listen_conf_t;
34
35
36typedef struct {
Igor Sysoevb1dfe472004-12-21 12:30:30 +000037 in_addr_t addr;
38 in_port_t port;
39 int family;
Igor Sysoevb145b062005-06-15 18:33:41 +000040
Igor Sysoevb1dfe472004-12-21 12:30:30 +000041 ngx_str_t file_name;
42 ngx_int_t line;
Igor Sysoev10a543a2004-03-16 07:10:12 +000043
Igor Sysoevb145b062005-06-15 18:33:41 +000044 ngx_http_listen_conf_t conf;
Igor Sysoev4e9393a2003-01-09 05:36:00 +000045} ngx_http_listen_t;
46
47
Igor Sysoev865c1502003-11-30 20:03:18 +000048typedef enum {
Igor Sysoev09c684b2005-11-09 17:25:55 +000049 NGX_HTTP_POST_READ_PHASE = 0,
Igor Sysoev59f3aa32004-06-24 16:07:04 +000050
Igor Sysoev09c684b2005-11-09 17:25:55 +000051 NGX_HTTP_SERVER_REWRITE_PHASE,
Igor Sysoevda173ab2006-08-30 10:39:17 +000052
Igor Sysoev09c684b2005-11-09 17:25:55 +000053 NGX_HTTP_FIND_CONFIG_PHASE,
Igor Sysoev1ebfead2005-02-16 13:40:36 +000054 NGX_HTTP_REWRITE_PHASE,
Igor Sysoevda173ab2006-08-30 10:39:17 +000055 NGX_HTTP_POST_REWRITE_PHASE,
Igor Sysoev59f3aa32004-06-24 16:07:04 +000056
Igor Sysoevc31a9bb2005-11-26 10:11:11 +000057 NGX_HTTP_PREACCESS_PHASE,
58
Igor Sysoev59f3aa32004-06-24 16:07:04 +000059 NGX_HTTP_ACCESS_PHASE,
Igor Sysoevda173ab2006-08-30 10:39:17 +000060 NGX_HTTP_POST_ACCESS_PHASE,
61
Igor Sysoev865c1502003-11-30 20:03:18 +000062 NGX_HTTP_CONTENT_PHASE,
Igor Sysoev59f3aa32004-06-24 16:07:04 +000063
Igor Sysoevc31a9bb2005-11-26 10:11:11 +000064 NGX_HTTP_LOG_PHASE
Igor Sysoev865c1502003-11-30 20:03:18 +000065} ngx_http_phases;
66
Igor Sysoevda173ab2006-08-30 10:39:17 +000067typedef struct ngx_http_phase_handler_s ngx_http_phase_handler_t;
68
69typedef ngx_int_t (*ngx_http_phase_handler_pt)(ngx_http_request_t *r,
70 ngx_http_phase_handler_t *ph);
71
72struct ngx_http_phase_handler_s {
73 ngx_http_phase_handler_pt checker;
74 ngx_http_handler_pt handler;
75 ngx_uint_t next;
76};
77
78
79typedef struct {
80 ngx_http_phase_handler_t *handlers;
81 ngx_uint_t server_rewrite_index;
82} ngx_http_phase_engine_t;
83
Igor Sysoev865c1502003-11-30 20:03:18 +000084
Igor Sysoev4e9393a2003-01-09 05:36:00 +000085typedef struct {
Igor Sysoevb1dfe472004-12-21 12:30:30 +000086 ngx_array_t handlers;
Igor Sysoevb3e73d82003-10-10 15:10:50 +000087} ngx_http_phase_t;
88
Igor Sysoevb3e73d82003-10-10 15:10:50 +000089
90typedef struct {
Igor Sysoev805d9db2005-02-03 19:33:37 +000091 ngx_array_t servers; /* ngx_http_core_srv_conf_t */
Igor Sysoevb3e73d82003-10-10 15:10:50 +000092
Igor Sysoevda173ab2006-08-30 10:39:17 +000093 ngx_http_phase_engine_t phase_engine;
Igor Sysoevb1af9bb2004-06-25 14:42:03 +000094
Igor Sysoev3338cfd2006-05-11 14:43:47 +000095 ngx_hash_t headers_in_hash;
Igor Sysoevffe71442006-02-08 15:33:12 +000096
97 ngx_hash_t variables_hash;
98
99 ngx_array_t variables; /* ngx_http_variable_t */
Igor Sysoev02f742b2005-04-08 15:18:55 +0000100
Igor Sysoev305a9d82005-12-26 17:07:48 +0000101 ngx_uint_t server_names_hash_max_size;
102 ngx_uint_t server_names_hash_bucket_size;
Igor Sysoev805d9db2005-02-03 19:33:37 +0000103
Igor Sysoevffe71442006-02-08 15:33:12 +0000104 ngx_uint_t variables_hash_max_size;
105 ngx_uint_t variables_hash_bucket_size;
106
107 ngx_hash_keys_arrays_t *variables_keys;
Igor Sysoevda173ab2006-08-30 10:39:17 +0000108
109 ngx_http_phase_t phases[NGX_HTTP_LOG_PHASE + 1];
Igor Sysoevbb4ec5c2003-05-16 15:27:48 +0000110} ngx_http_core_main_conf_t;
111
112
113typedef struct {
Igor Sysoev1c3567e2004-07-15 16:35:51 +0000114 /*
Igor Sysoevc31a9bb2005-11-26 10:11:11 +0000115 * array of the ngx_http_core_loc_conf_t *,
116 * used in the ngx_http_core_find_location() and in the merge phase
Igor Sysoev1c3567e2004-07-15 16:35:51 +0000117 */
Igor Sysoevb1dfe472004-12-21 12:30:30 +0000118 ngx_array_t locations;
Igor Sysoeva9830112003-05-19 16:39:14 +0000119
Igor Sysoev805d9db2005-02-03 19:33:37 +0000120 /* array of the ngx_http_listen_t, "listen" directive */
Igor Sysoevb1dfe472004-12-21 12:30:30 +0000121 ngx_array_t listen;
Igor Sysoev187fcd82003-05-23 11:53:01 +0000122
Igor Sysoev805d9db2005-02-03 19:33:37 +0000123 /* array of the ngx_http_server_name_t, "server_name" directive */
Igor Sysoevb1dfe472004-12-21 12:30:30 +0000124 ngx_array_t server_names;
Igor Sysoev10a543a2004-03-16 07:10:12 +0000125
Igor Sysoev1c3567e2004-07-15 16:35:51 +0000126 /* server ctx */
Igor Sysoevb1dfe472004-12-21 12:30:30 +0000127 ngx_http_conf_ctx_t *ctx;
Igor Sysoev10a543a2004-03-16 07:10:12 +0000128
Igor Sysoev305a9d82005-12-26 17:07:48 +0000129 ngx_str_t server_name;
130
Igor Sysoevb1dfe472004-12-21 12:30:30 +0000131 size_t connection_pool_size;
132 size_t request_pool_size;
133 size_t client_header_buffer_size;
Igor Sysoev3043bfc2004-05-14 16:51:47 +0000134
Igor Sysoevb1dfe472004-12-21 12:30:30 +0000135 ngx_bufs_t large_client_header_buffers;
Igor Sysoev85080d02004-09-22 16:18:21 +0000136
Igor Sysoevb1dfe472004-12-21 12:30:30 +0000137 ngx_msec_t client_header_timeout;
Igor Sysoev1c3567e2004-07-15 16:35:51 +0000138
Igor Sysoev8290d282006-02-03 12:58:48 +0000139 ngx_flag_t optimize_server_names;
Igor Sysoev3362b8d2005-05-14 18:42:03 +0000140 ngx_flag_t ignore_invalid_headers;
Igor Sysoev1765f472006-07-07 16:33:19 +0000141
142 ngx_uint_t wildcard; /* unsigned wildcard:1 */
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000143} ngx_http_core_srv_conf_t;
144
145
Igor Sysoevfe5cb6b2003-01-29 07:25:51 +0000146/* list of structures to find core_srv_conf quickly at run time */
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000147
Igor Sysoev305a9d82005-12-26 17:07:48 +0000148
149typedef struct {
150 in_addr_t addr;
151 /* the default server configuration for this address:port */
152 ngx_http_core_srv_conf_t *core_srv_conf;
153 ngx_http_virtual_names_t *virtual_names;
154} ngx_http_in_addr_t;
155
156
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000157typedef struct {
Igor Sysoevb1dfe472004-12-21 12:30:30 +0000158 in_port_t port;
159 ngx_str_t port_text;
Igor Sysoev305a9d82005-12-26 17:07:48 +0000160 ngx_http_in_addr_t *addrs;
161 ngx_uint_t naddrs;
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000162} ngx_http_in_port_t;
163
Igor Sysoev6ddfbf02003-05-15 15:42:53 +0000164
Igor Sysoev305a9d82005-12-26 17:07:48 +0000165typedef struct {
166 in_port_t port;
167 ngx_array_t addrs; /* array of ngx_http_conf_in_addr_t */
168} ngx_http_conf_in_port_t;
169
170
171typedef struct {
Igor Sysoeva8fa0a62003-11-25 20:44:56 +0000172 in_addr_t addr;
Igor Sysoevb1dfe472004-12-21 12:30:30 +0000173
Igor Sysoev305a9d82005-12-26 17:07:48 +0000174 ngx_hash_t hash;
175 ngx_hash_wildcard_t *dns_wildcards;
176
177 ngx_array_t names; /* array of ngx_http_server_name_t */
Igor Sysoevb1dfe472004-12-21 12:30:30 +0000178
179 /* the default server configuration for this address:port */
180 ngx_http_core_srv_conf_t *core_srv_conf;
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000181
Igor Sysoev305a9d82005-12-26 17:07:48 +0000182 unsigned default_server:1;
183 unsigned bind:1;
184
185 ngx_http_listen_conf_t *listen_conf;
186} ngx_http_conf_in_addr_t;
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000187
Igor Sysoev6ddfbf02003-05-15 15:42:53 +0000188
Igor Sysoevfe5cb6b2003-01-29 07:25:51 +0000189typedef struct {
190 ngx_str_t name;
191 ngx_http_core_srv_conf_t *core_srv_conf; /* virtual name server conf */
192} ngx_http_server_name_t;
193
194
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000195typedef struct {
Igor Sysoev08e63d42006-08-14 15:09:38 +0000196 ngx_int_t status;
197 ngx_int_t overwrite;
198 ngx_str_t uri;
199 ngx_array_t *uri_lengths;
200 ngx_array_t *uri_values;
Igor Sysoev74e95c22003-11-09 20:03:38 +0000201} ngx_http_err_page_t;
202
203
Igor Sysoev74a5ddb2004-07-18 19:11:20 +0000204typedef struct ngx_http_core_loc_conf_s ngx_http_core_loc_conf_t;
205
206struct ngx_http_core_loc_conf_s {
Igor Sysoev6253ca12003-05-27 12:18:54 +0000207 ngx_str_t name; /* location name */
Igor Sysoev74a5ddb2004-07-18 19:11:20 +0000208
Igor Sysoevc0edbcc2004-10-21 15:34:38 +0000209#if (NGX_PCRE)
Igor Sysoev74a5ddb2004-07-18 19:11:20 +0000210 ngx_regex_t *regex;
211#endif
212
Igor Sysoev805d9db2005-02-03 19:33:37 +0000213 unsigned noname:1; /* "if () {}" block */
214
Igor Sysoev74a5ddb2004-07-18 19:11:20 +0000215 unsigned exact_match:1;
Igor Sysoevd43bee82004-11-20 19:52:20 +0000216 unsigned noregex:1;
217
Igor Sysoev74a5ddb2004-07-18 19:11:20 +0000218 unsigned auto_redirect:1;
219 unsigned alias:1;
220
221 /* array of inclusive ngx_http_core_loc_conf_t */
222 ngx_array_t locations;
223
224 /* pointer to the modules' loc_conf */
225 void **loc_conf ;
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000226
Igor Sysoev94e32ce2006-04-07 14:08:04 +0000227 uint32_t limit_except;
228 void **limit_except_loc_conf ;
229
Igor Sysoev2f657222004-06-16 15:32:11 +0000230 ngx_http_handler_pt handler;
Igor Sysoeve2a31542003-04-08 15:40:10 +0000231
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +0000232 ngx_str_t root; /* root, alias */
233 ngx_str_t post_action;
234
Igor Sysoev3ca233e2005-12-28 14:23:52 +0000235 ngx_array_t *root_lengths;
236 ngx_array_t *root_values;
237
Igor Sysoev24025022005-12-16 15:07:08 +0000238 ngx_array_t *types;
239 ngx_hash_t types_hash;
240 ngx_str_t default_type;
241
Igor Sysoev1765f472006-07-07 16:33:19 +0000242 off_t client_max_body_size; /* client_max_body_size */
243
Igor Sysoevdbb27762004-04-01 16:20:53 +0000244 size_t client_body_buffer_size; /* client_body_buffer_size */
Igor Sysoevef066482004-06-21 15:59:32 +0000245 size_t send_lowat; /* send_lowat */
Igor Sysoev7823cc32004-07-14 16:01:42 +0000246 size_t postpone_output; /* postpone_output */
247 size_t limit_rate; /* limit_rate */
Igor Sysoev10a543a2004-03-16 07:10:12 +0000248
Igor Sysoev2b0c76c2003-10-27 21:01:00 +0000249 ngx_msec_t client_body_timeout; /* client_body_timeout */
Igor Sysoev6253ca12003-05-27 12:18:54 +0000250 ngx_msec_t send_timeout; /* send_timeout */
Igor Sysoev6253ca12003-05-27 12:18:54 +0000251 ngx_msec_t keepalive_timeout; /* keepalive_timeout */
252 ngx_msec_t lingering_time; /* lingering_time */
253 ngx_msec_t lingering_timeout; /* lingering_timeout */
Igor Sysoeve2a31542003-04-08 15:40:10 +0000254
Igor Sysoevf7abd722004-09-23 06:32:00 +0000255 time_t keepalive_header; /* keepalive_timeout */
256
Igor Sysoev31eb8c02005-09-23 11:02:22 +0000257 ngx_flag_t satisfy_any; /* satisfy_any */
Igor Sysoev899b44e2005-05-12 14:58:06 +0000258 ngx_flag_t internal; /* internal */
Igor Sysoev8a2b2fb2006-04-14 09:53:38 +0000259 ngx_flag_t client_body_in_file_only; /* client_body_in_file_only */
Igor Sysoev10a543a2004-03-16 07:10:12 +0000260 ngx_flag_t sendfile; /* sendfile */
261 ngx_flag_t tcp_nopush; /* tcp_nopush */
Igor Sysoev924bd792004-10-11 15:07:03 +0000262 ngx_flag_t tcp_nodelay; /* tcp_nodelay */
Igor Sysoev0ab91b92004-06-06 19:49:18 +0000263 ngx_flag_t reset_timedout_connection; /* reset_timedout_connection */
Igor Sysoev7b190b42005-06-07 15:56:31 +0000264 ngx_flag_t port_in_redirect; /* port_in_redirect */
Igor Sysoev10a543a2004-03-16 07:10:12 +0000265 ngx_flag_t msie_padding; /* msie_padding */
Igor Sysoev3f8dc592006-08-28 16:57:48 +0000266 ngx_flag_t msie_refresh; /* msie_refresh */
Igor Sysoev5192b362005-07-08 14:34:20 +0000267 ngx_flag_t log_not_found; /* log_not_found */
Igor Sysoev3f8dc592006-08-28 16:57:48 +0000268 ngx_flag_t recursive_error_pages; /* recursive_error_pages */
Igor Sysoev10a543a2004-03-16 07:10:12 +0000269
Igor Sysoev74e95c22003-11-09 20:03:38 +0000270 ngx_array_t *error_pages; /* error_page */
Igor Sysoev12b4b002003-10-24 06:53:41 +0000271
Igor Sysoev02025fd2005-01-18 13:03:58 +0000272 ngx_path_t *client_body_temp_path; /* client_body_temp_path */
273
Igor Sysoev865c1502003-11-30 20:03:18 +0000274 ngx_http_cache_hash_t *open_files;
275
Igor Sysoev9d639522003-07-07 06:11:50 +0000276 ngx_log_t *err_log;
Igor Sysoev74a5ddb2004-07-18 19:11:20 +0000277
Igor Sysoev24025022005-12-16 15:07:08 +0000278 ngx_uint_t types_hash_max_size;
279 ngx_uint_t types_hash_bucket_size;
280
Igor Sysoev805d9db2005-02-03 19:33:37 +0000281#if 0
Igor Sysoev74a5ddb2004-07-18 19:11:20 +0000282 ngx_http_core_loc_conf_t *prev_location;
Igor Sysoev805d9db2005-02-03 19:33:37 +0000283#endif
Igor Sysoev74a5ddb2004-07-18 19:11:20 +0000284};
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000285
286
Igor Sysoevda173ab2006-08-30 10:39:17 +0000287void ngx_http_core_run_phases(ngx_http_request_t *r);
288ngx_int_t ngx_http_core_generic_phase(ngx_http_request_t *r,
289 ngx_http_phase_handler_t *ph);
290ngx_int_t ngx_http_core_find_config_phase(ngx_http_request_t *r,
291 ngx_http_phase_handler_t *ph);
292ngx_int_t ngx_http_core_post_rewrite_phase(ngx_http_request_t *r,
293 ngx_http_phase_handler_t *ph);
294ngx_int_t ngx_http_core_access_phase(ngx_http_request_t *r,
295 ngx_http_phase_handler_t *ph);
296ngx_int_t ngx_http_core_post_access_phase(ngx_http_request_t *r,
297 ngx_http_phase_handler_t *ph);
298ngx_int_t ngx_http_core_content_phase(ngx_http_request_t *r,
299 ngx_http_phase_handler_t *ph);
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000300
Igor Sysoev865c1502003-11-30 20:03:18 +0000301ngx_int_t ngx_http_set_content_type(ngx_http_request_t *r);
Igor Sysoev3b30a902003-12-25 20:26:58 +0000302ngx_int_t ngx_http_set_exten(ngx_http_request_t *r);
Igor Sysoev208eed22005-10-07 13:30:52 +0000303u_char *ngx_http_map_uri_to_path(ngx_http_request_t *r, ngx_str_t *name,
Igor Sysoev0e5f86d2006-10-12 13:36:54 +0000304 size_t *root_length, size_t reserved);
Igor Sysoevceb99292005-09-06 16:09:32 +0000305ngx_int_t ngx_http_auth_basic_user(ngx_http_request_t *r);
Igor Sysoev865c1502003-11-30 20:03:18 +0000306
Igor Sysoev899b44e2005-05-12 14:58:06 +0000307ngx_int_t ngx_http_subrequest(ngx_http_request_t *r,
Igor Sysoev9fcccaf2006-10-10 14:30:39 +0000308 ngx_str_t *uri, ngx_str_t *args, ngx_http_request_t **sr,
Igor Sysoev960100e2006-10-13 15:20:10 +0000309 ngx_http_post_subrequest_t *psr, ngx_uint_t flags);
Igor Sysoev2f657222004-06-16 15:32:11 +0000310ngx_int_t ngx_http_internal_redirect(ngx_http_request_t *r,
Igor Sysoev8184d1b2005-03-04 14:06:57 +0000311 ngx_str_t *uri, ngx_str_t *args);
Igor Sysoev805d9db2005-02-03 19:33:37 +0000312
Igor Sysoev9ac946b2005-10-24 15:09:41 +0000313ngx_http_cleanup_t *ngx_http_cleanup_add(ngx_http_request_t *r, size_t size);
314
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000315
Igor Sysoev2f657222004-06-16 15:32:11 +0000316typedef ngx_int_t (*ngx_http_output_header_filter_pt)(ngx_http_request_t *r);
317typedef ngx_int_t (*ngx_http_output_body_filter_pt)
Igor Sysoev8184d1b2005-03-04 14:06:57 +0000318 (ngx_http_request_t *r, ngx_chain_t *chain);
Igor Sysoev0ab91b92004-06-06 19:49:18 +0000319
320
Igor Sysoev2f657222004-06-16 15:32:11 +0000321ngx_int_t ngx_http_output_filter(ngx_http_request_t *r, ngx_chain_t *chain);
322ngx_int_t ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *chain);
Igor Sysoev0ab91b92004-06-06 19:49:18 +0000323
324
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +0000325extern ngx_module_t ngx_http_core_module;
326
327extern ngx_uint_t ngx_http_max_module;
328
329
330#define ngx_http_clear_content_length(r) \
331 \
332 r->headers_out.content_length_n = -1; \
333 if (r->headers_out.content_length) { \
334 r->headers_out.content_length->hash = 0; \
335 r->headers_out.content_length = NULL; \
336 }
337 \
338#define ngx_http_clear_accept_ranges(r) \
339 \
Igor Sysoevc31a9bb2005-11-26 10:11:11 +0000340 r->allow_ranges = 0; \
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +0000341 if (r->headers_out.accept_ranges) { \
342 r->headers_out.accept_ranges->hash = 0 ; \
343 r->headers_out.accept_ranges = NULL; \
344 }
345
346#define ngx_http_clear_last_modified(r) \
347 \
348 r->headers_out.last_modified_time = -1; \
349 if (r->headers_out.last_modified) { \
350 r->headers_out.last_modified->hash = 0; \
351 r->headers_out.last_modified = NULL; \
352 }
353
354
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000355#endif /* _NGX_HTTP_CORE_H_INCLUDED_ */