nginx 0.8.35
[nginx-catap.git] / src / http / ngx_http_core_module.h
blob631f3992772d19487c883a6e6ecafe71f11cd376
2 /*
3 * Copyright (C) Igor Sysoev
4 */
7 #ifndef _NGX_HTTP_CORE_H_INCLUDED_
8 #define _NGX_HTTP_CORE_H_INCLUDED_
11 #include <ngx_config.h>
12 #include <ngx_core.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_AIO_OFF 0
28 #define NGX_HTTP_AIO_ON 1
29 #define NGX_HTTP_AIO_SENDFILE 2
32 #define NGX_HTTP_SATISFY_ALL 0
33 #define NGX_HTTP_SATISFY_ANY 1
36 #define NGX_HTTP_IMS_OFF 0
37 #define NGX_HTTP_IMS_EXACT 1
38 #define NGX_HTTP_IMS_BEFORE 2
41 typedef struct ngx_http_location_tree_node_s ngx_http_location_tree_node_t;
42 typedef struct ngx_http_core_loc_conf_s ngx_http_core_loc_conf_t;
45 typedef struct {
46 union {
47 struct sockaddr sockaddr;
48 struct sockaddr_in sockaddr_in;
49 #if (NGX_HAVE_INET6)
50 struct sockaddr_in6 sockaddr_in6;
51 #endif
52 #if (NGX_HAVE_UNIX_DOMAIN)
53 struct sockaddr_un sockaddr_un;
54 #endif
55 u_char sockaddr_data[NGX_SOCKADDRLEN];
56 } u;
58 socklen_t socklen;
60 unsigned set:1;
61 unsigned default_server:1;
62 unsigned bind:1;
63 unsigned wildcard:1;
64 #if (NGX_HTTP_SSL)
65 unsigned ssl:1;
66 #endif
67 #if (NGX_HAVE_INET6 && defined IPV6_V6ONLY)
68 unsigned ipv6only:2;
69 #endif
71 int backlog;
72 int rcvbuf;
73 int sndbuf;
75 #if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER)
76 char *accept_filter;
77 #endif
78 #if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT)
79 ngx_uint_t deferred_accept;
80 #endif
82 u_char addr[NGX_SOCKADDR_STRLEN + 1];
83 } ngx_http_listen_opt_t;
86 typedef enum {
87 NGX_HTTP_POST_READ_PHASE = 0,
89 NGX_HTTP_SERVER_REWRITE_PHASE,
91 NGX_HTTP_FIND_CONFIG_PHASE,
92 NGX_HTTP_REWRITE_PHASE,
93 NGX_HTTP_POST_REWRITE_PHASE,
95 NGX_HTTP_PREACCESS_PHASE,
97 NGX_HTTP_ACCESS_PHASE,
98 NGX_HTTP_POST_ACCESS_PHASE,
100 NGX_HTTP_TRY_FILES_PHASE,
101 NGX_HTTP_CONTENT_PHASE,
103 NGX_HTTP_LOG_PHASE
104 } ngx_http_phases;
106 typedef struct ngx_http_phase_handler_s ngx_http_phase_handler_t;
108 typedef ngx_int_t (*ngx_http_phase_handler_pt)(ngx_http_request_t *r,
109 ngx_http_phase_handler_t *ph);
111 struct ngx_http_phase_handler_s {
112 ngx_http_phase_handler_pt checker;
113 ngx_http_handler_pt handler;
114 ngx_uint_t next;
118 typedef struct {
119 ngx_http_phase_handler_t *handlers;
120 ngx_uint_t server_rewrite_index;
121 ngx_uint_t location_rewrite_index;
122 } ngx_http_phase_engine_t;
125 typedef struct {
126 ngx_array_t handlers;
127 } ngx_http_phase_t;
130 typedef struct {
131 ngx_array_t servers; /* ngx_http_core_srv_conf_t */
133 ngx_http_phase_engine_t phase_engine;
135 ngx_hash_t headers_in_hash;
137 ngx_hash_t variables_hash;
139 ngx_array_t variables; /* ngx_http_variable_t */
140 ngx_uint_t ncaptures;
142 ngx_uint_t server_names_hash_max_size;
143 ngx_uint_t server_names_hash_bucket_size;
145 ngx_uint_t variables_hash_max_size;
146 ngx_uint_t variables_hash_bucket_size;
148 ngx_hash_keys_arrays_t *variables_keys;
150 ngx_array_t *ports;
152 ngx_uint_t try_files; /* unsigned try_files:1 */
154 ngx_http_phase_t phases[NGX_HTTP_LOG_PHASE + 1];
155 } ngx_http_core_main_conf_t;
158 typedef struct {
159 /* array of the ngx_http_server_name_t, "server_name" directive */
160 ngx_array_t server_names;
162 /* server ctx */
163 ngx_http_conf_ctx_t *ctx;
165 ngx_str_t server_name;
167 size_t connection_pool_size;
168 size_t request_pool_size;
169 size_t client_header_buffer_size;
171 ngx_bufs_t large_client_header_buffers;
173 ngx_msec_t client_header_timeout;
175 ngx_flag_t ignore_invalid_headers;
176 ngx_flag_t merge_slashes;
177 ngx_flag_t underscores_in_headers;
179 unsigned listen:1;
180 #if (NGX_PCRE)
181 unsigned captures:1;
182 #endif
184 ngx_http_core_loc_conf_t **named_locations;
185 } ngx_http_core_srv_conf_t;
188 /* list of structures to find core_srv_conf quickly at run time */
191 typedef struct {
192 /* the default server configuration for this address:port */
193 ngx_http_core_srv_conf_t *default_server;
195 ngx_http_virtual_names_t *virtual_names;
197 #if (NGX_HTTP_SSL)
198 ngx_uint_t ssl; /* unsigned ssl:1; */
199 #endif
200 } ngx_http_addr_conf_t;
203 typedef struct {
204 in_addr_t addr;
205 ngx_http_addr_conf_t conf;
206 } ngx_http_in_addr_t;
209 #if (NGX_HAVE_INET6)
211 typedef struct {
212 struct in6_addr addr6;
213 ngx_http_addr_conf_t conf;
214 } ngx_http_in6_addr_t;
216 #endif
219 typedef struct {
220 /* ngx_http_in_addr_t or ngx_http_in6_addr_t */
221 void *addrs;
222 ngx_uint_t naddrs;
223 } ngx_http_port_t;
226 typedef struct {
227 ngx_int_t family;
228 in_port_t port;
229 ngx_array_t addrs; /* array of ngx_http_conf_addr_t */
230 } ngx_http_conf_port_t;
233 typedef struct {
234 ngx_http_listen_opt_t opt;
236 ngx_hash_t hash;
237 ngx_hash_wildcard_t *wc_head;
238 ngx_hash_wildcard_t *wc_tail;
240 #if (NGX_PCRE)
241 ngx_uint_t nregex;
242 ngx_http_server_name_t *regex;
243 #endif
245 /* the default server configuration for this address:port */
246 ngx_http_core_srv_conf_t *default_server;
247 ngx_array_t servers; /* array of ngx_http_core_srv_conf_t */
248 } ngx_http_conf_addr_t;
251 struct ngx_http_server_name_s {
252 #if (NGX_PCRE)
253 ngx_http_regex_t *regex;
254 #endif
255 ngx_http_core_srv_conf_t *server; /* virtual name server conf */
256 ngx_str_t name;
260 typedef struct {
261 ngx_int_t status;
262 ngx_int_t overwrite;
263 ngx_http_complex_value_t value;
264 ngx_str_t args;
265 } ngx_http_err_page_t;
268 typedef struct {
269 ngx_array_t *lengths;
270 ngx_array_t *values;
271 ngx_str_t name;
273 unsigned code:10;
274 unsigned test_dir:1;
275 } ngx_http_try_file_t;
278 struct ngx_http_core_loc_conf_s {
279 ngx_str_t name; /* location name */
281 #if (NGX_PCRE)
282 ngx_http_regex_t *regex;
283 #endif
285 unsigned noname:1; /* "if () {}" block or limit_except */
286 unsigned named:1;
288 unsigned exact_match:1;
289 unsigned noregex:1;
291 unsigned auto_redirect:1;
292 unsigned alias:1;
293 #if (NGX_HTTP_GZIP)
294 unsigned gzip_disable_msie6:2;
295 #endif
297 ngx_http_location_tree_node_t *static_locations;
298 #if (NGX_PCRE)
299 ngx_http_core_loc_conf_t **regex_locations;
300 #endif
302 /* pointer to the modules' loc_conf */
303 void **loc_conf;
305 uint32_t limit_except;
306 void **limit_except_loc_conf;
308 ngx_http_handler_pt handler;
310 ngx_str_t root; /* root, alias */
311 ngx_str_t post_action;
313 ngx_array_t *root_lengths;
314 ngx_array_t *root_values;
316 ngx_array_t *types;
317 ngx_hash_t types_hash;
318 ngx_str_t default_type;
320 off_t client_max_body_size; /* client_max_body_size */
321 off_t directio; /* directio */
322 off_t directio_alignment; /* directio_alignment */
324 size_t client_body_buffer_size; /* client_body_buffer_size */
325 size_t send_lowat; /* send_lowat */
326 size_t postpone_output; /* postpone_output */
327 size_t limit_rate; /* limit_rate */
328 size_t limit_rate_after; /* limit_rate_after */
329 size_t sendfile_max_chunk; /* sendfile_max_chunk */
330 size_t read_ahead; /* read_ahead */
332 ngx_msec_t client_body_timeout; /* client_body_timeout */
333 ngx_msec_t send_timeout; /* send_timeout */
334 ngx_msec_t keepalive_timeout; /* keepalive_timeout */
335 ngx_msec_t lingering_time; /* lingering_time */
336 ngx_msec_t lingering_timeout; /* lingering_timeout */
337 ngx_msec_t resolver_timeout; /* resolver_timeout */
339 ngx_resolver_t *resolver; /* resolver */
341 time_t keepalive_header; /* keepalive_timeout */
343 ngx_uint_t keepalive_requests; /* keepalive_requests */
344 ngx_uint_t satisfy; /* satisfy */
345 ngx_uint_t if_modified_since; /* if_modified_since */
346 ngx_uint_t client_body_in_file_only; /* client_body_in_file_only */
348 ngx_flag_t client_body_in_single_buffer;
349 /* client_body_in_singe_buffer */
350 ngx_flag_t internal; /* internal */
351 ngx_flag_t sendfile; /* sendfile */
352 #if (NGX_HAVE_FILE_AIO)
353 ngx_flag_t aio; /* aio */
354 #endif
355 ngx_flag_t tcp_nopush; /* tcp_nopush */
356 ngx_flag_t tcp_nodelay; /* tcp_nodelay */
357 ngx_flag_t reset_timedout_connection; /* reset_timedout_connection */
358 ngx_flag_t server_name_in_redirect; /* server_name_in_redirect */
359 ngx_flag_t port_in_redirect; /* port_in_redirect */
360 ngx_flag_t msie_padding; /* msie_padding */
361 ngx_flag_t msie_refresh; /* msie_refresh */
362 ngx_flag_t log_not_found; /* log_not_found */
363 ngx_flag_t log_subrequest; /* log_subrequest */
364 ngx_flag_t recursive_error_pages; /* recursive_error_pages */
365 ngx_flag_t server_tokens; /* server_tokens */
366 ngx_flag_t chunked_transfer_encoding; /* chunked_transfer_encoding */
368 #if (NGX_HTTP_GZIP)
369 ngx_flag_t gzip_vary; /* gzip_vary */
371 ngx_uint_t gzip_http_version; /* gzip_http_version */
372 ngx_uint_t gzip_proxied; /* gzip_proxied */
374 #if (NGX_PCRE)
375 ngx_array_t *gzip_disable; /* gzip_disable */
376 #endif
377 #endif
379 ngx_array_t *error_pages; /* error_page */
380 ngx_http_try_file_t *try_files; /* try_files */
382 ngx_path_t *client_body_temp_path; /* client_body_temp_path */
384 ngx_open_file_cache_t *open_file_cache;
385 time_t open_file_cache_valid;
386 ngx_uint_t open_file_cache_min_uses;
387 ngx_flag_t open_file_cache_errors;
388 ngx_flag_t open_file_cache_events;
390 ngx_log_t *error_log;
392 ngx_uint_t types_hash_max_size;
393 ngx_uint_t types_hash_bucket_size;
395 ngx_queue_t *locations;
397 #if 0
398 ngx_http_core_loc_conf_t *prev_location;
399 #endif
403 typedef struct {
404 ngx_queue_t queue;
405 ngx_http_core_loc_conf_t *exact;
406 ngx_http_core_loc_conf_t *inclusive;
407 ngx_str_t *name;
408 u_char *file_name;
409 ngx_uint_t line;
410 ngx_queue_t list;
411 } ngx_http_location_queue_t;
414 struct ngx_http_location_tree_node_s {
415 ngx_http_location_tree_node_t *left;
416 ngx_http_location_tree_node_t *right;
417 ngx_http_location_tree_node_t *tree;
419 ngx_http_core_loc_conf_t *exact;
420 ngx_http_core_loc_conf_t *inclusive;
422 u_char auto_redirect;
423 u_char len;
424 u_char name[1];
428 void ngx_http_core_run_phases(ngx_http_request_t *r);
429 ngx_int_t ngx_http_core_generic_phase(ngx_http_request_t *r,
430 ngx_http_phase_handler_t *ph);
431 ngx_int_t ngx_http_core_find_config_phase(ngx_http_request_t *r,
432 ngx_http_phase_handler_t *ph);
433 ngx_int_t ngx_http_core_post_rewrite_phase(ngx_http_request_t *r,
434 ngx_http_phase_handler_t *ph);
435 ngx_int_t ngx_http_core_access_phase(ngx_http_request_t *r,
436 ngx_http_phase_handler_t *ph);
437 ngx_int_t ngx_http_core_post_access_phase(ngx_http_request_t *r,
438 ngx_http_phase_handler_t *ph);
439 ngx_int_t ngx_http_core_try_files_phase(ngx_http_request_t *r,
440 ngx_http_phase_handler_t *ph);
441 ngx_int_t ngx_http_core_content_phase(ngx_http_request_t *r,
442 ngx_http_phase_handler_t *ph);
445 void *ngx_http_test_content_type(ngx_http_request_t *r, ngx_hash_t *types_hash);
446 ngx_int_t ngx_http_set_content_type(ngx_http_request_t *r);
447 void ngx_http_set_exten(ngx_http_request_t *r);
448 u_char *ngx_http_map_uri_to_path(ngx_http_request_t *r, ngx_str_t *name,
449 size_t *root_length, size_t reserved);
450 ngx_int_t ngx_http_auth_basic_user(ngx_http_request_t *r);
451 #if (NGX_HTTP_GZIP)
452 ngx_int_t ngx_http_gzip_ok(ngx_http_request_t *r);
453 #endif
456 ngx_int_t ngx_http_subrequest(ngx_http_request_t *r,
457 ngx_str_t *uri, ngx_str_t *args, ngx_http_request_t **sr,
458 ngx_http_post_subrequest_t *psr, ngx_uint_t flags);
459 ngx_int_t ngx_http_internal_redirect(ngx_http_request_t *r,
460 ngx_str_t *uri, ngx_str_t *args);
461 ngx_int_t ngx_http_named_location(ngx_http_request_t *r, ngx_str_t *name);
464 ngx_http_cleanup_t *ngx_http_cleanup_add(ngx_http_request_t *r, size_t size);
467 typedef ngx_int_t (*ngx_http_output_header_filter_pt)(ngx_http_request_t *r);
468 typedef ngx_int_t (*ngx_http_output_body_filter_pt)
469 (ngx_http_request_t *r, ngx_chain_t *chain);
472 ngx_int_t ngx_http_output_filter(ngx_http_request_t *r, ngx_chain_t *chain);
473 ngx_int_t ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *chain);
476 extern ngx_module_t ngx_http_core_module;
478 extern ngx_uint_t ngx_http_max_module;
480 extern ngx_str_t ngx_http_core_get_method;
483 #define ngx_http_clear_content_length(r) \
485 r->headers_out.content_length_n = -1; \
486 if (r->headers_out.content_length) { \
487 r->headers_out.content_length->hash = 0; \
488 r->headers_out.content_length = NULL; \
491 #define ngx_http_clear_accept_ranges(r) \
493 r->allow_ranges = 0; \
494 if (r->headers_out.accept_ranges) { \
495 r->headers_out.accept_ranges->hash = 0; \
496 r->headers_out.accept_ranges = NULL; \
499 #define ngx_http_clear_last_modified(r) \
501 r->headers_out.last_modified_time = -1; \
502 if (r->headers_out.last_modified) { \
503 r->headers_out.last_modified->hash = 0; \
504 r->headers_out.last_modified = NULL; \
508 #endif /* _NGX_HTTP_CORE_H_INCLUDED_ */