3 * Copyright (C) Igor Sysoev
7 #ifndef _NGX_HTTP_CORE_H_INCLUDED_
8 #define _NGX_HTTP_CORE_H_INCLUDED_
11 #include <ngx_config.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
;
47 struct sockaddr sockaddr
;
48 struct sockaddr_in sockaddr_in
;
50 struct sockaddr_in6 sockaddr_in6
;
52 #if (NGX_HAVE_UNIX_DOMAIN)
53 struct sockaddr_un sockaddr_un
;
55 u_char sockaddr_data
[NGX_SOCKADDRLEN
];
61 unsigned default_server
:1;
67 #if (NGX_HAVE_INET6 && defined IPV6_V6ONLY)
75 #if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER)
78 #if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT)
79 ngx_uint_t deferred_accept
;
82 u_char addr
[NGX_SOCKADDR_STRLEN
+ 1];
83 } ngx_http_listen_opt_t
;
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
,
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
;
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
;
126 ngx_array_t handlers
;
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
;
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
;
159 /* array of the ngx_http_server_name_t, "server_name" directive */
160 ngx_array_t server_names
;
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
;
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 */
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
;
198 ngx_uint_t ssl
; /* unsigned ssl:1; */
200 } ngx_http_addr_conf_t
;
205 ngx_http_addr_conf_t conf
;
206 } ngx_http_in_addr_t
;
212 struct in6_addr addr6
;
213 ngx_http_addr_conf_t conf
;
214 } ngx_http_in6_addr_t
;
220 /* ngx_http_in_addr_t or ngx_http_in6_addr_t */
229 ngx_array_t addrs
; /* array of ngx_http_conf_addr_t */
230 } ngx_http_conf_port_t
;
234 ngx_http_listen_opt_t opt
;
237 ngx_hash_wildcard_t
*wc_head
;
238 ngx_hash_wildcard_t
*wc_tail
;
242 ngx_http_server_name_t
*regex
;
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
{
253 ngx_http_regex_t
*regex
;
255 ngx_http_core_srv_conf_t
*server
; /* virtual name server conf */
263 ngx_http_complex_value_t value
;
265 } ngx_http_err_page_t
;
269 ngx_array_t
*lengths
;
275 } ngx_http_try_file_t
;
278 struct ngx_http_core_loc_conf_s
{
279 ngx_str_t name
; /* location name */
282 ngx_http_regex_t
*regex
;
285 unsigned noname
:1; /* "if () {}" block or limit_except */
288 unsigned exact_match
:1;
291 unsigned auto_redirect
:1;
294 unsigned gzip_disable_msie6
:2;
297 ngx_http_location_tree_node_t
*static_locations
;
299 ngx_http_core_loc_conf_t
**regex_locations
;
302 /* pointer to the modules' 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
;
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 */
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 */
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 */
375 ngx_array_t
*gzip_disable
; /* gzip_disable */
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
;
398 ngx_http_core_loc_conf_t
*prev_location
;
405 ngx_http_core_loc_conf_t
*exact
;
406 ngx_http_core_loc_conf_t
*inclusive
;
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
;
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
);
452 ngx_int_t
ngx_http_gzip_ok(ngx_http_request_t
*r
);
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_ */