nginx 0.7.8
[nginx-catap.git] / src / http / ngx_http_core_module.h
blob3ecc7c33aeb6781e131a0c38ffe83d8e558b57f5
2 /*
3 * Copyright (C) Igor Sysoev
4 */
7 #ifndef _NGX_HTTP_CORE_H_INCLUDED_
8 #define _NGX_HTTP_CORE_H_INCLUDED_
11 #include <ngx_string.h>
12 #include <ngx_array.h>
13 #include <ngx_http.h>
16 #define NGX_HTTP_GZIP_PROXIED_OFF 0x0002
17 #define NGX_HTTP_GZIP_PROXIED_EXPIRED 0x0004
18 #define NGX_HTTP_GZIP_PROXIED_NO_CACHE 0x0008
19 #define NGX_HTTP_GZIP_PROXIED_NO_STORE 0x0010
20 #define NGX_HTTP_GZIP_PROXIED_PRIVATE 0x0020
21 #define NGX_HTTP_GZIP_PROXIED_NO_LM 0x0040
22 #define NGX_HTTP_GZIP_PROXIED_NO_ETAG 0x0080
23 #define NGX_HTTP_GZIP_PROXIED_AUTH 0x0100
24 #define NGX_HTTP_GZIP_PROXIED_ANY 0x0200
27 #define NGX_HTTP_SATISFY_ALL 0
28 #define NGX_HTTP_SATISFY_ANY 1
31 typedef struct ngx_http_location_tree_node_s ngx_http_location_tree_node_t;
32 typedef struct ngx_http_core_loc_conf_s ngx_http_core_loc_conf_t;
35 typedef struct {
36 unsigned default_server:1;
37 unsigned bind:1;
39 int backlog;
40 int rcvbuf;
41 int sndbuf;
43 #if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER)
44 char *accept_filter;
45 #endif
46 #if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT)
47 ngx_uint_t deferred_accept;
48 #endif
50 u_char addr[INET_ADDRSTRLEN + 6];
52 } ngx_http_listen_conf_t;
55 typedef struct {
56 in_addr_t addr;
57 in_port_t port;
58 int family;
60 u_char *file_name;
61 ngx_uint_t line;
63 ngx_http_listen_conf_t conf;
64 } ngx_http_listen_t;
67 typedef enum {
68 NGX_HTTP_POST_READ_PHASE = 0,
70 NGX_HTTP_SERVER_REWRITE_PHASE,
72 NGX_HTTP_FIND_CONFIG_PHASE,
73 NGX_HTTP_REWRITE_PHASE,
74 NGX_HTTP_POST_REWRITE_PHASE,
76 NGX_HTTP_PREACCESS_PHASE,
78 NGX_HTTP_ACCESS_PHASE,
79 NGX_HTTP_POST_ACCESS_PHASE,
81 NGX_HTTP_CONTENT_PHASE,
83 NGX_HTTP_LOG_PHASE
84 } ngx_http_phases;
86 typedef struct ngx_http_phase_handler_s ngx_http_phase_handler_t;
88 typedef ngx_int_t (*ngx_http_phase_handler_pt)(ngx_http_request_t *r,
89 ngx_http_phase_handler_t *ph);
91 struct ngx_http_phase_handler_s {
92 ngx_http_phase_handler_pt checker;
93 ngx_http_handler_pt handler;
94 ngx_uint_t next;
98 typedef struct {
99 ngx_http_phase_handler_t *handlers;
100 ngx_uint_t server_rewrite_index;
101 ngx_uint_t location_rewrite_index;
102 } ngx_http_phase_engine_t;
105 typedef struct {
106 ngx_array_t handlers;
107 } ngx_http_phase_t;
110 typedef struct {
111 ngx_array_t servers; /* ngx_http_core_srv_conf_t */
113 ngx_http_phase_engine_t phase_engine;
115 ngx_hash_t headers_in_hash;
117 ngx_hash_t variables_hash;
119 ngx_array_t variables; /* ngx_http_variable_t */
121 ngx_uint_t server_names_hash_max_size;
122 ngx_uint_t server_names_hash_bucket_size;
124 ngx_uint_t variables_hash_max_size;
125 ngx_uint_t variables_hash_bucket_size;
127 ngx_hash_keys_arrays_t *variables_keys;
129 ngx_http_phase_t phases[NGX_HTTP_LOG_PHASE + 1];
130 } ngx_http_core_main_conf_t;
133 typedef struct {
134 /* array of the ngx_http_listen_t, "listen" directive */
135 ngx_array_t listen;
137 /* array of the ngx_http_server_name_t, "server_name" directive */
138 ngx_array_t server_names;
140 /* server ctx */
141 ngx_http_conf_ctx_t *ctx;
143 ngx_str_t server_name;
145 size_t connection_pool_size;
146 size_t request_pool_size;
147 size_t client_header_buffer_size;
149 ngx_bufs_t large_client_header_buffers;
151 ngx_msec_t client_header_timeout;
153 ngx_flag_t ignore_invalid_headers;
154 ngx_flag_t merge_slashes;
156 ngx_http_core_loc_conf_t **named_locations;
157 } ngx_http_core_srv_conf_t;
160 /* list of structures to find core_srv_conf quickly at run time */
163 typedef struct {
164 in_addr_t addr;
166 /* the default server configuration for this address:port */
167 ngx_http_core_srv_conf_t *core_srv_conf;
169 ngx_http_virtual_names_t *virtual_names;
170 } ngx_http_in_addr_t;
173 typedef struct {
174 in_port_t port;
175 ngx_str_t port_text;
176 ngx_http_in_addr_t *addrs;
177 ngx_uint_t naddrs;
178 } ngx_http_in_port_t;
181 typedef struct {
182 in_port_t port;
183 ngx_array_t addrs; /* array of ngx_http_conf_in_addr_t */
184 } ngx_http_conf_in_port_t;
187 typedef struct {
188 in_addr_t addr;
190 ngx_hash_t hash;
191 ngx_hash_wildcard_t *wc_head;
192 ngx_hash_wildcard_t *wc_tail;
194 ngx_array_t names; /* array of ngx_http_server_name_t */
196 #if (NGX_PCRE)
197 ngx_uint_t nregex;
198 ngx_http_server_name_t *regex;
199 #endif
201 /* the default server configuration for this address:port */
202 ngx_http_core_srv_conf_t *core_srv_conf;
204 unsigned default_server:1;
205 unsigned bind:1;
207 ngx_http_listen_conf_t *listen_conf;
208 } ngx_http_conf_in_addr_t;
211 struct ngx_http_server_name_s {
212 #if (NGX_PCRE)
213 ngx_regex_t *regex;
214 #endif
215 ngx_http_core_srv_conf_t *core_srv_conf; /* virtual name server conf */
216 ngx_str_t name;
220 typedef struct {
221 ngx_int_t status;
222 ngx_int_t overwrite;
223 ngx_str_t uri;
224 ngx_str_t args;
225 ngx_array_t *uri_lengths;
226 ngx_array_t *uri_values;
227 } ngx_http_err_page_t;
230 struct ngx_http_core_loc_conf_s {
231 ngx_str_t name; /* location name */
233 #if (NGX_PCRE)
234 ngx_regex_t *regex;
235 #endif
237 unsigned noname:1; /* "if () {}" block or limit_except */
238 unsigned named:1;
240 unsigned exact_match:1;
241 unsigned noregex:1;
243 unsigned auto_redirect:1;
244 unsigned alias:1;
246 ngx_http_location_tree_node_t *static_locations;
247 ngx_http_core_loc_conf_t **regex_locations;
249 /* pointer to the modules' loc_conf */
250 void **loc_conf;
252 uint32_t limit_except;
253 void **limit_except_loc_conf;
255 ngx_http_handler_pt handler;
257 ngx_str_t root; /* root, alias */
258 ngx_str_t post_action;
260 ngx_array_t *root_lengths;
261 ngx_array_t *root_values;
263 ngx_array_t *types;
264 ngx_hash_t types_hash;
265 ngx_str_t default_type;
267 off_t client_max_body_size; /* client_max_body_size */
268 off_t directio; /* directio */
270 size_t client_body_buffer_size; /* client_body_buffer_size */
271 size_t send_lowat; /* send_lowat */
272 size_t postpone_output; /* postpone_output */
273 size_t limit_rate; /* limit_rate */
274 size_t sendfile_max_chunk; /* sendfile_max_chunk */
276 ngx_msec_t client_body_timeout; /* client_body_timeout */
277 ngx_msec_t send_timeout; /* send_timeout */
278 ngx_msec_t keepalive_timeout; /* keepalive_timeout */
279 ngx_msec_t lingering_time; /* lingering_time */
280 ngx_msec_t lingering_timeout; /* lingering_timeout */
281 ngx_msec_t resolver_timeout; /* resolver_timeout */
283 ngx_resolver_t *resolver; /* resolver */
285 time_t keepalive_header; /* keepalive_timeout */
287 ngx_uint_t satisfy; /* satisfy */
289 ngx_flag_t internal; /* internal */
290 ngx_flag_t client_body_in_file_only; /* client_body_in_file_only */
291 ngx_flag_t sendfile; /* sendfile */
292 ngx_flag_t tcp_nopush; /* tcp_nopush */
293 ngx_flag_t tcp_nodelay; /* tcp_nodelay */
294 ngx_flag_t reset_timedout_connection; /* reset_timedout_connection */
295 ngx_flag_t server_name_in_redirect; /* server_name_in_redirect */
296 ngx_flag_t port_in_redirect; /* port_in_redirect */
297 ngx_flag_t msie_padding; /* msie_padding */
298 ngx_flag_t msie_refresh; /* msie_refresh */
299 ngx_flag_t log_not_found; /* log_not_found */
300 ngx_flag_t recursive_error_pages; /* recursive_error_pages */
301 ngx_flag_t server_tokens; /* server_tokens */
303 #if (NGX_HTTP_GZIP)
304 ngx_flag_t gzip_vary; /* gzip_vary */
306 ngx_uint_t gzip_http_version; /* gzip_http_version */
307 ngx_uint_t gzip_proxied; /* gzip_proxied */
309 #if (NGX_PCRE)
310 ngx_array_t *gzip_disable; /* gzip_disable */
311 #endif
312 #endif
314 ngx_array_t *error_pages; /* error_page */
316 ngx_path_t *client_body_temp_path; /* client_body_temp_path */
318 ngx_open_file_cache_t *open_file_cache;
319 time_t open_file_cache_valid;
320 ngx_uint_t open_file_cache_min_uses;
321 ngx_flag_t open_file_cache_errors;
322 ngx_flag_t open_file_cache_events;
324 ngx_log_t *err_log;
326 ngx_uint_t types_hash_max_size;
327 ngx_uint_t types_hash_bucket_size;
329 ngx_queue_t *locations;
331 #if 0
332 ngx_http_core_loc_conf_t *prev_location;
333 #endif
337 typedef struct {
338 ngx_queue_t queue;
339 ngx_http_core_loc_conf_t *exact;
340 ngx_http_core_loc_conf_t *inclusive;
341 ngx_str_t *name;
342 u_char *file_name;
343 ngx_uint_t line;
344 ngx_queue_t list;
345 } ngx_http_location_queue_t;
348 struct ngx_http_location_tree_node_s {
349 ngx_http_location_tree_node_t *left;
350 ngx_http_location_tree_node_t *right;
351 ngx_http_location_tree_node_t *tree;
353 ngx_http_core_loc_conf_t *exact;
354 ngx_http_core_loc_conf_t *inclusive;
356 u_char auto_redirect;
357 u_char len;
358 u_char name[1];
362 void ngx_http_core_run_phases(ngx_http_request_t *r);
363 ngx_int_t ngx_http_core_generic_phase(ngx_http_request_t *r,
364 ngx_http_phase_handler_t *ph);
365 ngx_int_t ngx_http_core_find_config_phase(ngx_http_request_t *r,
366 ngx_http_phase_handler_t *ph);
367 ngx_int_t ngx_http_core_post_rewrite_phase(ngx_http_request_t *r,
368 ngx_http_phase_handler_t *ph);
369 ngx_int_t ngx_http_core_access_phase(ngx_http_request_t *r,
370 ngx_http_phase_handler_t *ph);
371 ngx_int_t ngx_http_core_post_access_phase(ngx_http_request_t *r,
372 ngx_http_phase_handler_t *ph);
373 ngx_int_t ngx_http_core_content_phase(ngx_http_request_t *r,
374 ngx_http_phase_handler_t *ph);
377 void *ngx_http_test_content_type(ngx_http_request_t *r, ngx_hash_t *types_hash);
378 ngx_int_t ngx_http_set_content_type(ngx_http_request_t *r);
379 ngx_int_t ngx_http_set_exten(ngx_http_request_t *r);
380 u_char *ngx_http_map_uri_to_path(ngx_http_request_t *r, ngx_str_t *name,
381 size_t *root_length, size_t reserved);
382 ngx_int_t ngx_http_auth_basic_user(ngx_http_request_t *r);
383 ngx_int_t ngx_http_server_addr(ngx_http_request_t *r, ngx_str_t *s);
384 #if (NGX_HTTP_GZIP)
385 ngx_int_t ngx_http_gzip_ok(ngx_http_request_t *r);
386 #endif
389 ngx_int_t ngx_http_subrequest(ngx_http_request_t *r,
390 ngx_str_t *uri, ngx_str_t *args, ngx_http_request_t **sr,
391 ngx_http_post_subrequest_t *psr, ngx_uint_t flags);
392 ngx_int_t ngx_http_internal_redirect(ngx_http_request_t *r,
393 ngx_str_t *uri, ngx_str_t *args);
394 ngx_int_t ngx_http_named_location(ngx_http_request_t *r, ngx_str_t *name);
397 ngx_http_cleanup_t *ngx_http_cleanup_add(ngx_http_request_t *r, size_t size);
400 typedef ngx_int_t (*ngx_http_output_header_filter_pt)(ngx_http_request_t *r);
401 typedef ngx_int_t (*ngx_http_output_body_filter_pt)
402 (ngx_http_request_t *r, ngx_chain_t *chain);
405 ngx_int_t ngx_http_output_filter(ngx_http_request_t *r, ngx_chain_t *chain);
406 ngx_int_t ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *chain);
409 extern ngx_module_t ngx_http_core_module;
411 extern ngx_uint_t ngx_http_max_module;
414 #define ngx_http_clear_content_length(r) \
416 r->headers_out.content_length_n = -1; \
417 if (r->headers_out.content_length) { \
418 r->headers_out.content_length->hash = 0; \
419 r->headers_out.content_length = NULL; \
422 #define ngx_http_clear_accept_ranges(r) \
424 r->allow_ranges = 0; \
425 if (r->headers_out.accept_ranges) { \
426 r->headers_out.accept_ranges->hash = 0; \
427 r->headers_out.accept_ranges = NULL; \
430 #define ngx_http_clear_last_modified(r) \
432 r->headers_out.last_modified_time = -1; \
433 if (r->headers_out.last_modified) { \
434 r->headers_out.last_modified->hash = 0; \
435 r->headers_out.last_modified = NULL; \
439 #endif /* _NGX_HTTP_CORE_H_INCLUDED_ */