Back to home page

Nginx displayed by LXR

Source navigation ]
Diff markup ]
Identifier search ]
general search ]
 
 
Version: nginx-1.15.12 ]​[ nginx-1.16.0 ]​

0001 
0002 /*
0003  * Copyright (C) Igor Sysoev
0004  * Copyright (C) Nginx, Inc.
0005  */
0006 
0007 
0008 #include <ngx_config.h>
0009 #include <ngx_core.h>
0010 #include <ngx_http.h>
0011 
0012 
0013 typedef struct {
0014     u_char    *name;
0015     uint32_t   method;
0016 } ngx_http_method_name_t;
0017 
0018 
0019 #define NGX_HTTP_REQUEST_BODY_FILE_OFF    0
0020 #define NGX_HTTP_REQUEST_BODY_FILE_ON     1
0021 #define NGX_HTTP_REQUEST_BODY_FILE_CLEAN  2
0022 
0023 
0024 static ngx_int_t ngx_http_core_find_location(ngx_http_request_t *r);
0025 static ngx_int_t ngx_http_core_find_static_location(ngx_http_request_t *r,
0026     ngx_http_location_tree_node_t *node);
0027 
0028 static ngx_int_t ngx_http_core_preconfiguration(ngx_conf_t *cf);
0029 static ngx_int_t ngx_http_core_postconfiguration(ngx_conf_t *cf);
0030 static void *ngx_http_core_create_main_conf(ngx_conf_t *cf);
0031 static char *ngx_http_core_init_main_conf(ngx_conf_t *cf, void *conf);
0032 static void *ngx_http_core_create_srv_conf(ngx_conf_t *cf);
0033 static char *ngx_http_core_merge_srv_conf(ngx_conf_t *cf,
0034     void *parent, void *child);
0035 static void *ngx_http_core_create_loc_conf(ngx_conf_t *cf);
0036 static char *ngx_http_core_merge_loc_conf(ngx_conf_t *cf,
0037     void *parent, void *child);
0038 
0039 static char *ngx_http_core_server(ngx_conf_t *cf, ngx_command_t *cmd,
0040     void *dummy);
0041 static char *ngx_http_core_location(ngx_conf_t *cf, ngx_command_t *cmd,
0042     void *dummy);
0043 static ngx_int_t ngx_http_core_regex_location(ngx_conf_t *cf,
0044     ngx_http_core_loc_conf_t *clcf, ngx_str_t *regex, ngx_uint_t caseless);
0045 
0046 static char *ngx_http_core_types(ngx_conf_t *cf, ngx_command_t *cmd,
0047     void *conf);
0048 static char *ngx_http_core_type(ngx_conf_t *cf, ngx_command_t *dummy,
0049     void *conf);
0050 
0051 static char *ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd,
0052     void *conf);
0053 static char *ngx_http_core_server_name(ngx_conf_t *cf, ngx_command_t *cmd,
0054     void *conf);
0055 static char *ngx_http_core_root(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
0056 static char *ngx_http_core_limit_except(ngx_conf_t *cf, ngx_command_t *cmd,
0057     void *conf);
0058 static char *ngx_http_core_set_aio(ngx_conf_t *cf, ngx_command_t *cmd,
0059     void *conf);
0060 static char *ngx_http_core_directio(ngx_conf_t *cf, ngx_command_t *cmd,
0061     void *conf);
0062 static char *ngx_http_core_error_page(ngx_conf_t *cf, ngx_command_t *cmd,
0063     void *conf);
0064 static char *ngx_http_core_open_file_cache(ngx_conf_t *cf, ngx_command_t *cmd,
0065     void *conf);
0066 static char *ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd,
0067     void *conf);
0068 static char *ngx_http_core_keepalive(ngx_conf_t *cf, ngx_command_t *cmd,
0069     void *conf);
0070 static char *ngx_http_core_internal(ngx_conf_t *cf, ngx_command_t *cmd,
0071     void *conf);
0072 static char *ngx_http_core_resolver(ngx_conf_t *cf, ngx_command_t *cmd,
0073     void *conf);
0074 #if (NGX_HTTP_GZIP)
0075 static ngx_int_t ngx_http_gzip_accept_encoding(ngx_str_t *ae);
0076 static ngx_uint_t ngx_http_gzip_quantity(u_char *p, u_char *last);
0077 static char *ngx_http_gzip_disable(ngx_conf_t *cf, ngx_command_t *cmd,
0078     void *conf);
0079 #endif
0080 static ngx_int_t ngx_http_get_forwarded_addr_internal(ngx_http_request_t *r,
0081     ngx_addr_t *addr, u_char *xff, size_t xfflen, ngx_array_t *proxies,
0082     int recursive);
0083 #if (NGX_HAVE_OPENAT)
0084 static char *ngx_http_disable_symlinks(ngx_conf_t *cf, ngx_command_t *cmd,
0085     void *conf);
0086 #endif
0087 
0088 static char *ngx_http_core_lowat_check(ngx_conf_t *cf, void *post, void *data);
0089 static char *ngx_http_core_pool_size(ngx_conf_t *cf, void *post, void *data);
0090 
0091 static ngx_conf_post_t  ngx_http_core_lowat_post =
0092     { ngx_http_core_lowat_check };
0093 
0094 static ngx_conf_post_handler_pt  ngx_http_core_pool_size_p =
0095     ngx_http_core_pool_size;
0096 
0097 
0098 static ngx_conf_enum_t  ngx_http_core_request_body_in_file[] = {
0099     { ngx_string("off"), NGX_HTTP_REQUEST_BODY_FILE_OFF },
0100     { ngx_string("on"), NGX_HTTP_REQUEST_BODY_FILE_ON },
0101     { ngx_string("clean"), NGX_HTTP_REQUEST_BODY_FILE_CLEAN },
0102     { ngx_null_string, 0 }
0103 };
0104 
0105 
0106 static ngx_conf_enum_t  ngx_http_core_satisfy[] = {
0107     { ngx_string("all"), NGX_HTTP_SATISFY_ALL },
0108     { ngx_string("any"), NGX_HTTP_SATISFY_ANY },
0109     { ngx_null_string, 0 }
0110 };
0111 
0112 
0113 static ngx_conf_enum_t  ngx_http_core_lingering_close[] = {
0114     { ngx_string("off"), NGX_HTTP_LINGERING_OFF },
0115     { ngx_string("on"), NGX_HTTP_LINGERING_ON },
0116     { ngx_string("always"), NGX_HTTP_LINGERING_ALWAYS },
0117     { ngx_null_string, 0 }
0118 };
0119 
0120 
0121 static ngx_conf_enum_t  ngx_http_core_server_tokens[] = {
0122     { ngx_string("off"), NGX_HTTP_SERVER_TOKENS_OFF },
0123     { ngx_string("on"), NGX_HTTP_SERVER_TOKENS_ON },
0124     { ngx_string("build"), NGX_HTTP_SERVER_TOKENS_BUILD },
0125     { ngx_null_string, 0 }
0126 };
0127 
0128 
0129 static ngx_conf_enum_t  ngx_http_core_if_modified_since[] = {
0130     { ngx_string("off"), NGX_HTTP_IMS_OFF },
0131     { ngx_string("exact"), NGX_HTTP_IMS_EXACT },
0132     { ngx_string("before"), NGX_HTTP_IMS_BEFORE },
0133     { ngx_null_string, 0 }
0134 };
0135 
0136 
0137 static ngx_conf_bitmask_t  ngx_http_core_keepalive_disable[] = {
0138     { ngx_string("none"), NGX_HTTP_KEEPALIVE_DISABLE_NONE },
0139     { ngx_string("msie6"), NGX_HTTP_KEEPALIVE_DISABLE_MSIE6 },
0140     { ngx_string("safari"), NGX_HTTP_KEEPALIVE_DISABLE_SAFARI },
0141     { ngx_null_string, 0 }
0142 };
0143 
0144 
0145 static ngx_path_init_t  ngx_http_client_temp_path = {
0146     ngx_string(NGX_HTTP_CLIENT_TEMP_PATH), { 0, 0, 0 }
0147 };
0148 
0149 
0150 #if (NGX_HTTP_GZIP)
0151 
0152 static ngx_conf_enum_t  ngx_http_gzip_http_version[] = {
0153     { ngx_string("1.0"), NGX_HTTP_VERSION_10 },
0154     { ngx_string("1.1"), NGX_HTTP_VERSION_11 },
0155     { ngx_null_string, 0 }
0156 };
0157 
0158 
0159 static ngx_conf_bitmask_t  ngx_http_gzip_proxied_mask[] = {
0160     { ngx_string("off"), NGX_HTTP_GZIP_PROXIED_OFF },
0161     { ngx_string("expired"), NGX_HTTP_GZIP_PROXIED_EXPIRED },
0162     { ngx_string("no-cache"), NGX_HTTP_GZIP_PROXIED_NO_CACHE },
0163     { ngx_string("no-store"), NGX_HTTP_GZIP_PROXIED_NO_STORE },
0164     { ngx_string("private"), NGX_HTTP_GZIP_PROXIED_PRIVATE },
0165     { ngx_string("no_last_modified"), NGX_HTTP_GZIP_PROXIED_NO_LM },
0166     { ngx_string("no_etag"), NGX_HTTP_GZIP_PROXIED_NO_ETAG },
0167     { ngx_string("auth"), NGX_HTTP_GZIP_PROXIED_AUTH },
0168     { ngx_string("any"), NGX_HTTP_GZIP_PROXIED_ANY },
0169     { ngx_null_string, 0 }
0170 };
0171 
0172 
0173 static ngx_str_t  ngx_http_gzip_no_cache = ngx_string("no-cache");
0174 static ngx_str_t  ngx_http_gzip_no_store = ngx_string("no-store");
0175 static ngx_str_t  ngx_http_gzip_private = ngx_string("private");
0176 
0177 #endif
0178 
0179 
0180 static ngx_command_t  ngx_http_core_commands[] = {
0181 
0182     { ngx_string("variables_hash_max_size"),
0183       NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
0184       ngx_conf_set_num_slot,
0185       NGX_HTTP_MAIN_CONF_OFFSET,
0186       offsetof(ngx_http_core_main_conf_t, variables_hash_max_size),
0187       NULL },
0188 
0189     { ngx_string("variables_hash_bucket_size"),
0190       NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
0191       ngx_conf_set_num_slot,
0192       NGX_HTTP_MAIN_CONF_OFFSET,
0193       offsetof(ngx_http_core_main_conf_t, variables_hash_bucket_size),
0194       NULL },
0195 
0196     { ngx_string("server_names_hash_max_size"),
0197       NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
0198       ngx_conf_set_num_slot,
0199       NGX_HTTP_MAIN_CONF_OFFSET,
0200       offsetof(ngx_http_core_main_conf_t, server_names_hash_max_size),
0201       NULL },
0202 
0203     { ngx_string("server_names_hash_bucket_size"),
0204       NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
0205       ngx_conf_set_num_slot,
0206       NGX_HTTP_MAIN_CONF_OFFSET,
0207       offsetof(ngx_http_core_main_conf_t, server_names_hash_bucket_size),
0208       NULL },
0209 
0210     { ngx_string("server"),
0211       NGX_HTTP_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_NOARGS,
0212       ngx_http_core_server,
0213       0,
0214       0,
0215       NULL },
0216 
0217     { ngx_string("connection_pool_size"),
0218       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
0219       ngx_conf_set_size_slot,
0220       NGX_HTTP_SRV_CONF_OFFSET,
0221       offsetof(ngx_http_core_srv_conf_t, connection_pool_size),
0222       &ngx_http_core_pool_size_p },
0223 
0224     { ngx_string("request_pool_size"),
0225       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
0226       ngx_conf_set_size_slot,
0227       NGX_HTTP_SRV_CONF_OFFSET,
0228       offsetof(ngx_http_core_srv_conf_t, request_pool_size),
0229       &ngx_http_core_pool_size_p },
0230 
0231     { ngx_string("client_header_timeout"),
0232       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
0233       ngx_conf_set_msec_slot,
0234       NGX_HTTP_SRV_CONF_OFFSET,
0235       offsetof(ngx_http_core_srv_conf_t, client_header_timeout),
0236       NULL },
0237 
0238     { ngx_string("client_header_buffer_size"),
0239       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
0240       ngx_conf_set_size_slot,
0241       NGX_HTTP_SRV_CONF_OFFSET,
0242       offsetof(ngx_http_core_srv_conf_t, client_header_buffer_size),
0243       NULL },
0244 
0245     { ngx_string("large_client_header_buffers"),
0246       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE2,
0247       ngx_conf_set_bufs_slot,
0248       NGX_HTTP_SRV_CONF_OFFSET,
0249       offsetof(ngx_http_core_srv_conf_t, large_client_header_buffers),
0250       NULL },
0251 
0252     { ngx_string("ignore_invalid_headers"),
0253       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_FLAG,
0254       ngx_conf_set_flag_slot,
0255       NGX_HTTP_SRV_CONF_OFFSET,
0256       offsetof(ngx_http_core_srv_conf_t, ignore_invalid_headers),
0257       NULL },
0258 
0259     { ngx_string("merge_slashes"),
0260       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_FLAG,
0261       ngx_conf_set_flag_slot,
0262       NGX_HTTP_SRV_CONF_OFFSET,
0263       offsetof(ngx_http_core_srv_conf_t, merge_slashes),
0264       NULL },
0265 
0266     { ngx_string("underscores_in_headers"),
0267       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_FLAG,
0268       ngx_conf_set_flag_slot,
0269       NGX_HTTP_SRV_CONF_OFFSET,
0270       offsetof(ngx_http_core_srv_conf_t, underscores_in_headers),
0271       NULL },
0272 
0273     { ngx_string("location"),
0274       NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_BLOCK|NGX_CONF_TAKE12,
0275       ngx_http_core_location,
0276       NGX_HTTP_SRV_CONF_OFFSET,
0277       0,
0278       NULL },
0279 
0280     { ngx_string("listen"),
0281       NGX_HTTP_SRV_CONF|NGX_CONF_1MORE,
0282       ngx_http_core_listen,
0283       NGX_HTTP_SRV_CONF_OFFSET,
0284       0,
0285       NULL },
0286 
0287     { ngx_string("server_name"),
0288       NGX_HTTP_SRV_CONF|NGX_CONF_1MORE,
0289       ngx_http_core_server_name,
0290       NGX_HTTP_SRV_CONF_OFFSET,
0291       0,
0292       NULL },
0293 
0294     { ngx_string("types_hash_max_size"),
0295       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
0296       ngx_conf_set_num_slot,
0297       NGX_HTTP_LOC_CONF_OFFSET,
0298       offsetof(ngx_http_core_loc_conf_t, types_hash_max_size),
0299       NULL },
0300 
0301     { ngx_string("types_hash_bucket_size"),
0302       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
0303       ngx_conf_set_num_slot,
0304       NGX_HTTP_LOC_CONF_OFFSET,
0305       offsetof(ngx_http_core_loc_conf_t, types_hash_bucket_size),
0306       NULL },
0307 
0308     { ngx_string("types"),
0309       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF
0310                                           |NGX_CONF_BLOCK|NGX_CONF_NOARGS,
0311       ngx_http_core_types,
0312       NGX_HTTP_LOC_CONF_OFFSET,
0313       0,
0314       NULL },
0315 
0316     { ngx_string("default_type"),
0317       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
0318       ngx_conf_set_str_slot,
0319       NGX_HTTP_LOC_CONF_OFFSET,
0320       offsetof(ngx_http_core_loc_conf_t, default_type),
0321       NULL },
0322 
0323     { ngx_string("root"),
0324       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
0325                         |NGX_CONF_TAKE1,
0326       ngx_http_core_root,
0327       NGX_HTTP_LOC_CONF_OFFSET,
0328       0,
0329       NULL },
0330 
0331     { ngx_string("alias"),
0332       NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
0333       ngx_http_core_root,
0334       NGX_HTTP_LOC_CONF_OFFSET,
0335       0,
0336       NULL },
0337 
0338     { ngx_string("limit_except"),
0339       NGX_HTTP_LOC_CONF|NGX_CONF_BLOCK|NGX_CONF_1MORE,
0340       ngx_http_core_limit_except,
0341       NGX_HTTP_LOC_CONF_OFFSET,
0342       0,
0343       NULL },
0344 
0345     { ngx_string("client_max_body_size"),
0346       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
0347       ngx_conf_set_off_slot,
0348       NGX_HTTP_LOC_CONF_OFFSET,
0349       offsetof(ngx_http_core_loc_conf_t, client_max_body_size),
0350       NULL },
0351 
0352     { ngx_string("client_body_buffer_size"),
0353       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
0354       ngx_conf_set_size_slot,
0355       NGX_HTTP_LOC_CONF_OFFSET,
0356       offsetof(ngx_http_core_loc_conf_t, client_body_buffer_size),
0357       NULL },
0358 
0359     { ngx_string("client_body_timeout"),
0360       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
0361       ngx_conf_set_msec_slot,
0362       NGX_HTTP_LOC_CONF_OFFSET,
0363       offsetof(ngx_http_core_loc_conf_t, client_body_timeout),
0364       NULL },
0365 
0366     { ngx_string("client_body_temp_path"),
0367       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1234,
0368       ngx_conf_set_path_slot,
0369       NGX_HTTP_LOC_CONF_OFFSET,
0370       offsetof(ngx_http_core_loc_conf_t, client_body_temp_path),
0371       NULL },
0372 
0373     { ngx_string("client_body_in_file_only"),
0374       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
0375       ngx_conf_set_enum_slot,
0376       NGX_HTTP_LOC_CONF_OFFSET,
0377       offsetof(ngx_http_core_loc_conf_t, client_body_in_file_only),
0378       &ngx_http_core_request_body_in_file },
0379 
0380     { ngx_string("client_body_in_single_buffer"),
0381       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
0382       ngx_conf_set_flag_slot,
0383       NGX_HTTP_LOC_CONF_OFFSET,
0384       offsetof(ngx_http_core_loc_conf_t, client_body_in_single_buffer),
0385       NULL },
0386 
0387     { ngx_string("sendfile"),
0388       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
0389                         |NGX_CONF_FLAG,
0390       ngx_conf_set_flag_slot,
0391       NGX_HTTP_LOC_CONF_OFFSET,
0392       offsetof(ngx_http_core_loc_conf_t, sendfile),
0393       NULL },
0394 
0395     { ngx_string("sendfile_max_chunk"),
0396       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
0397       ngx_conf_set_size_slot,
0398       NGX_HTTP_LOC_CONF_OFFSET,
0399       offsetof(ngx_http_core_loc_conf_t, sendfile_max_chunk),
0400       NULL },
0401 
0402     { ngx_string("subrequest_output_buffer_size"),
0403       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
0404       ngx_conf_set_size_slot,
0405       NGX_HTTP_LOC_CONF_OFFSET,
0406       offsetof(ngx_http_core_loc_conf_t, subrequest_output_buffer_size),
0407       NULL },
0408 
0409     { ngx_string("aio"),
0410       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
0411       ngx_http_core_set_aio,
0412       NGX_HTTP_LOC_CONF_OFFSET,
0413       0,
0414       NULL },
0415 
0416     { ngx_string("aio_write"),
0417       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
0418       ngx_conf_set_flag_slot,
0419       NGX_HTTP_LOC_CONF_OFFSET,
0420       offsetof(ngx_http_core_loc_conf_t, aio_write),
0421       NULL },
0422 
0423     { ngx_string("read_ahead"),
0424       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
0425       ngx_conf_set_size_slot,
0426       NGX_HTTP_LOC_CONF_OFFSET,
0427       offsetof(ngx_http_core_loc_conf_t, read_ahead),
0428       NULL },
0429 
0430     { ngx_string("directio"),
0431       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
0432       ngx_http_core_directio,
0433       NGX_HTTP_LOC_CONF_OFFSET,
0434       0,
0435       NULL },
0436 
0437     { ngx_string("directio_alignment"),
0438       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
0439       ngx_conf_set_off_slot,
0440       NGX_HTTP_LOC_CONF_OFFSET,
0441       offsetof(ngx_http_core_loc_conf_t, directio_alignment),
0442       NULL },
0443 
0444     { ngx_string("tcp_nopush"),
0445       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
0446       ngx_conf_set_flag_slot,
0447       NGX_HTTP_LOC_CONF_OFFSET,
0448       offsetof(ngx_http_core_loc_conf_t, tcp_nopush),
0449       NULL },
0450 
0451     { ngx_string("tcp_nodelay"),
0452       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
0453       ngx_conf_set_flag_slot,
0454       NGX_HTTP_LOC_CONF_OFFSET,
0455       offsetof(ngx_http_core_loc_conf_t, tcp_nodelay),
0456       NULL },
0457 
0458     { ngx_string("send_timeout"),
0459       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
0460       ngx_conf_set_msec_slot,
0461       NGX_HTTP_LOC_CONF_OFFSET,
0462       offsetof(ngx_http_core_loc_conf_t, send_timeout),
0463       NULL },
0464 
0465     { ngx_string("send_lowat"),
0466       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
0467       ngx_conf_set_size_slot,
0468       NGX_HTTP_LOC_CONF_OFFSET,
0469       offsetof(ngx_http_core_loc_conf_t, send_lowat),
0470       &ngx_http_core_lowat_post },
0471 
0472     { ngx_string("postpone_output"),
0473       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
0474       ngx_conf_set_size_slot,
0475       NGX_HTTP_LOC_CONF_OFFSET,
0476       offsetof(ngx_http_core_loc_conf_t, postpone_output),
0477       NULL },
0478 
0479     { ngx_string("limit_rate"),
0480       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
0481                         |NGX_CONF_TAKE1,
0482       ngx_conf_set_size_slot,
0483       NGX_HTTP_LOC_CONF_OFFSET,
0484       offsetof(ngx_http_core_loc_conf_t, limit_rate),
0485       NULL },
0486 
0487     { ngx_string("limit_rate_after"),
0488       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
0489                         |NGX_CONF_TAKE1,
0490       ngx_conf_set_size_slot,
0491       NGX_HTTP_LOC_CONF_OFFSET,
0492       offsetof(ngx_http_core_loc_conf_t, limit_rate_after),
0493       NULL },
0494 
0495     { ngx_string("keepalive_timeout"),
0496       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE12,
0497       ngx_http_core_keepalive,
0498       NGX_HTTP_LOC_CONF_OFFSET,
0499       0,
0500       NULL },
0501 
0502     { ngx_string("keepalive_requests"),
0503       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
0504       ngx_conf_set_num_slot,
0505       NGX_HTTP_LOC_CONF_OFFSET,
0506       offsetof(ngx_http_core_loc_conf_t, keepalive_requests),
0507       NULL },
0508 
0509     { ngx_string("keepalive_disable"),
0510       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE12,
0511       ngx_conf_set_bitmask_slot,
0512       NGX_HTTP_LOC_CONF_OFFSET,
0513       offsetof(ngx_http_core_loc_conf_t, keepalive_disable),
0514       &ngx_http_core_keepalive_disable },
0515 
0516     { ngx_string("satisfy"),
0517       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
0518       ngx_conf_set_enum_slot,
0519       NGX_HTTP_LOC_CONF_OFFSET,
0520       offsetof(ngx_http_core_loc_conf_t, satisfy),
0521       &ngx_http_core_satisfy },
0522 
0523     { ngx_string("internal"),
0524       NGX_HTTP_LOC_CONF|NGX_CONF_NOARGS,
0525       ngx_http_core_internal,
0526       NGX_HTTP_LOC_CONF_OFFSET,
0527       0,
0528       NULL },
0529 
0530     { ngx_string("lingering_close"),
0531       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
0532       ngx_conf_set_enum_slot,
0533       NGX_HTTP_LOC_CONF_OFFSET,
0534       offsetof(ngx_http_core_loc_conf_t, lingering_close),
0535       &ngx_http_core_lingering_close },
0536 
0537     { ngx_string("lingering_time"),
0538       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
0539       ngx_conf_set_msec_slot,
0540       NGX_HTTP_LOC_CONF_OFFSET,
0541       offsetof(ngx_http_core_loc_conf_t, lingering_time),
0542       NULL },
0543 
0544     { ngx_string("lingering_timeout"),
0545       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
0546       ngx_conf_set_msec_slot,
0547       NGX_HTTP_LOC_CONF_OFFSET,
0548       offsetof(ngx_http_core_loc_conf_t, lingering_timeout),
0549       NULL },
0550 
0551     { ngx_string("reset_timedout_connection"),
0552       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
0553       ngx_conf_set_flag_slot,
0554       NGX_HTTP_LOC_CONF_OFFSET,
0555       offsetof(ngx_http_core_loc_conf_t, reset_timedout_connection),
0556       NULL },
0557 
0558     { ngx_string("absolute_redirect"),
0559       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
0560       ngx_conf_set_flag_slot,
0561       NGX_HTTP_LOC_CONF_OFFSET,
0562       offsetof(ngx_http_core_loc_conf_t, absolute_redirect),
0563       NULL },
0564 
0565     { ngx_string("server_name_in_redirect"),
0566       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
0567       ngx_conf_set_flag_slot,
0568       NGX_HTTP_LOC_CONF_OFFSET,
0569       offsetof(ngx_http_core_loc_conf_t, server_name_in_redirect),
0570       NULL },
0571 
0572     { ngx_string("port_in_redirect"),
0573       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
0574       ngx_conf_set_flag_slot,
0575       NGX_HTTP_LOC_CONF_OFFSET,
0576       offsetof(ngx_http_core_loc_conf_t, port_in_redirect),
0577       NULL },
0578 
0579     { ngx_string("msie_padding"),
0580       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
0581       ngx_conf_set_flag_slot,
0582       NGX_HTTP_LOC_CONF_OFFSET,
0583       offsetof(ngx_http_core_loc_conf_t, msie_padding),
0584       NULL },
0585 
0586     { ngx_string("msie_refresh"),
0587       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
0588       ngx_conf_set_flag_slot,
0589       NGX_HTTP_LOC_CONF_OFFSET,
0590       offsetof(ngx_http_core_loc_conf_t, msie_refresh),
0591       NULL },
0592 
0593     { ngx_string("log_not_found"),
0594       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
0595       ngx_conf_set_flag_slot,
0596       NGX_HTTP_LOC_CONF_OFFSET,
0597       offsetof(ngx_http_core_loc_conf_t, log_not_found),
0598       NULL },
0599 
0600     { ngx_string("log_subrequest"),
0601       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
0602       ngx_conf_set_flag_slot,
0603       NGX_HTTP_LOC_CONF_OFFSET,
0604       offsetof(ngx_http_core_loc_conf_t, log_subrequest),
0605       NULL },
0606 
0607     { ngx_string("recursive_error_pages"),
0608       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
0609       ngx_conf_set_flag_slot,
0610       NGX_HTTP_LOC_CONF_OFFSET,
0611       offsetof(ngx_http_core_loc_conf_t, recursive_error_pages),
0612       NULL },
0613 
0614     { ngx_string("server_tokens"),
0615       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
0616       ngx_conf_set_enum_slot,
0617       NGX_HTTP_LOC_CONF_OFFSET,
0618       offsetof(ngx_http_core_loc_conf_t, server_tokens),
0619       &ngx_http_core_server_tokens },
0620 
0621     { ngx_string("if_modified_since"),
0622       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
0623       ngx_conf_set_enum_slot,
0624       NGX_HTTP_LOC_CONF_OFFSET,
0625       offsetof(ngx_http_core_loc_conf_t, if_modified_since),
0626       &ngx_http_core_if_modified_since },
0627 
0628     { ngx_string("max_ranges"),
0629       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
0630       ngx_conf_set_num_slot,
0631       NGX_HTTP_LOC_CONF_OFFSET,
0632       offsetof(ngx_http_core_loc_conf_t, max_ranges),
0633       NULL },
0634 
0635     { ngx_string("chunked_transfer_encoding"),
0636       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
0637       ngx_conf_set_flag_slot,
0638       NGX_HTTP_LOC_CONF_OFFSET,
0639       offsetof(ngx_http_core_loc_conf_t, chunked_transfer_encoding),
0640       NULL },
0641 
0642     { ngx_string("etag"),
0643       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
0644       ngx_conf_set_flag_slot,
0645       NGX_HTTP_LOC_CONF_OFFSET,
0646       offsetof(ngx_http_core_loc_conf_t, etag),
0647       NULL },
0648 
0649     { ngx_string("error_page"),
0650       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
0651                         |NGX_CONF_2MORE,
0652       ngx_http_core_error_page,
0653       NGX_HTTP_LOC_CONF_OFFSET,
0654       0,
0655       NULL },
0656 
0657     { ngx_string("post_action"),
0658       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
0659                         |NGX_CONF_TAKE1,
0660       ngx_conf_set_str_slot,
0661       NGX_HTTP_LOC_CONF_OFFSET,
0662       offsetof(ngx_http_core_loc_conf_t, post_action),
0663       NULL },
0664 
0665     { ngx_string("error_log"),
0666       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
0667       ngx_http_core_error_log,
0668       NGX_HTTP_LOC_CONF_OFFSET,
0669       0,
0670       NULL },
0671 
0672     { ngx_string("open_file_cache"),
0673       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE12,
0674       ngx_http_core_open_file_cache,
0675       NGX_HTTP_LOC_CONF_OFFSET,
0676       offsetof(ngx_http_core_loc_conf_t, open_file_cache),
0677       NULL },
0678 
0679     { ngx_string("open_file_cache_valid"),
0680       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
0681       ngx_conf_set_sec_slot,
0682       NGX_HTTP_LOC_CONF_OFFSET,
0683       offsetof(ngx_http_core_loc_conf_t, open_file_cache_valid),
0684       NULL },
0685 
0686     { ngx_string("open_file_cache_min_uses"),
0687       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
0688       ngx_conf_set_num_slot,
0689       NGX_HTTP_LOC_CONF_OFFSET,
0690       offsetof(ngx_http_core_loc_conf_t, open_file_cache_min_uses),
0691       NULL },
0692 
0693     { ngx_string("open_file_cache_errors"),
0694       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
0695       ngx_conf_set_flag_slot,
0696       NGX_HTTP_LOC_CONF_OFFSET,
0697       offsetof(ngx_http_core_loc_conf_t, open_file_cache_errors),
0698       NULL },
0699 
0700     { ngx_string("open_file_cache_events"),
0701       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
0702       ngx_conf_set_flag_slot,
0703       NGX_HTTP_LOC_CONF_OFFSET,
0704       offsetof(ngx_http_core_loc_conf_t, open_file_cache_events),
0705       NULL },
0706 
0707     { ngx_string("resolver"),
0708       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
0709       ngx_http_core_resolver,
0710       NGX_HTTP_LOC_CONF_OFFSET,
0711       0,
0712       NULL },
0713 
0714     { ngx_string("resolver_timeout"),
0715       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
0716       ngx_conf_set_msec_slot,
0717       NGX_HTTP_LOC_CONF_OFFSET,
0718       offsetof(ngx_http_core_loc_conf_t, resolver_timeout),
0719       NULL },
0720 
0721 #if (NGX_HTTP_GZIP)
0722 
0723     { ngx_string("gzip_vary"),
0724       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
0725       ngx_conf_set_flag_slot,
0726       NGX_HTTP_LOC_CONF_OFFSET,
0727       offsetof(ngx_http_core_loc_conf_t, gzip_vary),
0728       NULL },
0729 
0730     { ngx_string("gzip_http_version"),
0731       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
0732       ngx_conf_set_enum_slot,
0733       NGX_HTTP_LOC_CONF_OFFSET,
0734       offsetof(ngx_http_core_loc_conf_t, gzip_http_version),
0735       &ngx_http_gzip_http_version },
0736 
0737     { ngx_string("gzip_proxied"),
0738       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
0739       ngx_conf_set_bitmask_slot,
0740       NGX_HTTP_LOC_CONF_OFFSET,
0741       offsetof(ngx_http_core_loc_conf_t, gzip_proxied),
0742       &ngx_http_gzip_proxied_mask },
0743 
0744     { ngx_string("gzip_disable"),
0745       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
0746       ngx_http_gzip_disable,
0747       NGX_HTTP_LOC_CONF_OFFSET,
0748       0,
0749       NULL },
0750 
0751 #endif
0752 
0753 #if (NGX_HAVE_OPENAT)
0754 
0755     { ngx_string("disable_symlinks"),
0756       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE12,
0757       ngx_http_disable_symlinks,
0758       NGX_HTTP_LOC_CONF_OFFSET,
0759       0,
0760       NULL },
0761 
0762 #endif
0763 
0764       ngx_null_command
0765 };
0766 
0767 
0768 static ngx_http_module_t  ngx_http_core_module_ctx = {
0769     ngx_http_core_preconfiguration,        /* preconfiguration */
0770     ngx_http_core_postconfiguration,       /* postconfiguration */
0771 
0772     ngx_http_core_create_main_conf,        /* create main configuration */
0773     ngx_http_core_init_main_conf,          /* init main configuration */
0774 
0775     ngx_http_core_create_srv_conf,         /* create server configuration */
0776     ngx_http_core_merge_srv_conf,          /* merge server configuration */
0777 
0778     ngx_http_core_create_loc_conf,         /* create location configuration */
0779     ngx_http_core_merge_loc_conf           /* merge location configuration */
0780 };
0781 
0782 
0783 ngx_module_t  ngx_http_core_module = {
0784     NGX_MODULE_V1,
0785     &ngx_http_core_module_ctx,             /* module context */
0786     ngx_http_core_commands,                /* module directives */
0787     NGX_HTTP_MODULE,                       /* module type */
0788     NULL,                                  /* init master */
0789     NULL,                                  /* init module */
0790     NULL,                                  /* init process */
0791     NULL,                                  /* init thread */
0792     NULL,                                  /* exit thread */
0793     NULL,                                  /* exit process */
0794     NULL,                                  /* exit master */
0795     NGX_MODULE_V1_PADDING
0796 };
0797 
0798 
0799 ngx_str_t  ngx_http_core_get_method = { 3, (u_char *) "GET" };
0800 
0801 
0802 void
0803 ngx_http_handler(ngx_http_request_t *r)
0804 {
0805     ngx_http_core_main_conf_t  *cmcf;
0806 
0807     r->connection->log->action = NULL;
0808 
0809     if (!r->internal) {
0810         switch (r->headers_in.connection_type) {
0811         case 0:
0812             r->keepalive = (r->http_version > NGX_HTTP_VERSION_10);
0813             break;
0814 
0815         case NGX_HTTP_CONNECTION_CLOSE:
0816             r->keepalive = 0;
0817             break;
0818 
0819         case NGX_HTTP_CONNECTION_KEEP_ALIVE:
0820             r->keepalive = 1;
0821             break;
0822         }
0823 
0824         r->lingering_close = (r->headers_in.content_length_n > 0
0825                               || r->headers_in.chunked);
0826         r->phase_handler = 0;
0827 
0828     } else {
0829         cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
0830         r->phase_handler = cmcf->phase_engine.server_rewrite_index;
0831     }
0832 
0833     r->valid_location = 1;
0834 #if (NGX_HTTP_GZIP)
0835     r->gzip_tested = 0;
0836     r->gzip_ok = 0;
0837     r->gzip_vary = 0;
0838 #endif
0839 
0840     r->write_event_handler = ngx_http_core_run_phases;
0841     ngx_http_core_run_phases(r);
0842 }
0843 
0844 
0845 void
0846 ngx_http_core_run_phases(ngx_http_request_t *r)
0847 {
0848     ngx_int_t                   rc;
0849     ngx_http_phase_handler_t   *ph;
0850     ngx_http_core_main_conf_t  *cmcf;
0851 
0852     cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
0853 
0854     ph = cmcf->phase_engine.handlers;
0855 
0856     while (ph[r->phase_handler].checker) {
0857 
0858         rc = ph[r->phase_handler].checker(r, &ph[r->phase_handler]);
0859 
0860         if (rc == NGX_OK) {
0861             return;
0862         }
0863     }
0864 }
0865 
0866 
0867 ngx_int_t
0868 ngx_http_core_generic_phase(ngx_http_request_t *r, ngx_http_phase_handler_t *ph)
0869 {
0870     ngx_int_t  rc;
0871 
0872     /*
0873      * generic phase checker,
0874      * used by the post read and pre-access phases
0875      */
0876 
0877     ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
0878                    "generic phase: %ui", r->phase_handler);
0879 
0880     rc = ph->handler(r);
0881 
0882     if (rc == NGX_OK) {
0883         r->phase_handler = ph->next;
0884         return NGX_AGAIN;
0885     }
0886 
0887     if (rc == NGX_DECLINED) {
0888         r->phase_handler++;
0889         return NGX_AGAIN;
0890     }
0891 
0892     if (rc == NGX_AGAIN || rc == NGX_DONE) {
0893         return NGX_OK;
0894     }
0895 
0896     /* rc == NGX_ERROR || rc == NGX_HTTP_...  */
0897 
0898     ngx_http_finalize_request(r, rc);
0899 
0900     return NGX_OK;
0901 }
0902 
0903 
0904 ngx_int_t
0905 ngx_http_core_rewrite_phase(ngx_http_request_t *r, ngx_http_phase_handler_t *ph)
0906 {
0907     ngx_int_t  rc;
0908 
0909     ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
0910                    "rewrite phase: %ui", r->phase_handler);
0911 
0912     rc = ph->handler(r);
0913 
0914     if (rc == NGX_DECLINED) {
0915         r->phase_handler++;
0916         return NGX_AGAIN;
0917     }
0918 
0919     if (rc == NGX_DONE) {
0920         return NGX_OK;
0921     }
0922 
0923     /* NGX_OK, NGX_AGAIN, NGX_ERROR, NGX_HTTP_...  */
0924 
0925     ngx_http_finalize_request(r, rc);
0926 
0927     return NGX_OK;
0928 }
0929 
0930 
0931 ngx_int_t
0932 ngx_http_core_find_config_phase(ngx_http_request_t *r,
0933     ngx_http_phase_handler_t *ph)
0934 {
0935     u_char                    *p;
0936     size_t                     len;
0937     ngx_int_t                  rc;
0938     ngx_http_core_loc_conf_t  *clcf;
0939 
0940     r->content_handler = NULL;
0941     r->uri_changed = 0;
0942 
0943     rc = ngx_http_core_find_location(r);
0944 
0945     if (rc == NGX_ERROR) {
0946         ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
0947         return NGX_OK;
0948     }
0949 
0950     clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
0951 
0952     if (!r->internal && clcf->internal) {
0953         ngx_http_finalize_request(r, NGX_HTTP_NOT_FOUND);
0954         return NGX_OK;
0955     }
0956 
0957     ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
0958                    "using configuration \"%s%V\"",
0959                    (clcf->noname ? "*" : (clcf->exact_match ? "=" : "")),
0960                    &clcf->name);
0961 
0962     ngx_http_update_location_config(r);
0963 
0964     ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
0965                    "http cl:%O max:%O",
0966                    r->headers_in.content_length_n, clcf->client_max_body_size);
0967 
0968     if (r->headers_in.content_length_n != -1
0969         && !r->discard_body
0970         && clcf->client_max_body_size
0971         && clcf->client_max_body_size < r->headers_in.content_length_n)
0972     {
0973         ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
0974                       "client intended to send too large body: %O bytes",
0975                       r->headers_in.content_length_n);
0976 
0977         r->expect_tested = 1;
0978         (void) ngx_http_discard_request_body(r);
0979         ngx_http_finalize_request(r, NGX_HTTP_REQUEST_ENTITY_TOO_LARGE);
0980         return NGX_OK;
0981     }
0982 
0983     if (rc == NGX_DONE) {
0984         ngx_http_clear_location(r);
0985 
0986         r->headers_out.location = ngx_list_push(&r->headers_out.headers);
0987         if (r->headers_out.location == NULL) {
0988             ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
0989             return NGX_OK;
0990         }
0991 
0992         r->headers_out.location->hash = 1;
0993         ngx_str_set(&r->headers_out.location->key, "Location");
0994 
0995         if (r->args.len == 0) {
0996             r->headers_out.location->value = clcf->name;
0997 
0998         } else {
0999             len = clcf->name.len + 1 + r->args.len;
1000             p = ngx_pnalloc(r->pool, len);
1001 
1002             if (p == NULL) {
1003                 ngx_http_clear_location(r);
1004                 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
1005                 return NGX_OK;
1006             }
1007 
1008             r->headers_out.location->value.len = len;
1009             r->headers_out.location->value.data = p;
1010 
1011             p = ngx_cpymem(p, clcf->name.data, clcf->name.len);
1012             *p++ = '?';
1013             ngx_memcpy(p, r->args.data, r->args.len);
1014         }
1015 
1016         ngx_http_finalize_request(r, NGX_HTTP_MOVED_PERMANENTLY);
1017         return NGX_OK;
1018     }
1019 
1020     r->phase_handler++;
1021     return NGX_AGAIN;
1022 }
1023 
1024 
1025 ngx_int_t
1026 ngx_http_core_post_rewrite_phase(ngx_http_request_t *r,
1027     ngx_http_phase_handler_t *ph)
1028 {
1029     ngx_http_core_srv_conf_t  *cscf;
1030 
1031     ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1032                    "post rewrite phase: %ui", r->phase_handler);
1033 
1034     if (!r->uri_changed) {
1035         r->phase_handler++;
1036         return NGX_AGAIN;
1037     }
1038 
1039     ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1040                    "uri changes: %d", r->uri_changes);
1041 
1042     /*
1043      * gcc before 3.3 compiles the broken code for
1044      *     if (r->uri_changes-- == 0)
1045      * if the r->uri_changes is defined as
1046      *     unsigned  uri_changes:4
1047      */
1048 
1049     r->uri_changes--;
1050 
1051     if (r->uri_changes == 0) {
1052         ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
1053                       "rewrite or internal redirection cycle "
1054                       "while processing \"%V\"", &r->uri);
1055 
1056         ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
1057         return NGX_OK;
1058     }
1059 
1060     r->phase_handler = ph->next;
1061 
1062     cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
1063     r->loc_conf = cscf->ctx->loc_conf;
1064 
1065     return NGX_AGAIN;
1066 }
1067 
1068 
1069 ngx_int_t
1070 ngx_http_core_access_phase(ngx_http_request_t *r, ngx_http_phase_handler_t *ph)
1071 {
1072     ngx_int_t                  rc;
1073     ngx_http_core_loc_conf_t  *clcf;
1074 
1075     if (r != r->main) {
1076         r->phase_handler = ph->next;
1077         return NGX_AGAIN;
1078     }
1079 
1080     ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1081                    "access phase: %ui", r->phase_handler);
1082 
1083     rc = ph->handler(r);
1084 
1085     if (rc == NGX_DECLINED) {
1086         r->phase_handler++;
1087         return NGX_AGAIN;
1088     }
1089 
1090     if (rc == NGX_AGAIN || rc == NGX_DONE) {
1091         return NGX_OK;
1092     }
1093 
1094     clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
1095 
1096     if (clcf->satisfy == NGX_HTTP_SATISFY_ALL) {
1097 
1098         if (rc == NGX_OK) {
1099             r->phase_handler++;
1100             return NGX_AGAIN;
1101         }
1102 
1103     } else {
1104         if (rc == NGX_OK) {
1105             r->access_code = 0;
1106 
1107             if (r->headers_out.www_authenticate) {
1108                 r->headers_out.www_authenticate->hash = 0;
1109             }
1110 
1111             r->phase_handler = ph->next;
1112             return NGX_AGAIN;
1113         }
1114 
1115         if (rc == NGX_HTTP_FORBIDDEN || rc == NGX_HTTP_UNAUTHORIZED) {
1116             if (r->access_code != NGX_HTTP_UNAUTHORIZED) {
1117                 r->access_code = rc;
1118             }
1119 
1120             r->phase_handler++;
1121             return NGX_AGAIN;
1122         }
1123     }
1124 
1125     /* rc == NGX_ERROR || rc == NGX_HTTP_...  */
1126 
1127     ngx_http_finalize_request(r, rc);
1128     return NGX_OK;
1129 }
1130 
1131 
1132 ngx_int_t
1133 ngx_http_core_post_access_phase(ngx_http_request_t *r,
1134     ngx_http_phase_handler_t *ph)
1135 {
1136     ngx_int_t  access_code;
1137 
1138     ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1139                    "post access phase: %ui", r->phase_handler);
1140 
1141     access_code = r->access_code;
1142 
1143     if (access_code) {
1144         if (access_code == NGX_HTTP_FORBIDDEN) {
1145             ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
1146                           "access forbidden by rule");
1147         }
1148 
1149         r->access_code = 0;
1150         ngx_http_finalize_request(r, access_code);
1151         return NGX_OK;
1152     }
1153 
1154     r->phase_handler++;
1155     return NGX_AGAIN;
1156 }
1157 
1158 
1159 ngx_int_t
1160 ngx_http_core_content_phase(ngx_http_request_t *r,
1161     ngx_http_phase_handler_t *ph)
1162 {
1163     size_t     root;
1164     ngx_int_t  rc;
1165     ngx_str_t  path;
1166 
1167     if (r->content_handler) {
1168         r->write_event_handler = ngx_http_request_empty_handler;
1169         ngx_http_finalize_request(r, r->content_handler(r));
1170         return NGX_OK;
1171     }
1172 
1173     ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1174                    "content phase: %ui", r->phase_handler);
1175 
1176     rc = ph->handler(r);
1177 
1178     if (rc != NGX_DECLINED) {
1179         ngx_http_finalize_request(r, rc);
1180         return NGX_OK;
1181     }
1182 
1183     /* rc == NGX_DECLINED */
1184 
1185     ph++;
1186 
1187     if (ph->checker) {
1188         r->phase_handler++;
1189         return NGX_AGAIN;
1190     }
1191 
1192     /* no content handler was found */
1193 
1194     if (r->uri.data[r->uri.len - 1] == '/') {
1195 
1196         if (ngx_http_map_uri_to_path(r, &path, &root, 0) != NULL) {
1197             ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
1198                           "directory index of \"%s\" is forbidden", path.data);
1199         }
1200 
1201         ngx_http_finalize_request(r, NGX_HTTP_FORBIDDEN);
1202         return NGX_OK;
1203     }
1204 
1205     ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "no handler found");
1206 
1207     ngx_http_finalize_request(r, NGX_HTTP_NOT_FOUND);
1208     return NGX_OK;
1209 }
1210 
1211 
1212 void
1213 ngx_http_update_location_config(ngx_http_request_t *r)
1214 {
1215     ngx_http_core_loc_conf_t  *clcf;
1216 
1217     clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
1218 
1219     if (r->method & clcf->limit_except) {
1220         r->loc_conf = clcf->limit_except_loc_conf;
1221         clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
1222     }
1223 
1224     if (r == r->main) {
1225         ngx_set_connection_log(r->connection, clcf->error_log);
1226     }
1227 
1228     if ((ngx_io.flags & NGX_IO_SENDFILE) && clcf->sendfile) {
1229         r->connection->sendfile = 1;
1230 
1231     } else {
1232         r->connection->sendfile = 0;
1233     }
1234 
1235     if (clcf->client_body_in_file_only) {
1236         r->request_body_in_file_only = 1;
1237         r->request_body_in_persistent_file = 1;
1238         r->request_body_in_clean_file =
1239             clcf->client_body_in_file_only == NGX_HTTP_REQUEST_BODY_FILE_CLEAN;
1240         r->request_body_file_log_level = NGX_LOG_NOTICE;
1241 
1242     } else {
1243         r->request_body_file_log_level = NGX_LOG_WARN;
1244     }
1245 
1246     r->request_body_in_single_buf = clcf->client_body_in_single_buffer;
1247 
1248     if (r->keepalive) {
1249         if (clcf->keepalive_timeout == 0) {
1250             r->keepalive = 0;
1251 
1252         } else if (r->connection->requests >= clcf->keepalive_requests) {
1253             r->keepalive = 0;
1254 
1255         } else if (r->headers_in.msie6
1256                    && r->method == NGX_HTTP_POST
1257                    && (clcf->keepalive_disable
1258                        & NGX_HTTP_KEEPALIVE_DISABLE_MSIE6))
1259         {
1260             /*
1261              * MSIE may wait for some time if an response for
1262              * a POST request was sent over a keepalive connection
1263              */
1264             r->keepalive = 0;
1265 
1266         } else if (r->headers_in.safari
1267                    && (clcf->keepalive_disable
1268                        & NGX_HTTP_KEEPALIVE_DISABLE_SAFARI))
1269         {
1270             /*
1271              * Safari may send a POST request to a closed keepalive
1272              * connection and may stall for some time, see
1273              *     https://bugs.webkit.org/show_bug.cgi?id=5760
1274              */
1275             r->keepalive = 0;
1276         }
1277     }
1278 
1279     if (!clcf->tcp_nopush) {
1280         /* disable TCP_NOPUSH/TCP_CORK use */
1281         r->connection->tcp_nopush = NGX_TCP_NOPUSH_DISABLED;
1282     }
1283 
1284     if (r->limit_rate == 0) {
1285         r->limit_rate = clcf->limit_rate;
1286     }
1287 
1288     if (clcf->handler) {
1289         r->content_handler = clcf->handler;
1290     }
1291 }
1292 
1293 
1294 /*
1295  * NGX_OK       - exact or regex match
1296  * NGX_DONE     - auto redirect
1297  * NGX_AGAIN    - inclusive match
1298  * NGX_ERROR    - regex error
1299  * NGX_DECLINED - no match
1300  */
1301 
1302 static ngx_int_t
1303 ngx_http_core_find_location(ngx_http_request_t *r)
1304 {
1305     ngx_int_t                  rc;
1306     ngx_http_core_loc_conf_t  *pclcf;
1307 #if (NGX_PCRE)
1308     ngx_int_t                  n;
1309     ngx_uint_t                 noregex;
1310     ngx_http_core_loc_conf_t  *clcf, **clcfp;
1311 
1312     noregex = 0;
1313 #endif
1314 
1315     pclcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
1316 
1317     rc = ngx_http_core_find_static_location(r, pclcf->static_locations);
1318 
1319     if (rc == NGX_AGAIN) {
1320 
1321 #if (NGX_PCRE)
1322         clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
1323 
1324         noregex = clcf->noregex;
1325 #endif
1326 
1327         /* look up nested locations */
1328 
1329         rc = ngx_http_core_find_location(r);
1330     }
1331 
1332     if (rc == NGX_OK || rc == NGX_DONE) {
1333         return rc;
1334     }
1335 
1336     /* rc == NGX_DECLINED or rc == NGX_AGAIN in nested location */
1337 
1338 #if (NGX_PCRE)
1339 
1340     if (noregex == 0 && pclcf->regex_locations) {
1341 
1342         for (clcfp = pclcf->regex_locations; *clcfp; clcfp++) {
1343 
1344             ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1345                            "test location: ~ \"%V\"", &(*clcfp)->name);
1346 
1347             n = ngx_http_regex_exec(r, (*clcfp)->regex, &r->uri);
1348 
1349             if (n == NGX_OK) {
1350                 r->loc_conf = (*clcfp)->loc_conf;
1351 
1352                 /* look up nested locations */
1353 
1354                 rc = ngx_http_core_find_location(r);
1355 
1356                 return (rc == NGX_ERROR) ? rc : NGX_OK;
1357             }
1358 
1359             if (n == NGX_DECLINED) {
1360                 continue;
1361             }
1362 
1363             return NGX_ERROR;
1364         }
1365     }
1366 #endif
1367 
1368     return rc;
1369 }
1370 
1371 
1372 /*
1373  * NGX_OK       - exact match
1374  * NGX_DONE     - auto redirect
1375  * NGX_AGAIN    - inclusive match
1376  * NGX_DECLINED - no match
1377  */
1378 
1379 static ngx_int_t
1380 ngx_http_core_find_static_location(ngx_http_request_t *r,
1381     ngx_http_location_tree_node_t *node)
1382 {
1383     u_char     *uri;
1384     size_t      len, n;
1385     ngx_int_t   rc, rv;
1386 
1387     len = r->uri.len;
1388     uri = r->uri.data;
1389 
1390     rv = NGX_DECLINED;
1391 
1392     for ( ;; ) {
1393 
1394         if (node == NULL) {
1395             return rv;
1396         }
1397 
1398         ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1399                        "test location: \"%*s\"",
1400                        (size_t) node->len, node->name);
1401 
1402         n = (len <= (size_t) node->len) ? len : node->len;
1403 
1404         rc = ngx_filename_cmp(uri, node->name, n);
1405 
1406         if (rc != 0) {
1407             node = (rc < 0) ? node->left : node->right;
1408 
1409             continue;
1410         }
1411 
1412         if (len > (size_t) node->len) {
1413 
1414             if (node->inclusive) {
1415 
1416                 r->loc_conf = node->inclusive->loc_conf;
1417                 rv = NGX_AGAIN;
1418 
1419                 node = node->tree;
1420                 uri += n;
1421                 len -= n;
1422 
1423                 continue;
1424             }
1425 
1426             /* exact only */
1427 
1428             node = node->right;
1429 
1430             continue;
1431         }
1432 
1433         if (len == (size_t) node->len) {
1434 
1435             if (node->exact) {
1436                 r->loc_conf = node->exact->loc_conf;
1437                 return NGX_OK;
1438 
1439             } else {
1440                 r->loc_conf = node->inclusive->loc_conf;
1441                 return NGX_AGAIN;
1442             }
1443         }
1444 
1445         /* len < node->len */
1446 
1447         if (len + 1 == (size_t) node->len && node->auto_redirect) {
1448 
1449             r->loc_conf = (node->exact) ? node->exact->loc_conf:
1450                                           node->inclusive->loc_conf;
1451             rv = NGX_DONE;
1452         }
1453 
1454         node = node->left;
1455     }
1456 }
1457 
1458 
1459 void *
1460 ngx_http_test_content_type(ngx_http_request_t *r, ngx_hash_t *types_hash)
1461 {
1462     u_char      c, *lowcase;
1463     size_t      len;
1464     ngx_uint_t  i, hash;
1465 
1466     if (types_hash->size == 0) {
1467         return (void *) 4;
1468     }
1469 
1470     if (r->headers_out.content_type.len == 0) {
1471         return NULL;
1472     }
1473 
1474     len = r->headers_out.content_type_len;
1475 
1476     if (r->headers_out.content_type_lowcase == NULL) {
1477 
1478         lowcase = ngx_pnalloc(r->pool, len);
1479         if (lowcase == NULL) {
1480             return NULL;
1481         }
1482 
1483         r->headers_out.content_type_lowcase = lowcase;
1484 
1485         hash = 0;
1486 
1487         for (i = 0; i < len; i++) {
1488             c = ngx_tolower(r->headers_out.content_type.data[i]);
1489             hash = ngx_hash(hash, c);
1490             lowcase[i] = c;
1491         }
1492 
1493         r->headers_out.content_type_hash = hash;
1494     }
1495 
1496     return ngx_hash_find(types_hash, r->headers_out.content_type_hash,
1497                          r->headers_out.content_type_lowcase, len);
1498 }
1499 
1500 
1501 ngx_int_t
1502 ngx_http_set_content_type(ngx_http_request_t *r)
1503 {
1504     u_char                     c, *exten;
1505     ngx_str_t                 *type;
1506     ngx_uint_t                 i, hash;
1507     ngx_http_core_loc_conf_t  *clcf;
1508 
1509     if (r->headers_out.content_type.len) {
1510         return NGX_OK;
1511     }
1512 
1513     clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
1514 
1515     if (r->exten.len) {
1516 
1517         hash = 0;
1518 
1519         for (i = 0; i < r->exten.len; i++) {
1520             c = r->exten.data[i];
1521 
1522             if (c >= 'A' && c <= 'Z') {
1523 
1524                 exten = ngx_pnalloc(r->pool, r->exten.len);
1525                 if (exten == NULL) {
1526                     return NGX_ERROR;
1527                 }
1528 
1529                 hash = ngx_hash_strlow(exten, r->exten.data, r->exten.len);
1530 
1531                 r->exten.data = exten;
1532 
1533                 break;
1534             }
1535 
1536             hash = ngx_hash(hash, c);
1537         }
1538 
1539         type = ngx_hash_find(&clcf->types_hash, hash,
1540                              r->exten.data, r->exten.len);
1541 
1542         if (type) {
1543             r->headers_out.content_type_len = type->len;
1544             r->headers_out.content_type = *type;
1545 
1546             return NGX_OK;
1547         }
1548     }
1549 
1550     r->headers_out.content_type_len = clcf->default_type.len;
1551     r->headers_out.content_type = clcf->default_type;
1552 
1553     return NGX_OK;
1554 }
1555 
1556 
1557 void
1558 ngx_http_set_exten(ngx_http_request_t *r)
1559 {
1560     ngx_int_t  i;
1561 
1562     ngx_str_null(&r->exten);
1563 
1564     for (i = r->uri.len - 1; i > 1; i--) {
1565         if (r->uri.data[i] == '.' && r->uri.data[i - 1] != '/') {
1566 
1567             r->exten.len = r->uri.len - i - 1;
1568             r->exten.data = &r->uri.data[i + 1];
1569 
1570             return;
1571 
1572         } else if (r->uri.data[i] == '/') {
1573             return;
1574         }
1575     }
1576 
1577     return;
1578 }
1579 
1580 
1581 ngx_int_t
1582 ngx_http_set_etag(ngx_http_request_t *r)
1583 {
1584     ngx_table_elt_t           *etag;
1585     ngx_http_core_loc_conf_t  *clcf;
1586 
1587     clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
1588 
1589     if (!clcf->etag) {
1590         return NGX_OK;
1591     }
1592 
1593     etag = ngx_list_push(&r->headers_out.headers);
1594     if (etag == NULL) {
1595         return NGX_ERROR;
1596     }
1597 
1598     etag->hash = 1;
1599     ngx_str_set(&etag->key, "ETag");
1600 
1601     etag->value.data = ngx_pnalloc(r->pool, NGX_OFF_T_LEN + NGX_TIME_T_LEN + 3);
1602     if (etag->value.data == NULL) {
1603         etag->hash = 0;
1604         return NGX_ERROR;
1605     }
1606 
1607     etag->value.len = ngx_sprintf(etag->value.data, "\"%xT-%xO\"",
1608                                   r->headers_out.last_modified_time,
1609                                   r->headers_out.content_length_n)
1610                       - etag->value.data;
1611 
1612     r->headers_out.etag = etag;
1613 
1614     return NGX_OK;
1615 }
1616 
1617 
1618 void
1619 ngx_http_weak_etag(ngx_http_request_t *r)
1620 {
1621     size_t            len;
1622     u_char           *p;
1623     ngx_table_elt_t  *etag;
1624 
1625     etag = r->headers_out.etag;
1626 
1627     if (etag == NULL) {
1628         return;
1629     }
1630 
1631     if (etag->value.len > 2
1632         && etag->value.data[0] == 'W'
1633         && etag->value.data[1] == '/')
1634     {
1635         return;
1636     }
1637 
1638     if (etag->value.len < 1 || etag->value.data[0] != '"') {
1639         r->headers_out.etag->hash = 0;
1640         r->headers_out.etag = NULL;
1641         return;
1642     }
1643 
1644     p = ngx_pnalloc(r->pool, etag->value.len + 2);
1645     if (p == NULL) {
1646         r->headers_out.etag->hash = 0;
1647         r->headers_out.etag = NULL;
1648         return;
1649     }
1650 
1651     len = ngx_sprintf(p, "W/%V", &etag->value) - p;
1652 
1653     etag->value.data = p;
1654     etag->value.len = len;
1655 }
1656 
1657 
1658 ngx_int_t
1659 ngx_http_send_response(ngx_http_request_t *r, ngx_uint_t status,
1660     ngx_str_t *ct, ngx_http_complex_value_t *cv)
1661 {
1662     ngx_int_t     rc;
1663     ngx_str_t     val;
1664     ngx_buf_t    *b;
1665     ngx_chain_t   out;
1666 
1667     if (ngx_http_discard_request_body(r) != NGX_OK) {
1668         return NGX_HTTP_INTERNAL_SERVER_ERROR;
1669     }
1670 
1671     r->headers_out.status = status;
1672 
1673     if (ngx_http_complex_value(r, cv, &val) != NGX_OK) {
1674         return NGX_HTTP_INTERNAL_SERVER_ERROR;
1675     }
1676 
1677     if (status == NGX_HTTP_MOVED_PERMANENTLY
1678         || status == NGX_HTTP_MOVED_TEMPORARILY
1679         || status == NGX_HTTP_SEE_OTHER
1680         || status == NGX_HTTP_TEMPORARY_REDIRECT
1681         || status == NGX_HTTP_PERMANENT_REDIRECT)
1682     {
1683         ngx_http_clear_location(r);
1684 
1685         r->headers_out.location = ngx_list_push(&r->headers_out.headers);
1686         if (r->headers_out.location == NULL) {
1687             return NGX_HTTP_INTERNAL_SERVER_ERROR;
1688         }
1689 
1690         r->headers_out.location->hash = 1;
1691         ngx_str_set(&r->headers_out.location->key, "Location");
1692         r->headers_out.location->value = val;
1693 
1694         return status;
1695     }
1696 
1697     r->headers_out.content_length_n = val.len;
1698 
1699     if (ct) {
1700         r->headers_out.content_type_len = ct->len;
1701         r->headers_out.content_type = *ct;
1702 
1703     } else {
1704         if (ngx_http_set_content_type(r) != NGX_OK) {
1705             return NGX_HTTP_INTERNAL_SERVER_ERROR;
1706         }
1707     }
1708 
1709     if (r->method == NGX_HTTP_HEAD || (r != r->main && val.len == 0)) {
1710         return ngx_http_send_header(r);
1711     }
1712 
1713     b = ngx_calloc_buf(r->pool);
1714     if (b == NULL) {
1715         return NGX_HTTP_INTERNAL_SERVER_ERROR;
1716     }
1717 
1718     b->pos = val.data;
1719     b->last = val.data + val.len;
1720     b->memory = val.len ? 1 : 0;
1721     b->last_buf = (r == r->main) ? 1 : 0;
1722     b->last_in_chain = 1;
1723 
1724     out.buf = b;
1725     out.next = NULL;
1726 
1727     rc = ngx_http_send_header(r);
1728 
1729     if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) {
1730         return rc;
1731     }
1732 
1733     return ngx_http_output_filter(r, &out);
1734 }
1735 
1736 
1737 ngx_int_t
1738 ngx_http_send_header(ngx_http_request_t *r)
1739 {
1740     if (r->post_action) {
1741         return NGX_OK;
1742     }
1743 
1744     if (r->header_sent) {
1745         ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
1746                       "header already sent");
1747         return NGX_ERROR;
1748     }
1749 
1750     if (r->err_status) {
1751         r->headers_out.status = r->err_status;
1752         r->headers_out.status_line.len = 0;
1753     }
1754 
1755     return ngx_http_top_header_filter(r);
1756 }
1757 
1758 
1759 ngx_int_t
1760 ngx_http_output_filter(ngx_http_request_t *r, ngx_chain_t *in)
1761 {
1762     ngx_int_t          rc;
1763     ngx_connection_t  *c;
1764 
1765     c = r->connection;
1766 
1767     ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
1768                    "http output filter \"%V?%V\"", &r->uri, &r->args);
1769 
1770     rc = ngx_http_top_body_filter(r, in);
1771 
1772     if (rc == NGX_ERROR) {
1773         /* NGX_ERROR may be returned by any filter */
1774         c->error = 1;
1775     }
1776 
1777     return rc;
1778 }
1779 
1780 
1781 u_char *
1782 ngx_http_map_uri_to_path(ngx_http_request_t *r, ngx_str_t *path,
1783     size_t *root_length, size_t reserved)
1784 {
1785     u_char                    *last;
1786     size_t                     alias;
1787     ngx_http_core_loc_conf_t  *clcf;
1788 
1789     clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
1790 
1791     alias = clcf->alias;
1792 
1793     if (alias && !r->valid_location) {
1794         ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
1795                       "\"alias\" cannot be used in location \"%V\" "
1796                       "where URI was rewritten", &clcf->name);
1797         return NULL;
1798     }
1799 
1800     if (clcf->root_lengths == NULL) {
1801 
1802         *root_length = clcf->root.len;
1803 
1804         path->len = clcf->root.len + reserved + r->uri.len - alias + 1;
1805 
1806         path->data = ngx_pnalloc(r->pool, path->len);
1807         if (path->data == NULL) {
1808             return NULL;
1809         }
1810 
1811         last = ngx_copy(path->data, clcf->root.data, clcf->root.len);
1812 
1813     } else {
1814 
1815         if (alias == NGX_MAX_SIZE_T_VALUE) {
1816             reserved += r->add_uri_to_alias ? r->uri.len + 1 : 1;
1817 
1818         } else {
1819             reserved += r->uri.len - alias + 1;
1820         }
1821 
1822         if (ngx_http_script_run(r, path, clcf->root_lengths->elts, reserved,
1823                                 clcf->root_values->elts)
1824             == NULL)
1825         {
1826             return NULL;
1827         }
1828 
1829         if (ngx_get_full_name(r->pool, (ngx_str_t *) &ngx_cycle->prefix, path)
1830             != NGX_OK)
1831         {
1832             return NULL;
1833         }
1834 
1835         *root_length = path->len - reserved;
1836         last = path->data + *root_length;
1837 
1838         if (alias == NGX_MAX_SIZE_T_VALUE) {
1839             if (!r->add_uri_to_alias) {
1840                 *last = '\0';
1841                 return last;
1842             }
1843 
1844             alias = 0;
1845         }
1846     }
1847 
1848     last = ngx_cpystrn(last, r->uri.data + alias, r->uri.len - alias + 1);
1849 
1850     return last;
1851 }
1852 
1853 
1854 ngx_int_t
1855 ngx_http_auth_basic_user(ngx_http_request_t *r)
1856 {
1857     ngx_str_t   auth, encoded;
1858     ngx_uint_t  len;
1859 
1860     if (r->headers_in.user.len == 0 && r->headers_in.user.data != NULL) {
1861         return NGX_DECLINED;
1862     }
1863 
1864     if (r->headers_in.authorization == NULL) {
1865         r->headers_in.user.data = (u_char *) "";
1866         return NGX_DECLINED;
1867     }
1868 
1869     encoded = r->headers_in.authorization->value;
1870 
1871     if (encoded.len < sizeof("Basic ") - 1
1872         || ngx_strncasecmp(encoded.data, (u_char *) "Basic ",
1873                            sizeof("Basic ") - 1)
1874            != 0)
1875     {
1876         r->headers_in.user.data = (u_char *) "";
1877         return NGX_DECLINED;
1878     }
1879 
1880     encoded.len -= sizeof("Basic ") - 1;
1881     encoded.data += sizeof("Basic ") - 1;
1882 
1883     while (encoded.len && encoded.data[0] == ' ') {
1884         encoded.len--;
1885         encoded.data++;
1886     }
1887 
1888     if (encoded.len == 0) {
1889         r->headers_in.user.data = (u_char *) "";
1890         return NGX_DECLINED;
1891     }
1892 
1893     auth.len = ngx_base64_decoded_length(encoded.len);
1894     auth.data = ngx_pnalloc(r->pool, auth.len + 1);
1895     if (auth.data == NULL) {
1896         return NGX_ERROR;
1897     }
1898 
1899     if (ngx_decode_base64(&auth, &encoded) != NGX_OK) {
1900         r->headers_in.user.data = (u_char *) "";
1901         return NGX_DECLINED;
1902     }
1903 
1904     auth.data[auth.len] = '\0';
1905 
1906     for (len = 0; len < auth.len; len++) {
1907         if (auth.data[len] == ':') {
1908             break;
1909         }
1910     }
1911 
1912     if (len == 0 || len == auth.len) {
1913         r->headers_in.user.data = (u_char *) "";
1914         return NGX_DECLINED;
1915     }
1916 
1917     r->headers_in.user.len = len;
1918     r->headers_in.user.data = auth.data;
1919     r->headers_in.passwd.len = auth.len - len - 1;
1920     r->headers_in.passwd.data = &auth.data[len + 1];
1921 
1922     return NGX_OK;
1923 }
1924 
1925 
1926 #if (NGX_HTTP_GZIP)
1927 
1928 ngx_int_t
1929 ngx_http_gzip_ok(ngx_http_request_t *r)
1930 {
1931     time_t                     date, expires;
1932     ngx_uint_t                 p;
1933     ngx_array_t               *cc;
1934     ngx_table_elt_t           *e, *d, *ae;
1935     ngx_http_core_loc_conf_t  *clcf;
1936 
1937     r->gzip_tested = 1;
1938 
1939     if (r != r->main) {
1940         return NGX_DECLINED;
1941     }
1942 
1943     ae = r->headers_in.accept_encoding;
1944     if (ae == NULL) {
1945         return NGX_DECLINED;
1946     }
1947 
1948     if (ae->value.len < sizeof("gzip") - 1) {
1949         return NGX_DECLINED;
1950     }
1951 
1952     /*
1953      * test first for the most common case "gzip,...":
1954      *   MSIE:    "gzip, deflate"
1955      *   Firefox: "gzip,deflate"
1956      *   Chrome:  "gzip,deflate,sdch"
1957      *   Safari:  "gzip, deflate"
1958      *   Opera:   "gzip, deflate"
1959      */
1960 
1961     if (ngx_memcmp(ae->value.data, "gzip,", 5) != 0
1962         && ngx_http_gzip_accept_encoding(&ae->value) != NGX_OK)
1963     {
1964         return NGX_DECLINED;
1965     }
1966 
1967     clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
1968 
1969     if (r->headers_in.msie6 && clcf->gzip_disable_msie6) {
1970         return NGX_DECLINED;
1971     }
1972 
1973     if (r->http_version < clcf->gzip_http_version) {
1974         return NGX_DECLINED;
1975     }
1976 
1977     if (r->headers_in.via == NULL) {
1978         goto ok;
1979     }
1980 
1981     p = clcf->gzip_proxied;
1982 
1983     if (p & NGX_HTTP_GZIP_PROXIED_OFF) {
1984         return NGX_DECLINED;
1985     }
1986 
1987     if (p & NGX_HTTP_GZIP_PROXIED_ANY) {
1988         goto ok;
1989     }
1990 
1991     if (r->headers_in.authorization && (p & NGX_HTTP_GZIP_PROXIED_AUTH)) {
1992         goto ok;
1993     }
1994 
1995     e = r->headers_out.expires;
1996 
1997     if (e) {
1998 
1999         if (!(p & NGX_HTTP_GZIP_PROXIED_EXPIRED)) {
2000             return NGX_DECLINED;
2001         }
2002 
2003         expires = ngx_parse_http_time(e->value.data, e->value.len);
2004         if (expires == NGX_ERROR) {
2005             return NGX_DECLINED;
2006         }
2007 
2008         d = r->headers_out.date;
2009 
2010         if (d) {
2011             date = ngx_parse_http_time(d->value.data, d->value.len);
2012             if (date == NGX_ERROR) {
2013                 return NGX_DECLINED;
2014             }
2015 
2016         } else {
2017             date = ngx_time();
2018         }
2019 
2020         if (expires < date) {
2021             goto ok;
2022         }
2023 
2024         return NGX_DECLINED;
2025     }
2026 
2027     cc = &r->headers_out.cache_control;
2028 
2029     if (cc->elts) {
2030 
2031         if ((p & NGX_HTTP_GZIP_PROXIED_NO_CACHE)
2032             && ngx_http_parse_multi_header_lines(cc, &ngx_http_gzip_no_cache,
2033                                                  NULL)
2034                >= 0)
2035         {
2036             goto ok;
2037         }
2038 
2039         if ((p & NGX_HTTP_GZIP_PROXIED_NO_STORE)
2040             && ngx_http_parse_multi_header_lines(cc, &ngx_http_gzip_no_store,
2041                                                  NULL)
2042                >= 0)
2043         {
2044             goto ok;
2045         }
2046 
2047         if ((p & NGX_HTTP_GZIP_PROXIED_PRIVATE)
2048             && ngx_http_parse_multi_header_lines(cc, &ngx_http_gzip_private,
2049                                                  NULL)
2050                >= 0)
2051         {
2052             goto ok;
2053         }
2054 
2055         return NGX_DECLINED;
2056     }
2057 
2058     if ((p & NGX_HTTP_GZIP_PROXIED_NO_LM) && r->headers_out.last_modified) {
2059         return NGX_DECLINED;
2060     }
2061 
2062     if ((p & NGX_HTTP_GZIP_PROXIED_NO_ETAG) && r->headers_out.etag) {
2063         return NGX_DECLINED;
2064     }
2065 
2066 ok:
2067 
2068 #if (NGX_PCRE)
2069 
2070     if (clcf->gzip_disable && r->headers_in.user_agent) {
2071 
2072         if (ngx_regex_exec_array(clcf->gzip_disable,
2073                                  &r->headers_in.user_agent->value,
2074                                  r->connection->log)
2075             != NGX_DECLINED)
2076         {
2077             return NGX_DECLINED;
2078         }
2079     }
2080 
2081 #endif
2082 
2083     r->gzip_ok = 1;
2084 
2085     return NGX_OK;
2086 }
2087 
2088 
2089 /*
2090  * gzip is enabled for the following quantities:
2091  *     "gzip; q=0.001" ... "gzip; q=1.000"
2092  * gzip is disabled for the following quantities:
2093  *     "gzip; q=0" ... "gzip; q=0.000", and for any invalid cases
2094  */
2095 
2096 static ngx_int_t
2097 ngx_http_gzip_accept_encoding(ngx_str_t *ae)
2098 {
2099     u_char  *p, *start, *last;
2100 
2101     start = ae->data;
2102     last = start + ae->len;
2103 
2104     for ( ;; ) {
2105         p = ngx_strcasestrn(start, "gzip", 4 - 1);
2106         if (p == NULL) {
2107             return NGX_DECLINED;
2108         }
2109 
2110         if (p == start || (*(p - 1) == ',' || *(p - 1) == ' ')) {
2111             break;
2112         }
2113 
2114         start = p + 4;
2115     }
2116 
2117     p += 4;
2118 
2119     while (p < last) {
2120         switch (*p++) {
2121         case ',':
2122             return NGX_OK;
2123         case ';':
2124             goto quantity;
2125         case ' ':
2126             continue;
2127         default:
2128             return NGX_DECLINED;
2129         }
2130     }
2131 
2132     return NGX_OK;
2133 
2134 quantity:
2135 
2136     while (p < last) {
2137         switch (*p++) {
2138         case 'q':
2139         case 'Q':
2140             goto equal;
2141         case ' ':
2142             continue;
2143         default:
2144             return NGX_DECLINED;
2145         }
2146     }
2147 
2148     return NGX_OK;
2149 
2150 equal:
2151 
2152     if (p + 2 > last || *p++ != '=') {
2153         return NGX_DECLINED;
2154     }
2155 
2156     if (ngx_http_gzip_quantity(p, last) == 0) {
2157         return NGX_DECLINED;
2158     }
2159 
2160     return NGX_OK;
2161 }
2162 
2163 
2164 static ngx_uint_t
2165 ngx_http_gzip_quantity(u_char *p, u_char *last)
2166 {
2167     u_char      c;
2168     ngx_uint_t  n, q;
2169 
2170     c = *p++;
2171 
2172     if (c != '0' && c != '1') {
2173         return 0;
2174     }
2175 
2176     q = (c - '0') * 100;
2177 
2178     if (p == last) {
2179         return q;
2180     }
2181 
2182     c = *p++;
2183 
2184     if (c == ',' || c == ' ') {
2185         return q;
2186     }
2187 
2188     if (c != '.') {
2189         return 0;
2190     }
2191 
2192     n = 0;
2193 
2194     while (p < last) {
2195         c = *p++;
2196 
2197         if (c == ',' || c == ' ') {
2198             break;
2199         }
2200 
2201         if (c >= '0' && c <= '9') {
2202             q += c - '0';
2203             n++;
2204             continue;
2205         }
2206 
2207         return 0;
2208     }
2209 
2210     if (q > 100 || n > 3) {
2211         return 0;
2212     }
2213 
2214     return q;
2215 }
2216 
2217 #endif
2218 
2219 
2220 ngx_int_t
2221 ngx_http_subrequest(ngx_http_request_t *r,
2222     ngx_str_t *uri, ngx_str_t *args, ngx_http_request_t **psr,
2223     ngx_http_post_subrequest_t *ps, ngx_uint_t flags)
2224 {
2225     ngx_time_t                    *tp;
2226     ngx_connection_t              *c;
2227     ngx_http_request_t            *sr;
2228     ngx_http_core_srv_conf_t      *cscf;
2229     ngx_http_postponed_request_t  *pr, *p;
2230 
2231     if (r->subrequests == 0) {
2232         ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
2233                       "subrequests cycle while processing \"%V\"", uri);
2234         return NGX_ERROR;
2235     }
2236 
2237     /*
2238      * 1000 is reserved for other purposes.
2239      */
2240     if (r->main->count >= 65535 - 1000) {
2241         ngx_log_error(NGX_LOG_CRIT, r->connection->log, 0,
2242                       "request reference counter overflow "
2243                       "while processing \"%V\"", uri);
2244         return NGX_ERROR;
2245     }
2246 
2247     if (r->subrequest_in_memory) {
2248         ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
2249                       "nested in-memory subrequest \"%V\"", uri);
2250         return NGX_ERROR;
2251     }
2252 
2253     sr = ngx_pcalloc(r->pool, sizeof(ngx_http_request_t));
2254     if (sr == NULL) {
2255         return NGX_ERROR;
2256     }
2257 
2258     sr->signature = NGX_HTTP_MODULE;
2259 
2260     c = r->connection;
2261     sr->connection = c;
2262 
2263     sr->ctx = ngx_pcalloc(r->pool, sizeof(void *) * ngx_http_max_module);
2264     if (sr->ctx == NULL) {
2265         return NGX_ERROR;
2266     }
2267 
2268     if (ngx_list_init(&sr->headers_out.headers, r->pool, 20,
2269                       sizeof(ngx_table_elt_t))
2270         != NGX_OK)
2271     {
2272         return NGX_ERROR;
2273     }
2274 
2275     if (ngx_list_init(&sr->headers_out.trailers, r->pool, 4,
2276                       sizeof(ngx_table_elt_t))
2277         != NGX_OK)
2278     {
2279         return NGX_ERROR;
2280     }
2281 
2282     cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
2283     sr->main_conf = cscf->ctx->main_conf;
2284     sr->srv_conf = cscf->ctx->srv_conf;
2285     sr->loc_conf = cscf->ctx->loc_conf;
2286 
2287     sr->pool = r->pool;
2288 
2289     sr->headers_in = r->headers_in;
2290 
2291     ngx_http_clear_content_length(sr);
2292     ngx_http_clear_accept_ranges(sr);
2293     ngx_http_clear_last_modified(sr);
2294 
2295     sr->request_body = r->request_body;
2296 
2297 #if (NGX_HTTP_V2)
2298     sr->stream = r->stream;
2299 #endif
2300 
2301     sr->method = NGX_HTTP_GET;
2302     sr->http_version = r->http_version;
2303 
2304     sr->request_line = r->request_line;
2305     sr->uri = *uri;
2306 
2307     if (args) {
2308         sr->args = *args;
2309     }
2310 
2311     ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
2312                    "http subrequest \"%V?%V\"", uri, &sr->args);
2313 
2314     sr->subrequest_in_memory = (flags & NGX_HTTP_SUBREQUEST_IN_MEMORY) != 0;
2315     sr->waited = (flags & NGX_HTTP_SUBREQUEST_WAITED) != 0;
2316     sr->background = (flags & NGX_HTTP_SUBREQUEST_BACKGROUND) != 0;
2317 
2318     sr->unparsed_uri = r->unparsed_uri;
2319     sr->method_name = ngx_http_core_get_method;
2320     sr->http_protocol = r->http_protocol;
2321     sr->schema = r->schema;
2322 
2323     ngx_http_set_exten(sr);
2324 
2325     sr->main = r->main;
2326     sr->parent = r;
2327     sr->post_subrequest = ps;
2328     sr->read_event_handler = ngx_http_request_empty_handler;
2329     sr->write_event_handler = ngx_http_handler;
2330 
2331     sr->variables = r->variables;
2332 
2333     sr->log_handler = r->log_handler;
2334 
2335     if (sr->subrequest_in_memory) {
2336         sr->filter_need_in_memory = 1;
2337     }
2338 
2339     if (!sr->background) {
2340         if (c->data == r && r->postponed == NULL) {
2341             c->data = sr;
2342         }
2343 
2344         pr = ngx_palloc(r->pool, sizeof(ngx_http_postponed_request_t));
2345         if (pr == NULL) {
2346             return NGX_ERROR;
2347         }
2348 
2349         pr->request = sr;
2350         pr->out = NULL;
2351         pr->next = NULL;
2352 
2353         if (r->postponed) {
2354             for (p = r->postponed; p->next; p = p->next) { /* void */ }
2355             p->next = pr;
2356 
2357         } else {
2358             r->postponed = pr;
2359         }
2360     }
2361 
2362     sr->internal = 1;
2363 
2364     sr->discard_body = r->discard_body;
2365     sr->expect_tested = 1;
2366     sr->main_filter_need_in_memory = r->main_filter_need_in_memory;
2367 
2368     sr->uri_changes = NGX_HTTP_MAX_URI_CHANGES + 1;
2369     sr->subrequests = r->subrequests - 1;
2370 
2371     tp = ngx_timeofday();
2372     sr->start_sec = tp->sec;
2373     sr->start_msec = tp->msec;
2374 
2375     r->main->count++;
2376 
2377     *psr = sr;
2378 
2379     if (flags & NGX_HTTP_SUBREQUEST_CLONE) {
2380         sr->method = r->method;
2381         sr->method_name = r->method_name;
2382         sr->loc_conf = r->loc_conf;
2383         sr->valid_location = r->valid_location;
2384         sr->valid_unparsed_uri = r->valid_unparsed_uri;
2385         sr->content_handler = r->content_handler;
2386         sr->phase_handler = r->phase_handler;
2387         sr->write_event_handler = ngx_http_core_run_phases;
2388 
2389 #if (NGX_PCRE)
2390         sr->ncaptures = r->ncaptures;
2391         sr->captures = r->captures;
2392         sr->captures_data = r->captures_data;
2393         sr->realloc_captures = 1;
2394         r->realloc_captures = 1;
2395 #endif
2396 
2397         ngx_http_update_location_config(sr);
2398     }
2399 
2400     return ngx_http_post_request(sr, NULL);
2401 }
2402 
2403 
2404 ngx_int_t
2405 ngx_http_internal_redirect(ngx_http_request_t *r,
2406     ngx_str_t *uri, ngx_str_t *args)
2407 {
2408     ngx_http_core_srv_conf_t  *cscf;
2409 
2410     r->uri_changes--;
2411 
2412     if (r->uri_changes == 0) {
2413         ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
2414                       "rewrite or internal redirection cycle "
2415                       "while internally redirecting to \"%V\"", uri);
2416 
2417         r->main->count++;
2418         ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
2419         return NGX_DONE;
2420     }
2421 
2422     r->uri = *uri;
2423 
2424     if (args) {
2425         r->args = *args;
2426 
2427     } else {
2428         ngx_str_null(&r->args);
2429     }
2430 
2431     ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
2432                    "internal redirect: \"%V?%V\"", uri, &r->args);
2433 
2434     ngx_http_set_exten(r);
2435 
2436     /* clear the modules contexts */
2437     ngx_memzero(r->ctx, sizeof(void *) * ngx_http_max_module);
2438 
2439     cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
2440     r->loc_conf = cscf->ctx->loc_conf;
2441 
2442     ngx_http_update_location_config(r);
2443 
2444 #if (NGX_HTTP_CACHE)
2445     r->cache = NULL;
2446 #endif
2447 
2448     r->internal = 1;
2449     r->valid_unparsed_uri = 0;
2450     r->add_uri_to_alias = 0;
2451     r->main->count++;
2452 
2453     ngx_http_handler(r);
2454 
2455     return NGX_DONE;
2456 }
2457 
2458 
2459 ngx_int_t
2460 ngx_http_named_location(ngx_http_request_t *r, ngx_str_t *name)
2461 {
2462     ngx_http_core_srv_conf_t    *cscf;
2463     ngx_http_core_loc_conf_t   **clcfp;
2464     ngx_http_core_main_conf_t   *cmcf;
2465 
2466     r->main->count++;
2467     r->uri_changes--;
2468 
2469     if (r->uri_changes == 0) {
2470         ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
2471                       "rewrite or internal redirection cycle "
2472                       "while redirect to named location \"%V\"", name);
2473 
2474         ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
2475         return NGX_DONE;
2476     }
2477 
2478     if (r->uri.len == 0) {
2479         ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
2480                       "empty URI in redirect to named location \"%V\"", name);
2481 
2482         ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
2483         return NGX_DONE;
2484     }
2485 
2486     cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
2487 
2488     if (cscf->named_locations) {
2489 
2490         for (clcfp = cscf->named_locations; *clcfp; clcfp++) {
2491 
2492             ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
2493                            "test location: \"%V\"", &(*clcfp)->name);
2494 
2495             if (name->len != (*clcfp)->name.len
2496                 || ngx_strncmp(name->data, (*clcfp)->name.data, name->len) != 0)
2497             {
2498                 continue;
2499             }
2500 
2501             ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
2502                            "using location: %V \"%V?%V\"",
2503                            name, &r->uri, &r->args);
2504 
2505             r->internal = 1;
2506             r->content_handler = NULL;
2507             r->uri_changed = 0;
2508             r->loc_conf = (*clcfp)->loc_conf;
2509 
2510             /* clear the modules contexts */
2511             ngx_memzero(r->ctx, sizeof(void *) * ngx_http_max_module);
2512 
2513             ngx_http_update_location_config(r);
2514 
2515             cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
2516 
2517             r->phase_handler = cmcf->phase_engine.location_rewrite_index;
2518 
2519             r->write_event_handler = ngx_http_core_run_phases;
2520             ngx_http_core_run_phases(r);
2521 
2522             return NGX_DONE;
2523         }
2524     }
2525 
2526     ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
2527                   "could not find named location \"%V\"", name);
2528 
2529     ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
2530 
2531     return NGX_DONE;
2532 }
2533 
2534 
2535 ngx_http_cleanup_t *
2536 ngx_http_cleanup_add(ngx_http_request_t *r, size_t size)
2537 {
2538     ngx_http_cleanup_t  *cln;
2539 
2540     r = r->main;
2541 
2542     cln = ngx_palloc(r->pool, sizeof(ngx_http_cleanup_t));
2543     if (cln == NULL) {
2544         return NULL;
2545     }
2546 
2547     if (size) {
2548         cln->data = ngx_palloc(r->pool, size);
2549         if (cln->data == NULL) {
2550             return NULL;
2551         }
2552 
2553     } else {
2554         cln->data = NULL;
2555     }
2556 
2557     cln->handler = NULL;
2558     cln->next = r->cleanup;
2559 
2560     r->cleanup = cln;
2561 
2562     ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
2563                    "http cleanup add: %p", cln);
2564 
2565     return cln;
2566 }
2567 
2568 
2569 ngx_int_t
2570 ngx_http_set_disable_symlinks(ngx_http_request_t *r,
2571     ngx_http_core_loc_conf_t *clcf, ngx_str_t *path, ngx_open_file_info_t *of)
2572 {
2573 #if (NGX_HAVE_OPENAT)
2574     u_char     *p;
2575     ngx_str_t   from;
2576 
2577     of->disable_symlinks = clcf->disable_symlinks;
2578 
2579     if (clcf->disable_symlinks_from == NULL) {
2580         return NGX_OK;
2581     }
2582 
2583     if (ngx_http_complex_value(r, clcf->disable_symlinks_from, &from)
2584         != NGX_OK)
2585     {
2586         return NGX_ERROR;
2587     }
2588 
2589     if (from.len == 0
2590         || from.len > path->len
2591         || ngx_memcmp(path->data, from.data, from.len) != 0)
2592     {
2593         return NGX_OK;
2594     }
2595 
2596     if (from.len == path->len) {
2597         of->disable_symlinks = NGX_DISABLE_SYMLINKS_OFF;
2598         return NGX_OK;
2599     }
2600 
2601     p = path->data + from.len;
2602 
2603     if (*p == '/') {
2604         of->disable_symlinks_from = from.len;
2605         return NGX_OK;
2606     }
2607 
2608     p--;
2609 
2610     if (*p == '/') {
2611         of->disable_symlinks_from = from.len - 1;
2612     }
2613 #endif
2614 
2615     return NGX_OK;
2616 }
2617 
2618 
2619 ngx_int_t
2620 ngx_http_get_forwarded_addr(ngx_http_request_t *r, ngx_addr_t *addr,
2621     ngx_array_t *headers, ngx_str_t *value, ngx_array_t *proxies,
2622     int recursive)
2623 {
2624     ngx_int_t          rc;
2625     ngx_uint_t         i, found;
2626     ngx_table_elt_t  **h;
2627 
2628     if (headers == NULL) {
2629         return ngx_http_get_forwarded_addr_internal(r, addr, value->data,
2630                                                     value->len, proxies,
2631                                                     recursive);
2632     }
2633 
2634     i = headers->nelts;
2635     h = headers->elts;
2636 
2637     rc = NGX_DECLINED;
2638 
2639     found = 0;
2640 
2641     while (i-- > 0) {
2642         rc = ngx_http_get_forwarded_addr_internal(r, addr, h[i]->value.data,
2643                                                   h[i]->value.len, proxies,
2644                                                   recursive);
2645 
2646         if (!recursive) {
2647             break;
2648         }
2649 
2650         if (rc == NGX_DECLINED && found) {
2651             rc = NGX_DONE;
2652             break;
2653         }
2654 
2655         if (rc != NGX_OK) {
2656             break;
2657         }
2658 
2659         found = 1;
2660     }
2661 
2662     return rc;
2663 }
2664 
2665 
2666 static ngx_int_t
2667 ngx_http_get_forwarded_addr_internal(ngx_http_request_t *r, ngx_addr_t *addr,
2668     u_char *xff, size_t xfflen, ngx_array_t *proxies, int recursive)
2669 {
2670     u_char      *p;
2671     ngx_int_t    rc;
2672     ngx_addr_t   paddr;
2673 
2674     if (ngx_cidr_match(addr->sockaddr, proxies) != NGX_OK) {
2675         return NGX_DECLINED;
2676     }
2677 
2678     for (p = xff + xfflen - 1; p > xff; p--, xfflen--) {
2679         if (*p != ' ' && *p != ',') {
2680             break;
2681         }
2682     }
2683 
2684     for ( /* void */ ; p > xff; p--) {
2685         if (*p == ' ' || *p == ',') {
2686             p++;
2687             break;
2688         }
2689     }
2690 
2691     if (ngx_parse_addr_port(r->pool, &paddr, p, xfflen - (p - xff)) != NGX_OK) {
2692         return NGX_DECLINED;
2693     }
2694 
2695     *addr = paddr;
2696 
2697     if (recursive && p > xff) {
2698         rc = ngx_http_get_forwarded_addr_internal(r, addr, xff, p - 1 - xff,
2699                                                   proxies, 1);
2700 
2701         if (rc == NGX_DECLINED) {
2702             return NGX_DONE;
2703         }
2704 
2705         /* rc == NGX_OK || rc == NGX_DONE  */
2706         return rc;
2707     }
2708 
2709     return NGX_OK;
2710 }
2711 
2712 
2713 static char *
2714 ngx_http_core_server(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
2715 {
2716     char                        *rv;
2717     void                        *mconf;
2718     size_t                       len;
2719     u_char                      *p;
2720     ngx_uint_t                   i;
2721     ngx_conf_t                   pcf;
2722     ngx_http_module_t           *module;
2723     struct sockaddr_in          *sin;
2724     ngx_http_conf_ctx_t         *ctx, *http_ctx;
2725     ngx_http_listen_opt_t        lsopt;
2726     ngx_http_core_srv_conf_t    *cscf, **cscfp;
2727     ngx_http_core_main_conf_t   *cmcf;
2728 
2729     ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t));
2730     if (ctx == NULL) {
2731         return NGX_CONF_ERROR;
2732     }
2733 
2734     http_ctx = cf->ctx;
2735     ctx->main_conf = http_ctx->main_conf;
2736 
2737     /* the server{}'s srv_conf */
2738 
2739     ctx->srv_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
2740     if (ctx->srv_conf == NULL) {
2741         return NGX_CONF_ERROR;
2742     }
2743 
2744     /* the server{}'s loc_conf */
2745 
2746     ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
2747     if (ctx->loc_conf == NULL) {
2748         return NGX_CONF_ERROR;
2749     }
2750 
2751     for (i = 0; cf->cycle->modules[i]; i++) {
2752         if (cf->cycle->modules[i]->type != NGX_HTTP_MODULE) {
2753             continue;
2754         }
2755 
2756         module = cf->cycle->modules[i]->ctx;
2757 
2758         if (module->create_srv_conf) {
2759             mconf = module->create_srv_conf(cf);
2760             if (mconf == NULL) {
2761                 return NGX_CONF_ERROR;
2762             }
2763 
2764             ctx->srv_conf[cf->cycle->modules[i]->ctx_index] = mconf;
2765         }
2766 
2767         if (module->create_loc_conf) {
2768             mconf = module->create_loc_conf(cf);
2769             if (mconf == NULL) {
2770                 return NGX_CONF_ERROR;
2771             }
2772 
2773             ctx->loc_conf[cf->cycle->modules[i]->ctx_index] = mconf;
2774         }
2775     }
2776 
2777 
2778     /* the server configuration context */
2779 
2780     cscf = ctx->srv_conf[ngx_http_core_module.ctx_index];
2781     cscf->ctx = ctx;
2782 
2783 
2784     cmcf = ctx->main_conf[ngx_http_core_module.ctx_index];
2785 
2786     cscfp = ngx_array_push(&cmcf->servers);
2787     if (cscfp == NULL) {
2788         return NGX_CONF_ERROR;
2789     }
2790 
2791     *cscfp = cscf;
2792 
2793 
2794     /* parse inside server{} */
2795 
2796     pcf = *cf;
2797     cf->ctx = ctx;
2798     cf->cmd_type = NGX_HTTP_SRV_CONF;
2799 
2800     rv = ngx_conf_parse(cf, NULL);
2801 
2802     *cf = pcf;
2803 
2804     if (rv == NGX_CONF_OK && !cscf->listen) {
2805         ngx_memzero(&lsopt, sizeof(ngx_http_listen_opt_t));
2806 
2807         p = ngx_pcalloc(cf->pool, sizeof(struct sockaddr_in));
2808         if (p == NULL) {
2809             return NGX_CONF_ERROR;
2810         }
2811 
2812         lsopt.sockaddr = (struct sockaddr *) p;
2813 
2814         sin = (struct sockaddr_in *) p;
2815 
2816         sin->sin_family = AF_INET;
2817 #if (NGX_WIN32)
2818         sin->sin_port = htons(80);
2819 #else
2820         sin->sin_port = htons((getuid() == 0) ? 80 : 8000);
2821 #endif
2822         sin->sin_addr.s_addr = INADDR_ANY;
2823 
2824         lsopt.socklen = sizeof(struct sockaddr_in);
2825 
2826         lsopt.backlog = NGX_LISTEN_BACKLOG;
2827         lsopt.rcvbuf = -1;
2828         lsopt.sndbuf = -1;
2829 #if (NGX_HAVE_SETFIB)
2830         lsopt.setfib = -1;
2831 #endif
2832 #if (NGX_HAVE_TCP_FASTOPEN)
2833         lsopt.fastopen = -1;
2834 #endif
2835         lsopt.wildcard = 1;
2836 
2837         len = NGX_INET_ADDRSTRLEN + sizeof(":65535") - 1;
2838 
2839         p = ngx_pnalloc(cf->pool, len);
2840         if (p == NULL) {
2841             return NGX_CONF_ERROR;
2842         }
2843 
2844         lsopt.addr_text.data = p;
2845         lsopt.addr_text.len = ngx_sock_ntop(lsopt.sockaddr, lsopt.socklen, p,
2846                                             len, 1);
2847 
2848         if (ngx_http_add_listen(cf, cscf, &lsopt) != NGX_OK) {
2849             return NGX_CONF_ERROR;
2850         }
2851     }
2852 
2853     return rv;
2854 }
2855 
2856 
2857 static char *
2858 ngx_http_core_location(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
2859 {
2860     char                      *rv;
2861     u_char                    *mod;
2862     size_t                     len;
2863     ngx_str_t                 *value, *name;
2864     ngx_uint_t                 i;
2865     ngx_conf_t                 save;
2866     ngx_http_module_t         *module;
2867     ngx_http_conf_ctx_t       *ctx, *pctx;
2868     ngx_http_core_loc_conf_t  *clcf, *pclcf;
2869 
2870     ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t));
2871     if (ctx == NULL) {
2872         return NGX_CONF_ERROR;
2873     }
2874 
2875     pctx = cf->ctx;
2876     ctx->main_conf = pctx->main_conf;
2877     ctx->srv_conf = pctx->srv_conf;
2878 
2879     ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
2880     if (ctx->loc_conf == NULL) {
2881         return NGX_CONF_ERROR;
2882     }
2883 
2884     for (i = 0; cf->cycle->modules[i]; i++) {
2885         if (cf->cycle->modules[i]->type != NGX_HTTP_MODULE) {
2886             continue;
2887         }
2888 
2889         module = cf->cycle->modules[i]->ctx;
2890 
2891         if (module->create_loc_conf) {
2892             ctx->loc_conf[cf->cycle->modules[i]->ctx_index] =
2893                                                    module->create_loc_conf(cf);
2894             if (ctx->loc_conf[cf->cycle->modules[i]->ctx_index] == NULL) {
2895                 return NGX_CONF_ERROR;
2896             }
2897         }
2898     }
2899 
2900     clcf = ctx->loc_conf[ngx_http_core_module.ctx_index];
2901     clcf->loc_conf = ctx->loc_conf;
2902 
2903     value = cf->args->elts;
2904 
2905     if (cf->args->nelts == 3) {
2906 
2907         len = value[1].len;
2908         mod = value[1].data;
2909         name = &value[2];
2910 
2911         if (len == 1 && mod[0] == '=') {
2912 
2913             clcf->name = *name;
2914             clcf->exact_match = 1;
2915 
2916         } else if (len == 2 && mod[0] == '^' && mod[1] == '~') {
2917 
2918             clcf->name = *name;
2919             clcf->noregex = 1;
2920 
2921         } else if (len == 1 && mod[0] == '~') {
2922 
2923             if (ngx_http_core_regex_location(cf, clcf, name, 0) != NGX_OK) {
2924                 return NGX_CONF_ERROR;
2925             }
2926 
2927         } else if (len == 2 && mod[0] == '~' && mod[1] == '*') {
2928 
2929             if (ngx_http_core_regex_location(cf, clcf, name, 1) != NGX_OK) {
2930                 return NGX_CONF_ERROR;
2931             }
2932 
2933         } else {
2934             ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2935                                "invalid location modifier \"%V\"", &value[1]);
2936             return NGX_CONF_ERROR;
2937         }
2938 
2939     } else {
2940 
2941         name = &value[1];
2942 
2943         if (name->data[0] == '=') {
2944 
2945             clcf->name.len = name->len - 1;
2946             clcf->name.data = name->data + 1;
2947             clcf->exact_match = 1;
2948 
2949         } else if (name->data[0] == '^' && name->data[1] == '~') {
2950 
2951             clcf->name.len = name->len - 2;
2952             clcf->name.data = name->data + 2;
2953             clcf->noregex = 1;
2954 
2955         } else if (name->data[0] == '~') {
2956 
2957             name->len--;
2958             name->data++;
2959 
2960             if (name->data[0] == '*') {
2961 
2962                 name->len--;
2963                 name->data++;
2964 
2965                 if (ngx_http_core_regex_location(cf, clcf, name, 1) != NGX_OK) {
2966                     return NGX_CONF_ERROR;
2967                 }
2968 
2969             } else {
2970                 if (ngx_http_core_regex_location(cf, clcf, name, 0) != NGX_OK) {
2971                     return NGX_CONF_ERROR;
2972                 }
2973             }
2974 
2975         } else {
2976 
2977             clcf->name = *name;
2978 
2979             if (name->data[0] == '@') {
2980                 clcf->named = 1;
2981             }
2982         }
2983     }
2984 
2985     pclcf = pctx->loc_conf[ngx_http_core_module.ctx_index];
2986 
2987     if (cf->cmd_type == NGX_HTTP_LOC_CONF) {
2988 
2989         /* nested location */
2990 
2991 #if 0
2992         clcf->prev_location = pclcf;
2993 #endif
2994 
2995         if (pclcf->exact_match) {
2996             ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2997                                "location \"%V\" cannot be inside "
2998                                "the exact location \"%V\"",
2999                                &clcf->name, &pclcf->name);
3000             return NGX_CONF_ERROR;
3001         }
3002 
3003         if (pclcf->named) {
3004             ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3005                                "location \"%V\" cannot be inside "
3006                                "the named location \"%V\"",
3007                                &clcf->name, &pclcf->name);
3008             return NGX_CONF_ERROR;
3009         }
3010 
3011         if (clcf->named) {
3012             ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3013                                "named location \"%V\" can be "
3014                                "on the server level only",
3015                                &clcf->name);
3016             return NGX_CONF_ERROR;
3017         }
3018 
3019         len = pclcf->name.len;
3020 
3021 #if (NGX_PCRE)
3022         if (clcf->regex == NULL
3023             && ngx_filename_cmp(clcf->name.data, pclcf->name.data, len) != 0)
3024 #else
3025         if (ngx_filename_cmp(clcf->name.data, pclcf->name.data, len) != 0)
3026 #endif
3027         {
3028             ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3029                                "location \"%V\" is outside location \"%V\"",
3030                                &clcf->name, &pclcf->name);
3031             return NGX_CONF_ERROR;
3032         }
3033     }
3034 
3035     if (ngx_http_add_location(cf, &pclcf->locations, clcf) != NGX_OK) {
3036         return NGX_CONF_ERROR;
3037     }
3038 
3039     save = *cf;
3040     cf->ctx = ctx;
3041     cf->cmd_type = NGX_HTTP_LOC_CONF;
3042 
3043     rv = ngx_conf_parse(cf, NULL);
3044 
3045     *cf = save;
3046 
3047     return rv;
3048 }
3049 
3050 
3051 static ngx_int_t
3052 ngx_http_core_regex_location(ngx_conf_t *cf, ngx_http_core_loc_conf_t *clcf,
3053     ngx_str_t *regex, ngx_uint_t caseless)
3054 {
3055 #if (NGX_PCRE)
3056     ngx_regex_compile_t  rc;
3057     u_char               errstr[NGX_MAX_CONF_ERRSTR];
3058 
3059     ngx_memzero(&rc, sizeof(ngx_regex_compile_t));
3060 
3061     rc.pattern = *regex;
3062     rc.err.len = NGX_MAX_CONF_ERRSTR;
3063     rc.err.data = errstr;
3064 
3065 #if (NGX_HAVE_CASELESS_FILESYSTEM)
3066     rc.options = NGX_REGEX_CASELESS;
3067 #else
3068     rc.options = caseless ? NGX_REGEX_CASELESS : 0;
3069 #endif
3070 
3071     clcf->regex = ngx_http_regex_compile(cf, &rc);
3072     if (clcf->regex == NULL) {
3073         return NGX_ERROR;
3074     }
3075 
3076     clcf->name = *regex;
3077 
3078     return NGX_OK;
3079 
3080 #else
3081 
3082     ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3083                        "using regex \"%V\" requires PCRE library",
3084                        regex);
3085     return NGX_ERROR;
3086 
3087 #endif
3088 }
3089 
3090 
3091 static char *
3092 ngx_http_core_types(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
3093 {
3094     ngx_http_core_loc_conf_t *clcf = conf;
3095 
3096     char        *rv;
3097     ngx_conf_t   save;
3098 
3099     if (clcf->types == NULL) {
3100         clcf->types = ngx_array_create(cf->pool, 64, sizeof(ngx_hash_key_t));
3101         if (clcf->types == NULL) {
3102             return NGX_CONF_ERROR;
3103         }
3104     }
3105 
3106     save = *cf;
3107     cf->handler = ngx_http_core_type;
3108     cf->handler_conf = conf;
3109 
3110     rv = ngx_conf_parse(cf, NULL);
3111 
3112     *cf = save;
3113 
3114     return rv;
3115 }
3116 
3117 
3118 static char *
3119 ngx_http_core_type(ngx_conf_t *cf, ngx_command_t *dummy, void *conf)
3120 {
3121     ngx_http_core_loc_conf_t *clcf = conf;
3122 
3123     ngx_str_t       *value, *content_type, *old;
3124     ngx_uint_t       i, n, hash;
3125     ngx_hash_key_t  *type;
3126 
3127     value = cf->args->elts;
3128 
3129     if (ngx_strcmp(value[0].data, "include") == 0) {
3130         if (cf->args->nelts != 2) {
3131             ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3132                                "invalid number of arguments"
3133                                " in \"include\" directive");
3134             return NGX_CONF_ERROR;
3135         }
3136 
3137         return ngx_conf_include(cf, dummy, conf);
3138     }
3139 
3140     content_type = ngx_palloc(cf->pool, sizeof(ngx_str_t));
3141     if (content_type == NULL) {
3142         return NGX_CONF_ERROR;
3143     }
3144 
3145     *content_type = value[0];
3146 
3147     for (i = 1; i < cf->args->nelts; i++) {
3148 
3149         hash = ngx_hash_strlow(value[i].data, value[i].data, value[i].len);
3150 
3151         type = clcf->types->elts;
3152         for (n = 0; n < clcf->types->nelts; n++) {
3153             if (ngx_strcmp(value[i].data, type[n].key.data) == 0) {
3154                 old = type[n].value;
3155                 type[n].value = content_type;
3156 
3157                 ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
3158                                    "duplicate extension \"%V\", "
3159                                    "content type: \"%V\", "
3160                                    "previous content type: \"%V\"",
3161                                    &value[i], content_type, old);
3162                 goto next;
3163             }
3164         }
3165 
3166 
3167         type = ngx_array_push(clcf->types);
3168         if (type == NULL) {
3169             return NGX_CONF_ERROR;
3170         }
3171 
3172         type->key = value[i];
3173         type->key_hash = hash;
3174         type->value = content_type;
3175 
3176     next:
3177         continue;
3178     }
3179 
3180     return NGX_CONF_OK;
3181 }
3182 
3183 
3184 static ngx_int_t
3185 ngx_http_core_preconfiguration(ngx_conf_t *cf)
3186 {
3187     return ngx_http_variables_add_core_vars(cf);
3188 }
3189 
3190 
3191 static ngx_int_t
3192 ngx_http_core_postconfiguration(ngx_conf_t *cf)
3193 {
3194     ngx_http_top_request_body_filter = ngx_http_request_body_save_filter;
3195 
3196     return NGX_OK;
3197 }
3198 
3199 
3200 static void *
3201 ngx_http_core_create_main_conf(ngx_conf_t *cf)
3202 {
3203     ngx_http_core_main_conf_t  *cmcf;
3204 
3205     cmcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_main_conf_t));
3206     if (cmcf == NULL) {
3207         return NULL;
3208     }
3209 
3210     if (ngx_array_init(&cmcf->servers, cf->pool, 4,
3211                        sizeof(ngx_http_core_srv_conf_t *))
3212         != NGX_OK)
3213     {
3214         return NULL;
3215     }
3216 
3217     cmcf->server_names_hash_max_size = NGX_CONF_UNSET_UINT;
3218     cmcf->server_names_hash_bucket_size = NGX_CONF_UNSET_UINT;
3219 
3220     cmcf->variables_hash_max_size = NGX_CONF_UNSET_UINT;
3221     cmcf->variables_hash_bucket_size = NGX_CONF_UNSET_UINT;
3222 
3223     return cmcf;
3224 }
3225 
3226 
3227 static char *
3228 ngx_http_core_init_main_conf(ngx_conf_t *cf, void *conf)
3229 {
3230     ngx_http_core_main_conf_t *cmcf = conf;
3231 
3232     ngx_conf_init_uint_value(cmcf->server_names_hash_max_size, 512);
3233     ngx_conf_init_uint_value(cmcf->server_names_hash_bucket_size,
3234                              ngx_cacheline_size);
3235 
3236     cmcf->server_names_hash_bucket_size =
3237             ngx_align(cmcf->server_names_hash_bucket_size, ngx_cacheline_size);
3238 
3239 
3240     ngx_conf_init_uint_value(cmcf->variables_hash_max_size, 1024);
3241     ngx_conf_init_uint_value(cmcf->variables_hash_bucket_size, 64);
3242 
3243     cmcf->variables_hash_bucket_size =
3244                ngx_align(cmcf->variables_hash_bucket_size, ngx_cacheline_size);
3245 
3246     if (cmcf->ncaptures) {
3247         cmcf->ncaptures = (cmcf->ncaptures + 1) * 3;
3248     }
3249 
3250     return NGX_CONF_OK;
3251 }
3252 
3253 
3254 static void *
3255 ngx_http_core_create_srv_conf(ngx_conf_t *cf)
3256 {
3257     ngx_http_core_srv_conf_t  *cscf;
3258 
3259     cscf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_srv_conf_t));
3260     if (cscf == NULL) {
3261         return NULL;
3262     }
3263 
3264     /*
3265      * set by ngx_pcalloc():
3266      *
3267      *     conf->client_large_buffers.num = 0;
3268      */
3269 
3270     if (ngx_array_init(&cscf->server_names, cf->temp_pool, 4,
3271                        sizeof(ngx_http_server_name_t))
3272         != NGX_OK)
3273     {
3274         return NULL;
3275     }
3276 
3277     cscf->connection_pool_size = NGX_CONF_UNSET_SIZE;
3278     cscf->request_pool_size = NGX_CONF_UNSET_SIZE;
3279     cscf->client_header_timeout = NGX_CONF_UNSET_MSEC;
3280     cscf->client_header_buffer_size = NGX_CONF_UNSET_SIZE;
3281     cscf->ignore_invalid_headers = NGX_CONF_UNSET;
3282     cscf->merge_slashes = NGX_CONF_UNSET;
3283     cscf->underscores_in_headers = NGX_CONF_UNSET;
3284 
3285     cscf->file_name = cf->conf_file->file.name.data;
3286     cscf->line = cf->conf_file->line;
3287 
3288     return cscf;
3289 }
3290 
3291 
3292 static char *
3293 ngx_http_core_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
3294 {
3295     ngx_http_core_srv_conf_t *prev = parent;
3296     ngx_http_core_srv_conf_t *conf = child;
3297 
3298     ngx_str_t                name;
3299     ngx_http_server_name_t  *sn;
3300 
3301     /* TODO: it does not merge, it inits only */
3302 
3303     ngx_conf_merge_size_value(conf->connection_pool_size,
3304                               prev->connection_pool_size, 64 * sizeof(void *));
3305     ngx_conf_merge_size_value(conf->request_pool_size,
3306                               prev->request_pool_size, 4096);
3307     ngx_conf_merge_msec_value(conf->client_header_timeout,
3308                               prev->client_header_timeout, 60000);
3309     ngx_conf_merge_size_value(conf->client_header_buffer_size,
3310                               prev->client_header_buffer_size, 1024);
3311     ngx_conf_merge_bufs_value(conf->large_client_header_buffers,
3312                               prev->large_client_header_buffers,
3313                               4, 8192);
3314 
3315     if (conf->large_client_header_buffers.size < conf->connection_pool_size) {
3316         ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3317                            "the \"large_client_header_buffers\" size must be "
3318                            "equal to or greater than \"connection_pool_size\"");
3319         return NGX_CONF_ERROR;
3320     }
3321 
3322     ngx_conf_merge_value(conf->ignore_invalid_headers,
3323                               prev->ignore_invalid_headers, 1);
3324 
3325     ngx_conf_merge_value(conf->merge_slashes, prev->merge_slashes, 1);
3326 
3327     ngx_conf_merge_value(conf->underscores_in_headers,
3328                               prev->underscores_in_headers, 0);
3329 
3330     if (conf->server_names.nelts == 0) {
3331         /* the array has 4 empty preallocated elements, so push cannot fail */
3332         sn = ngx_array_push(&conf->server_names);
3333 #if (NGX_PCRE)
3334         sn->regex = NULL;
3335 #endif
3336         sn->server = conf;
3337         ngx_str_set(&sn->name, "");
3338     }
3339 
3340     sn = conf->server_names.elts;
3341     name = sn[0].name;
3342 
3343 #if (NGX_PCRE)
3344     if (sn->regex) {
3345         name.len++;
3346         name.data--;
3347     } else
3348 #endif
3349 
3350     if (name.data[0] == '.') {
3351         name.len--;
3352         name.data++;
3353     }
3354 
3355     conf->server_name.len = name.len;
3356     conf->server_name.data = ngx_pstrdup(cf->pool, &name);
3357     if (conf->server_name.data == NULL) {
3358         return NGX_CONF_ERROR;
3359     }
3360 
3361     return NGX_CONF_OK;
3362 }
3363 
3364 
3365 static void *
3366 ngx_http_core_create_loc_conf(ngx_conf_t *cf)
3367 {
3368     ngx_http_core_loc_conf_t  *clcf;
3369 
3370     clcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_loc_conf_t));
3371     if (clcf == NULL) {
3372         return NULL;
3373     }
3374 
3375     /*
3376      * set by ngx_pcalloc():
3377      *
3378      *     clcf->root = { 0, NULL };
3379      *     clcf->limit_except = 0;
3380      *     clcf->post_action = { 0, NULL };
3381      *     clcf->types = NULL;
3382      *     clcf->default_type = { 0, NULL };
3383      *     clcf->error_log = NULL;
3384      *     clcf->error_pages = NULL;
3385      *     clcf->client_body_path = NULL;
3386      *     clcf->regex = NULL;
3387      *     clcf->exact_match = 0;
3388      *     clcf->auto_redirect = 0;
3389      *     clcf->alias = 0;
3390      *     clcf->gzip_proxied = 0;
3391      *     clcf->keepalive_disable = 0;
3392      */
3393 
3394     clcf->client_max_body_size = NGX_CONF_UNSET;
3395     clcf->client_body_buffer_size = NGX_CONF_UNSET_SIZE;
3396     clcf->client_body_timeout = NGX_CONF_UNSET_MSEC;
3397     clcf->satisfy = NGX_CONF_UNSET_UINT;
3398     clcf->if_modified_since = NGX_CONF_UNSET_UINT;
3399     clcf->max_ranges = NGX_CONF_UNSET_UINT;
3400     clcf->client_body_in_file_only = NGX_CONF_UNSET_UINT;
3401     clcf->client_body_in_single_buffer = NGX_CONF_UNSET;
3402     clcf->internal = NGX_CONF_UNSET;
3403     clcf->sendfile = NGX_CONF_UNSET;
3404     clcf->sendfile_max_chunk = NGX_CONF_UNSET_SIZE;
3405     clcf->subrequest_output_buffer_size = NGX_CONF_UNSET_SIZE;
3406     clcf->aio = NGX_CONF_UNSET;
3407     clcf->aio_write = NGX_CONF_UNSET;
3408 #if (NGX_THREADS)
3409     clcf->thread_pool = NGX_CONF_UNSET_PTR;
3410     clcf->thread_pool_value = NGX_CONF_UNSET_PTR;
3411 #endif
3412     clcf->read_ahead = NGX_CONF_UNSET_SIZE;
3413     clcf->directio = NGX_CONF_UNSET;
3414     clcf->directio_alignment = NGX_CONF_UNSET;
3415     clcf->tcp_nopush = NGX_CONF_UNSET;
3416     clcf->tcp_nodelay = NGX_CONF_UNSET;
3417     clcf->send_timeout = NGX_CONF_UNSET_MSEC;
3418     clcf->send_lowat = NGX_CONF_UNSET_SIZE;
3419     clcf->postpone_output = NGX_CONF_UNSET_SIZE;
3420     clcf->limit_rate = NGX_CONF_UNSET_SIZE;
3421     clcf->limit_rate_after = NGX_CONF_UNSET_SIZE;
3422     clcf->keepalive_timeout = NGX_CONF_UNSET_MSEC;
3423     clcf->keepalive_header = NGX_CONF_UNSET;
3424     clcf->keepalive_requests = NGX_CONF_UNSET_UINT;
3425     clcf->lingering_close = NGX_CONF_UNSET_UINT;
3426     clcf->lingering_time = NGX_CONF_UNSET_MSEC;
3427     clcf->lingering_timeout = NGX_CONF_UNSET_MSEC;
3428     clcf->resolver_timeout = NGX_CONF_UNSET_MSEC;
3429     clcf->reset_timedout_connection = NGX_CONF_UNSET;
3430     clcf->absolute_redirect = NGX_CONF_UNSET;
3431     clcf->server_name_in_redirect = NGX_CONF_UNSET;
3432     clcf->port_in_redirect = NGX_CONF_UNSET;
3433     clcf->msie_padding = NGX_CONF_UNSET;
3434     clcf->msie_refresh = NGX_CONF_UNSET;
3435     clcf->log_not_found = NGX_CONF_UNSET;
3436     clcf->log_subrequest = NGX_CONF_UNSET;
3437     clcf->recursive_error_pages = NGX_CONF_UNSET;
3438     clcf->chunked_transfer_encoding = NGX_CONF_UNSET;
3439     clcf->etag = NGX_CONF_UNSET;
3440     clcf->server_tokens = NGX_CONF_UNSET_UINT;
3441     clcf->types_hash_max_size = NGX_CONF_UNSET_UINT;
3442     clcf->types_hash_bucket_size = NGX_CONF_UNSET_UINT;
3443 
3444     clcf->open_file_cache = NGX_CONF_UNSET_PTR;
3445     clcf->open_file_cache_valid = NGX_CONF_UNSET;
3446     clcf->open_file_cache_min_uses = NGX_CONF_UNSET_UINT;
3447     clcf->open_file_cache_errors = NGX_CONF_UNSET;
3448     clcf->open_file_cache_events = NGX_CONF_UNSET;
3449 
3450 #if (NGX_HTTP_GZIP)
3451     clcf->gzip_vary = NGX_CONF_UNSET;
3452     clcf->gzip_http_version = NGX_CONF_UNSET_UINT;
3453 #if (NGX_PCRE)
3454     clcf->gzip_disable = NGX_CONF_UNSET_PTR;
3455 #endif
3456     clcf->gzip_disable_msie6 = 3;
3457 #if (NGX_HTTP_DEGRADATION)
3458     clcf->gzip_disable_degradation = 3;
3459 #endif
3460 #endif
3461 
3462 #if (NGX_HAVE_OPENAT)
3463     clcf->disable_symlinks = NGX_CONF_UNSET_UINT;
3464     clcf->disable_symlinks_from = NGX_CONF_UNSET_PTR;
3465 #endif
3466 
3467     return clcf;
3468 }
3469 
3470 
3471 static ngx_str_t  ngx_http_core_text_html_type = ngx_string("text/html");
3472 static ngx_str_t  ngx_http_core_image_gif_type = ngx_string("image/gif");
3473 static ngx_str_t  ngx_http_core_image_jpeg_type = ngx_string("image/jpeg");
3474 
3475 static ngx_hash_key_t  ngx_http_core_default_types[] = {
3476     { ngx_string("html"), 0, &ngx_http_core_text_html_type },
3477     { ngx_string("gif"), 0, &ngx_http_core_image_gif_type },
3478     { ngx_string("jpg"), 0, &ngx_http_core_image_jpeg_type },
3479     { ngx_null_string, 0, NULL }
3480 };
3481 
3482 
3483 static char *
3484 ngx_http_core_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
3485 {
3486     ngx_http_core_loc_conf_t *prev = parent;
3487     ngx_http_core_loc_conf_t *conf = child;
3488 
3489     ngx_uint_t        i;
3490     ngx_hash_key_t   *type;
3491     ngx_hash_init_t   types_hash;
3492 
3493     if (conf->root.data == NULL) {
3494 
3495         conf->alias = prev->alias;
3496         conf->root = prev->root;
3497         conf->root_lengths = prev->root_lengths;
3498         conf->root_values = prev->root_values;
3499 
3500         if (prev->root.data == NULL) {
3501             ngx_str_set(&conf->root, "html");
3502 
3503             if (ngx_conf_full_name(cf->cycle, &conf->root, 0) != NGX_OK) {
3504                 return NGX_CONF_ERROR;
3505             }
3506         }
3507     }
3508 
3509     if (conf->post_action.data == NULL) {
3510         conf->post_action = prev->post_action;
3511     }
3512 
3513     ngx_conf_merge_uint_value(conf->types_hash_max_size,
3514                               prev->types_hash_max_size, 1024);
3515 
3516     ngx_conf_merge_uint_value(conf->types_hash_bucket_size,
3517                               prev->types_hash_bucket_size, 64);
3518 
3519     conf->types_hash_bucket_size = ngx_align(conf->types_hash_bucket_size,
3520                                              ngx_cacheline_size);
3521 
3522     /*
3523      * the special handling of the "types" directive in the "http" section
3524      * to inherit the http's conf->types_hash to all servers
3525      */
3526 
3527     if (prev->types && prev->types_hash.buckets == NULL) {
3528 
3529         types_hash.hash = &prev->types_hash;
3530         types_hash.key = ngx_hash_key_lc;
3531         types_hash.max_size = conf->types_hash_max_size;
3532         types_hash.bucket_size = conf->types_hash_bucket_size;
3533         types_hash.name = "types_hash";
3534         types_hash.pool = cf->pool;
3535         types_hash.temp_pool = NULL;
3536 
3537         if (ngx_hash_init(&types_hash, prev->types->elts, prev->types->nelts)
3538             != NGX_OK)
3539         {
3540             return NGX_CONF_ERROR;
3541         }
3542     }
3543 
3544     if (conf->types == NULL) {
3545         conf->types = prev->types;
3546         conf->types_hash = prev->types_hash;
3547     }
3548 
3549     if (conf->types == NULL) {
3550         conf->types = ngx_array_create(cf->pool, 3, sizeof(ngx_hash_key_t));
3551         if (conf->types == NULL) {
3552             return NGX_CONF_ERROR;
3553         }
3554 
3555         for (i = 0; ngx_http_core_default_types[i].key.len; i++) {
3556             type = ngx_array_push(conf->types);
3557             if (type == NULL) {
3558                 return NGX_CONF_ERROR;
3559             }
3560 
3561             type->key = ngx_http_core_default_types[i].key;
3562             type->key_hash =
3563                        ngx_hash_key_lc(ngx_http_core_default_types[i].key.data,
3564                                        ngx_http_core_default_types[i].key.len);
3565             type->value = ngx_http_core_default_types[i].value;
3566         }
3567     }
3568 
3569     if (conf->types_hash.buckets == NULL) {
3570 
3571         types_hash.hash = &conf->types_hash;
3572         types_hash.key = ngx_hash_key_lc;
3573         types_hash.max_size = conf->types_hash_max_size;
3574         types_hash.bucket_size = conf->types_hash_bucket_size;
3575         types_hash.name = "types_hash";
3576         types_hash.pool = cf->pool;
3577         types_hash.temp_pool = NULL;
3578 
3579         if (ngx_hash_init(&types_hash, conf->types->elts, conf->types->nelts)
3580             != NGX_OK)
3581         {
3582             return NGX_CONF_ERROR;
3583         }
3584     }
3585 
3586     if (conf->error_log == NULL) {
3587         if (prev->error_log) {
3588             conf->error_log = prev->error_log;
3589         } else {
3590             conf->error_log = &cf->cycle->new_log;
3591         }
3592     }
3593 
3594     if (conf->error_pages == NULL && prev->error_pages) {
3595         conf->error_pages = prev->error_pages;
3596     }
3597 
3598     ngx_conf_merge_str_value(conf->default_type,
3599                               prev->default_type, "text/plain");
3600 
3601     ngx_conf_merge_off_value(conf->client_max_body_size,
3602                               prev->client_max_body_size, 1 * 1024 * 1024);
3603     ngx_conf_merge_size_value(conf->client_body_buffer_size,
3604                               prev->client_body_buffer_size,
3605                               (size_t) 2 * ngx_pagesize);
3606     ngx_conf_merge_msec_value(conf->client_body_timeout,
3607                               prev->client_body_timeout, 60000);
3608 
3609     ngx_conf_merge_bitmask_value(conf->keepalive_disable,
3610                               prev->keepalive_disable,
3611                               (NGX_CONF_BITMASK_SET
3612                                |NGX_HTTP_KEEPALIVE_DISABLE_MSIE6));
3613     ngx_conf_merge_uint_value(conf->satisfy, prev->satisfy,
3614                               NGX_HTTP_SATISFY_ALL);
3615     ngx_conf_merge_uint_value(conf->if_modified_since, prev->if_modified_since,
3616                               NGX_HTTP_IMS_EXACT);
3617     ngx_conf_merge_uint_value(conf->max_ranges, prev->max_ranges,
3618                               NGX_MAX_INT32_VALUE);
3619     ngx_conf_merge_uint_value(conf->client_body_in_file_only,
3620                               prev->client_body_in_file_only,
3621                               NGX_HTTP_REQUEST_BODY_FILE_OFF);
3622     ngx_conf_merge_value(conf->client_body_in_single_buffer,
3623                               prev->client_body_in_single_buffer, 0);
3624     ngx_conf_merge_value(conf->internal, prev->internal, 0);
3625     ngx_conf_merge_value(conf->sendfile, prev->sendfile, 0);
3626     ngx_conf_merge_size_value(conf->sendfile_max_chunk,
3627                               prev->sendfile_max_chunk, 0);
3628     ngx_conf_merge_size_value(conf->subrequest_output_buffer_size,
3629                               prev->subrequest_output_buffer_size,
3630                               (size_t) ngx_pagesize);
3631     ngx_conf_merge_value(conf->aio, prev->aio, NGX_HTTP_AIO_OFF);
3632     ngx_conf_merge_value(conf->aio_write, prev->aio_write, 0);
3633 #if (NGX_THREADS)
3634     ngx_conf_merge_ptr_value(conf->thread_pool, prev->thread_pool, NULL);
3635     ngx_conf_merge_ptr_value(conf->thread_pool_value, prev->thread_pool_value,
3636                              NULL);
3637 #endif
3638     ngx_conf_merge_size_value(conf->read_ahead, prev->read_ahead, 0);
3639     ngx_conf_merge_off_value(conf->directio, prev->directio,
3640                               NGX_OPEN_FILE_DIRECTIO_OFF);
3641     ngx_conf_merge_off_value(conf->directio_alignment, prev->directio_alignment,
3642                               512);
3643     ngx_conf_merge_value(conf->tcp_nopush, prev->tcp_nopush, 0);
3644     ngx_conf_merge_value(conf->tcp_nodelay, prev->tcp_nodelay, 1);
3645 
3646     ngx_conf_merge_msec_value(conf->send_timeout, prev->send_timeout, 60000);
3647     ngx_conf_merge_size_value(conf->send_lowat, prev->send_lowat, 0);
3648     ngx_conf_merge_size_value(conf->postpone_output, prev->postpone_output,
3649                               1460);
3650     ngx_conf_merge_size_value(conf->limit_rate, prev->limit_rate, 0);
3651     ngx_conf_merge_size_value(conf->limit_rate_after, prev->limit_rate_after,
3652                               0);
3653     ngx_conf_merge_msec_value(conf->keepalive_timeout,
3654                               prev->keepalive_timeout, 75000);
3655     ngx_conf_merge_sec_value(conf->keepalive_header,
3656                               prev->keepalive_header, 0);
3657     ngx_conf_merge_uint_value(conf->keepalive_requests,
3658                               prev->keepalive_requests, 100);
3659     ngx_conf_merge_uint_value(conf->lingering_close,
3660                               prev->lingering_close, NGX_HTTP_LINGERING_ON);
3661     ngx_conf_merge_msec_value(conf->lingering_time,
3662                               prev->lingering_time, 30000);
3663     ngx_conf_merge_msec_value(conf->lingering_timeout,
3664                               prev->lingering_timeout, 5000);
3665     ngx_conf_merge_msec_value(conf->resolver_timeout,
3666                               prev->resolver_timeout, 30000);
3667 
3668     if (conf->resolver == NULL) {
3669 
3670         if (prev->resolver == NULL) {
3671 
3672             /*
3673              * create dummy resolver in http {} context
3674              * to inherit it in all servers
3675              */
3676 
3677             prev->resolver = ngx_resolver_create(cf, NULL, 0);
3678             if (prev->resolver == NULL) {
3679                 return NGX_CONF_ERROR;
3680             }
3681         }
3682 
3683         conf->resolver = prev->resolver;
3684     }
3685 
3686     if (ngx_conf_merge_path_value(cf, &conf->client_body_temp_path,
3687                               prev->client_body_temp_path,
3688                               &ngx_http_client_temp_path)
3689         != NGX_OK)
3690     {
3691         return NGX_CONF_ERROR;
3692     }
3693 
3694     ngx_conf_merge_value(conf->reset_timedout_connection,
3695                               prev->reset_timedout_connection, 0);
3696     ngx_conf_merge_value(conf->absolute_redirect,
3697                               prev->absolute_redirect, 1);
3698     ngx_conf_merge_value(conf->server_name_in_redirect,
3699                               prev->server_name_in_redirect, 0);
3700     ngx_conf_merge_value(conf->port_in_redirect, prev->port_in_redirect, 1);
3701     ngx_conf_merge_value(conf->msie_padding, prev->msie_padding, 1);
3702     ngx_conf_merge_value(conf->msie_refresh, prev->msie_refresh, 0);
3703     ngx_conf_merge_value(conf->log_not_found, prev->log_not_found, 1);
3704     ngx_conf_merge_value(conf->log_subrequest, prev->log_subrequest, 0);
3705     ngx_conf_merge_value(conf->recursive_error_pages,
3706                               prev->recursive_error_pages, 0);
3707     ngx_conf_merge_value(conf->chunked_transfer_encoding,
3708                               prev->chunked_transfer_encoding, 1);
3709     ngx_conf_merge_value(conf->etag, prev->etag, 1);
3710 
3711     ngx_conf_merge_uint_value(conf->server_tokens, prev->server_tokens,
3712                               NGX_HTTP_SERVER_TOKENS_ON);
3713 
3714     ngx_conf_merge_ptr_value(conf->open_file_cache,
3715                               prev->open_file_cache, NULL);
3716 
3717     ngx_conf_merge_sec_value(conf->open_file_cache_valid,
3718                               prev->open_file_cache_valid, 60);
3719 
3720     ngx_conf_merge_uint_value(conf->open_file_cache_min_uses,
3721                               prev->open_file_cache_min_uses, 1);
3722 
3723     ngx_conf_merge_sec_value(conf->open_file_cache_errors,
3724                               prev->open_file_cache_errors, 0);
3725 
3726     ngx_conf_merge_sec_value(conf->open_file_cache_events,
3727                               prev->open_file_cache_events, 0);
3728 #if (NGX_HTTP_GZIP)
3729 
3730     ngx_conf_merge_value(conf->gzip_vary, prev->gzip_vary, 0);
3731     ngx_conf_merge_uint_value(conf->gzip_http_version, prev->gzip_http_version,
3732                               NGX_HTTP_VERSION_11);
3733     ngx_conf_merge_bitmask_value(conf->gzip_proxied, prev->gzip_proxied,
3734                               (NGX_CONF_BITMASK_SET|NGX_HTTP_GZIP_PROXIED_OFF));
3735 
3736 #if (NGX_PCRE)
3737     ngx_conf_merge_ptr_value(conf->gzip_disable, prev->gzip_disable, NULL);
3738 #endif
3739 
3740     if (conf->gzip_disable_msie6 == 3) {
3741         conf->gzip_disable_msie6 =
3742             (prev->gzip_disable_msie6 == 3) ? 0 : prev->gzip_disable_msie6;
3743     }
3744 
3745 #if (NGX_HTTP_DEGRADATION)
3746 
3747     if (conf->gzip_disable_degradation == 3) {
3748         conf->gzip_disable_degradation =
3749             (prev->gzip_disable_degradation == 3) ?
3750                  0 : prev->gzip_disable_degradation;
3751     }
3752 
3753 #endif
3754 #endif
3755 
3756 #if (NGX_HAVE_OPENAT)
3757     ngx_conf_merge_uint_value(conf->disable_symlinks, prev->disable_symlinks,
3758                               NGX_DISABLE_SYMLINKS_OFF);
3759     ngx_conf_merge_ptr_value(conf->disable_symlinks_from,
3760                              prev->disable_symlinks_from, NULL);
3761 #endif
3762 
3763     return NGX_CONF_OK;
3764 }
3765 
3766 
3767 static char *
3768 ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
3769 {
3770     ngx_http_core_srv_conf_t *cscf = conf;
3771 
3772     ngx_str_t              *value, size;
3773     ngx_url_t               u;
3774     ngx_uint_t              n;
3775     ngx_http_listen_opt_t   lsopt;
3776 
3777     cscf->listen = 1;
3778 
3779     value = cf->args->elts;
3780 
3781     ngx_memzero(&u, sizeof(ngx_url_t));
3782 
3783     u.url = value[1];
3784     u.listen = 1;
3785     u.default_port = 80;
3786 
3787     if (ngx_parse_url(cf->pool, &u) != NGX_OK) {
3788         if (u.err) {
3789             ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3790                                "%s in \"%V\" of the \"listen\" directive",
3791                                u.err, &u.url);
3792         }
3793 
3794         return NGX_CONF_ERROR;
3795     }
3796 
3797     ngx_memzero(&lsopt, sizeof(ngx_http_listen_opt_t));
3798 
3799     lsopt.backlog = NGX_LISTEN_BACKLOG;
3800     lsopt.rcvbuf = -1;
3801     lsopt.sndbuf = -1;
3802 #if (NGX_HAVE_SETFIB)
3803     lsopt.setfib = -1;
3804 #endif
3805 #if (NGX_HAVE_TCP_FASTOPEN)
3806     lsopt.fastopen = -1;
3807 #endif
3808 #if (NGX_HAVE_INET6)
3809     lsopt.ipv6only = 1;
3810 #endif
3811 
3812     for (n = 2; n < cf->args->nelts; n++) {
3813 
3814         if (ngx_strcmp(value[n].data, "default_server") == 0
3815             || ngx_strcmp(value[n].data, "default") == 0)
3816         {
3817             lsopt.default_server = 1;
3818             continue;
3819         }
3820 
3821         if (ngx_strcmp(value[n].data, "bind") == 0) {
3822             lsopt.set = 1;
3823             lsopt.bind = 1;
3824             continue;
3825         }
3826 
3827 #if (NGX_HAVE_SETFIB)
3828         if (ngx_strncmp(value[n].data, "setfib=", 7) == 0) {
3829             lsopt.setfib = ngx_atoi(value[n].data + 7, value[n].len - 7);
3830             lsopt.set = 1;
3831             lsopt.bind = 1;
3832 
3833             if (lsopt.setfib == NGX_ERROR) {
3834                 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3835                                    "invalid setfib \"%V\"", &value[n]);
3836                 return NGX_CONF_ERROR;
3837             }
3838 
3839             continue;
3840         }
3841 #endif
3842 
3843 #if (NGX_HAVE_TCP_FASTOPEN)
3844         if (ngx_strncmp(value[n].data, "fastopen=", 9) == 0) {
3845             lsopt.fastopen = ngx_atoi(value[n].data + 9, value[n].len - 9);
3846             lsopt.set = 1;
3847             lsopt.bind = 1;
3848 
3849             if (lsopt.fastopen == NGX_ERROR) {
3850                 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3851                                    "invalid fastopen \"%V\"", &value[n]);
3852                 return NGX_CONF_ERROR;
3853             }
3854 
3855             continue;
3856         }
3857 #endif
3858 
3859         if (ngx_strncmp(value[n].data, "backlog=", 8) == 0) {
3860             lsopt.backlog = ngx_atoi(value[n].data + 8, value[n].len - 8);
3861             lsopt.set = 1;
3862             lsopt.bind = 1;
3863 
3864             if (lsopt.backlog == NGX_ERROR || lsopt.backlog == 0) {
3865                 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3866                                    "invalid backlog \"%V\"", &value[n]);
3867                 return NGX_CONF_ERROR;
3868             }
3869 
3870             continue;
3871         }
3872 
3873         if (ngx_strncmp(value[n].data, "rcvbuf=", 7) == 0) {
3874             size.len = value[n].len - 7;
3875             size.data = value[n].data + 7;
3876 
3877             lsopt.rcvbuf = ngx_parse_size(&size);
3878             lsopt.set = 1;
3879             lsopt.bind = 1;
3880 
3881             if (lsopt.rcvbuf == NGX_ERROR) {
3882                 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3883                                    "invalid rcvbuf \"%V\"", &value[n]);
3884                 return NGX_CONF_ERROR;
3885             }
3886 
3887             continue;
3888         }
3889 
3890         if (ngx_strncmp(value[n].data, "sndbuf=", 7) == 0) {
3891             size.len = value[n].len - 7;
3892             size.data = value[n].data + 7;
3893 
3894             lsopt.sndbuf = ngx_parse_size(&size);
3895             lsopt.set = 1;
3896             lsopt.bind = 1;
3897 
3898             if (lsopt.sndbuf == NGX_ERROR) {
3899                 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3900                                    "invalid sndbuf \"%V\"", &value[n]);
3901                 return NGX_CONF_ERROR;
3902             }
3903 
3904             continue;
3905         }
3906 
3907         if (ngx_strncmp(value[n].data, "accept_filter=", 14) == 0) {
3908 #if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER)
3909             lsopt.accept_filter = (char *) &value[n].data[14];
3910             lsopt.set = 1;
3911             lsopt.bind = 1;
3912 #else
3913             ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3914                                "accept filters \"%V\" are not supported "
3915                                "on this platform, ignored",
3916                                &value[n]);
3917 #endif
3918             continue;
3919         }
3920 
3921         if (ngx_strcmp(value[n].data, "deferred") == 0) {
3922 #if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT)
3923             lsopt.deferred_accept = 1;
3924             lsopt.set = 1;
3925             lsopt.bind = 1;
3926 #else
3927             ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3928                                "the deferred accept is not supported "
3929                                "on this platform, ignored");
3930 #endif
3931             continue;
3932         }
3933 
3934         if (ngx_strncmp(value[n].data, "ipv6only=o", 10) == 0) {
3935 #if (NGX_HAVE_INET6 && defined IPV6_V6ONLY)
3936             if (ngx_strcmp(&value[n].data[10], "n") == 0) {
3937                 lsopt.ipv6only = 1;
3938 
3939             } else if (ngx_strcmp(&value[n].data[10], "ff") == 0) {
3940                 lsopt.ipv6only = 0;
3941 
3942             } else {
3943                 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3944                                    "invalid ipv6only flags \"%s\"",
3945                                    &value[n].data[9]);
3946                 return NGX_CONF_ERROR;
3947             }
3948 
3949             lsopt.set = 1;
3950             lsopt.bind = 1;
3951 
3952             continue;
3953 #else
3954             ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3955                                "ipv6only is not supported "
3956                                "on this platform");
3957             return NGX_CONF_ERROR;
3958 #endif
3959         }
3960 
3961         if (ngx_strcmp(value[n].data, "reuseport") == 0) {
3962 #if (NGX_HAVE_REUSEPORT)
3963             lsopt.reuseport = 1;
3964             lsopt.set = 1;
3965             lsopt.bind = 1;
3966 #else
3967             ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3968                                "reuseport is not supported "
3969                                "on this platform, ignored");
3970 #endif
3971             continue;
3972         }
3973 
3974         if (ngx_strcmp(value[n].data, "ssl") == 0) {
3975 #if (NGX_HTTP_SSL)
3976             lsopt.ssl = 1;
3977             continue;
3978 #else
3979             ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3980                                "the \"ssl\" parameter requires "
3981                                "ngx_http_ssl_module");
3982             return NGX_CONF_ERROR;
3983 #endif
3984         }
3985 
3986         if (ngx_strcmp(value[n].data, "http2") == 0) {
3987 #if (NGX_HTTP_V2)
3988             lsopt.http2 = 1;
3989             continue;
3990 #else
3991             ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3992                                "the \"http2\" parameter requires "
3993                                "ngx_http_v2_module");
3994             return NGX_CONF_ERROR;
3995 #endif
3996         }
3997 
3998         if (ngx_strcmp(value[n].data, "spdy") == 0) {
3999             ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
4000                                "invalid parameter \"spdy\": "
4001                                "ngx_http_spdy_module was superseded "
4002                                "by ngx_http_v2_module");
4003             continue;
4004         }
4005 
4006         if (ngx_strncmp(value[n].data, "so_keepalive=", 13) == 0) {
4007 
4008             if (ngx_strcmp(&value[n].data[13], "on") == 0) {
4009                 lsopt.so_keepalive = 1;
4010 
4011             } else if (ngx_strcmp(&value[n].data[13], "off") == 0) {
4012                 lsopt.so_keepalive = 2;
4013 
4014             } else {
4015 
4016 #if (NGX_HAVE_KEEPALIVE_TUNABLE)
4017                 u_char     *p, *end;
4018                 ngx_str_t   s;
4019 
4020                 end = value[n].data + value[n].len;
4021                 s.data = value[n].data + 13;
4022 
4023                 p = ngx_strlchr(s.data, end, ':');
4024                 if (p == NULL) {
4025                     p = end;
4026                 }
4027 
4028                 if (p > s.data) {
4029                     s.len = p - s.data;
4030 
4031                     lsopt.tcp_keepidle = ngx_parse_time(&s, 1);
4032                     if (lsopt.tcp_keepidle == (time_t) NGX_ERROR) {
4033                         goto invalid_so_keepalive;
4034                     }
4035                 }
4036 
4037                 s.data = (p < end) ? (p + 1) : end;
4038 
4039                 p = ngx_strlchr(s.data, end, ':');
4040                 if (p == NULL) {
4041                     p = end;
4042                 }
4043 
4044                 if (p > s.data) {
4045                     s.len = p - s.data;
4046 
4047                     lsopt.tcp_keepintvl = ngx_parse_time(&s, 1);
4048                     if (lsopt.tcp_keepintvl == (time_t) NGX_ERROR) {
4049                         goto invalid_so_keepalive;
4050                     }
4051                 }
4052 
4053                 s.data = (p < end) ? (p + 1) : end;
4054 
4055                 if (s.data < end) {
4056                     s.len = end - s.data;
4057 
4058                     lsopt.tcp_keepcnt = ngx_atoi(s.data, s.len);
4059                     if (lsopt.tcp_keepcnt == NGX_ERROR) {
4060                         goto invalid_so_keepalive;
4061                     }
4062                 }
4063 
4064                 if (lsopt.tcp_keepidle == 0 && lsopt.tcp_keepintvl == 0
4065                     && lsopt.tcp_keepcnt == 0)
4066                 {
4067                     goto invalid_so_keepalive;
4068                 }
4069 
4070                 lsopt.so_keepalive = 1;
4071 
4072 #else
4073 
4074                 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
4075                                    "the \"so_keepalive\" parameter accepts "
4076                                    "only \"on\" or \"off\" on this platform");
4077                 return NGX_CONF_ERROR;
4078 
4079 #endif
4080             }
4081 
4082             lsopt.set = 1;
4083             lsopt.bind = 1;
4084 
4085             continue;
4086 
4087 #if (NGX_HAVE_KEEPALIVE_TUNABLE)
4088         invalid_so_keepalive:
4089 
4090             ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
4091                                "invalid so_keepalive value: \"%s\"",
4092                                &value[n].data[13]);
4093             return NGX_CONF_ERROR;
4094 #endif
4095         }
4096 
4097         if (ngx_strcmp(value[n].data, "proxy_protocol") == 0) {
4098             lsopt.proxy_protocol = 1;
4099             continue;
4100         }
4101 
4102         ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
4103                            "invalid parameter \"%V\"", &value[n]);
4104         return NGX_CONF_ERROR;
4105     }
4106 
4107     for (n = 0; n < u.naddrs; n++) {
4108         lsopt.sockaddr = u.addrs[n].sockaddr;
4109         lsopt.socklen = u.addrs[n].socklen;
4110         lsopt.addr_text = u.addrs[n].name;
4111         lsopt.wildcard = ngx_inet_wildcard(lsopt.sockaddr);
4112 
4113         if (ngx_http_add_listen(cf, cscf, &lsopt) != NGX_OK) {
4114             return NGX_CONF_ERROR;
4115         }
4116     }
4117 
4118     return NGX_CONF_OK;
4119 }
4120 
4121 
4122 static char *
4123 ngx_http_core_server_name(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
4124 {
4125     ngx_http_core_srv_conf_t *cscf = conf;
4126 
4127     u_char                   ch;
4128     ngx_str_t               *value;
4129     ngx_uint_t               i;
4130     ngx_http_server_name_t  *sn;
4131 
4132     value = cf->args->elts;
4133 
4134     for (i = 1; i < cf->args->nelts; i++) {
4135 
4136         ch = value[i].data[0];
4137 
4138         if ((ch == '*' && (value[i].len < 3 || value[i].data[1] != '.'))
4139             || (ch == '.' && value[i].len < 2))
4140         {
4141             ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
4142                                "server name \"%V\" is invalid", &value[i]);
4143             return NGX_CONF_ERROR;
4144         }
4145 
4146         if (ngx_strchr(value[i].data, '/')) {
4147             ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
4148                                "server name \"%V\" has suspicious symbols",
4149                                &value[i]);
4150         }
4151 
4152         sn = ngx_array_push(&cscf->server_names);
4153         if (sn == NULL) {
4154             return NGX_CONF_ERROR;
4155         }
4156 
4157 #if (NGX_PCRE)
4158         sn->regex = NULL;
4159 #endif
4160         sn->server = cscf;
4161 
4162         if (ngx_strcasecmp(value[i].data, (u_char *) "$hostname") == 0) {
4163             sn->name = cf->cycle->hostname;
4164 
4165         } else {
4166             sn->name = value[i];
4167         }
4168 
4169         if (value[i].data[0] != '~') {
4170             ngx_strlow(sn->name.data, sn->name.data, sn->name.len);
4171             continue;
4172         }
4173 
4174 #if (NGX_PCRE)
4175         {
4176         u_char               *p;
4177         ngx_regex_compile_t   rc;
4178         u_char                errstr[NGX_MAX_CONF_ERRSTR];
4179 
4180         if (value[i].len == 1) {
4181             ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
4182                                "empty regex in server name \"%V\"", &value[i]);
4183             return NGX_CONF_ERROR;
4184         }
4185 
4186         value[i].len--;
4187         value[i].data++;
4188 
4189         ngx_memzero(&rc, sizeof(ngx_regex_compile_t));
4190 
4191         rc.pattern = value[i];
4192         rc.err.len = NGX_MAX_CONF_ERRSTR;
4193         rc.err.data = errstr;
4194 
4195         for (p = value[i].data; p < value[i].data + value[i].len; p++) {
4196             if (*p >= 'A' && *p <= 'Z') {
4197                 rc.options = NGX_REGEX_CASELESS;
4198                 break;
4199             }
4200         }
4201 
4202         sn->regex = ngx_http_regex_compile(cf, &rc);
4203         if (sn->regex == NULL) {
4204             return NGX_CONF_ERROR;
4205         }
4206 
4207         sn->name = value[i];
4208         cscf->captures = (rc.captures > 0);
4209         }
4210 #else
4211         ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
4212                            "using regex \"%V\" "
4213                            "requires PCRE library", &value[i]);
4214 
4215         return NGX_CONF_ERROR;
4216 #endif
4217     }
4218 
4219     return NGX_CONF_OK;
4220 }
4221 
4222 
4223 static char *
4224 ngx_http_core_root(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
4225 {
4226     ngx_http_core_loc_conf_t *clcf = conf;
4227 
4228     ngx_str_t                  *value;
4229     ngx_int_t                   alias;
4230     ngx_uint_t                  n;
4231     ngx_http_script_compile_t   sc;
4232 
4233     alias = (cmd->name.len == sizeof("alias") - 1) ? 1 : 0;
4234 
4235     if (clcf->root.data) {
4236 
4237         if ((clcf->alias != 0) == alias) {
4238             return "is duplicate";
4239         }
4240 
4241         ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
4242                            "\"%V\" directive is duplicate, "
4243                            "\"%s\" directive was specified earlier",
4244                            &cmd->name, clcf->alias ? "alias" : "root");
4245 
4246         return NGX_CONF_ERROR;
4247     }
4248 
4249     if (clcf->named && alias) {
4250         ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
4251                            "the \"alias\" directive cannot be used "
4252                            "inside the named location");
4253 
4254         return NGX_CONF_ERROR;
4255     }
4256 
4257     value = cf->args->elts;
4258 
4259     if (ngx_strstr(value[1].data, "$document_root")
4260         || ngx_strstr(value[1].data, "${document_root}"))
4261     {
4262         ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
4263                            "the $document_root variable cannot be used "
4264                            "in the \"%V\" directive",
4265                            &cmd->name);
4266 
4267         return NGX_CONF_ERROR;
4268     }
4269 
4270     if (ngx_strstr(value[1].data, "$realpath_root")
4271         || ngx_strstr(value[1].data, "${realpath_root}"))
4272     {
4273         ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
4274                            "the $realpath_root variable cannot be used "
4275                            "in the \"%V\" directive",
4276                            &cmd->name);
4277 
4278         return NGX_CONF_ERROR;
4279     }
4280 
4281     clcf->alias = alias ? clcf->name.len : 0;
4282     clcf->root = value[1];
4283 
4284     if (!alias && clcf->root.len > 0
4285         && clcf->root.data[clcf->root.len - 1] == '/')
4286     {
4287         clcf->root.len--;
4288     }
4289 
4290     if (clcf->root.data[0] != '$') {
4291         if (ngx_conf_full_name(cf->cycle, &clcf->root, 0) != NGX_OK) {
4292             return NGX_CONF_ERROR;
4293         }
4294     }
4295 
4296     n = ngx_http_script_variables_count(&clcf->root);
4297 
4298     ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
4299     sc.variables = n;
4300 
4301 #if (NGX_PCRE)
4302     if (alias && clcf->regex) {
4303         clcf->alias = NGX_MAX_SIZE_T_VALUE;
4304         n = 1;
4305     }
4306 #endif
4307 
4308     if (n) {
4309         sc.cf = cf;
4310         sc.source = &clcf->root;
4311         sc.lengths = &clcf->root_lengths;
4312         sc.values = &clcf->root_values;
4313         sc.complete_lengths = 1;
4314         sc.complete_values = 1;
4315 
4316         if (ngx_http_script_compile(&sc) != NGX_OK) {
4317             return NGX_CONF_ERROR;
4318         }
4319     }
4320 
4321     return NGX_CONF_OK;
4322 }
4323 
4324 
4325 static ngx_http_method_name_t  ngx_methods_names[] = {
4326     { (u_char *) "GET",       (uint32_t) ~NGX_HTTP_GET },
4327     { (u_char *) "HEAD",      (uint32_t) ~NGX_HTTP_HEAD },
4328     { (u_char *) "POST",      (uint32_t) ~NGX_HTTP_POST },
4329     { (u_char *) "PUT",       (uint32_t) ~NGX_HTTP_PUT },
4330     { (u_char *) "DELETE",    (uint32_t) ~NGX_HTTP_DELETE },
4331     { (u_char *) "MKCOL",     (uint32_t) ~NGX_HTTP_MKCOL },
4332     { (u_char *) "COPY",      (uint32_t) ~NGX_HTTP_COPY },
4333     { (u_char *) "MOVE",      (uint32_t) ~NGX_HTTP_MOVE },
4334     { (u_char *) "OPTIONS",   (uint32_t) ~NGX_HTTP_OPTIONS },
4335     { (u_char *) "PROPFIND",  (uint32_t) ~NGX_HTTP_PROPFIND },
4336     { (u_char *) "PROPPATCH", (uint32_t) ~NGX_HTTP_PROPPATCH },
4337     { (u_char *) "LOCK",      (uint32_t) ~NGX_HTTP_LOCK },
4338     { (u_char *) "UNLOCK",    (uint32_t) ~NGX_HTTP_UNLOCK },
4339     { (u_char *) "PATCH",     (uint32_t) ~NGX_HTTP_PATCH },
4340     { NULL, 0 }
4341 };
4342 
4343 
4344 static char *
4345 ngx_http_core_limit_except(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
4346 {
4347     ngx_http_core_loc_conf_t *pclcf = conf;
4348 
4349     char                      *rv;
4350     void                      *mconf;
4351     ngx_str_t                 *value;
4352     ngx_uint_t                 i;
4353     ngx_conf_t                 save;
4354     ngx_http_module_t         *module;
4355     ngx_http_conf_ctx_t       *ctx, *pctx;
4356     ngx_http_method_name_t    *name;
4357     ngx_http_core_loc_conf_t  *clcf;
4358 
4359     if (pclcf->limit_except) {
4360         return "is duplicate";
4361     }
4362 
4363     pclcf->limit_except = 0xffffffff;
4364 
4365     value = cf->args->elts;
4366 
4367     for (i = 1; i < cf->args->nelts; i++) {
4368         for (name = ngx_methods_names; name->name; name++) {
4369 
4370             if (ngx_strcasecmp(value[i].data, name->name) == 0) {
4371                 pclcf->limit_except &= name->method;
4372                 goto next;
4373             }
4374         }
4375 
4376         ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
4377                            "invalid method \"%V\"", &value[i]);
4378         return NGX_CONF_ERROR;
4379 
4380     next:
4381         continue;
4382     }
4383 
4384     if (!(pclcf->limit_except & NGX_HTTP_GET)) {
4385         pclcf->limit_except &= (uint32_t) ~NGX_HTTP_HEAD;
4386     }
4387 
4388     ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t));
4389     if (ctx == NULL) {
4390         return NGX_CONF_ERROR;
4391     }
4392 
4393     pctx = cf->ctx;
4394     ctx->main_conf = pctx->main_conf;
4395     ctx->srv_conf = pctx->srv_conf;
4396 
4397     ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
4398     if (ctx->loc_conf == NULL) {
4399         return NGX_CONF_ERROR;
4400     }
4401 
4402     for (i = 0; cf->cycle->modules[i]; i++) {
4403         if (cf->cycle->modules[i]->type != NGX_HTTP_MODULE) {
4404             continue;
4405         }
4406 
4407         module = cf->cycle->modules[i]->ctx;
4408 
4409         if (module->create_loc_conf) {
4410 
4411             mconf = module->create_loc_conf(cf);
4412             if (mconf == NULL) {
4413                 return NGX_CONF_ERROR;
4414             }
4415 
4416             ctx->loc_conf[cf->cycle->modules[i]->ctx_index] = mconf;
4417         }
4418     }
4419 
4420 
4421     clcf = ctx->loc_conf[ngx_http_core_module.ctx_index];
4422     pclcf->limit_except_loc_conf = ctx->loc_conf;
4423     clcf->loc_conf = ctx->loc_conf;
4424     clcf->name = pclcf->name;
4425     clcf->noname = 1;
4426     clcf->lmt_excpt = 1;
4427 
4428     if (ngx_http_add_location(cf, &pclcf->locations, clcf) != NGX_OK) {
4429         return NGX_CONF_ERROR;
4430     }
4431 
4432     save = *cf;
4433     cf->ctx = ctx;
4434     cf->cmd_type = NGX_HTTP_LMT_CONF;
4435 
4436     rv = ngx_conf_parse(cf, NULL);
4437 
4438     *cf = save;
4439 
4440     return rv;
4441 }
4442 
4443 
4444 static char *
4445 ngx_http_core_set_aio(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
4446 {
4447     ngx_http_core_loc_conf_t *clcf = conf;
4448 
4449     ngx_str_t  *value;
4450 
4451     if (clcf->aio != NGX_CONF_UNSET) {
4452         return "is duplicate";
4453     }
4454 
4455 #if (NGX_THREADS)
4456     clcf->thread_pool = NULL;
4457     clcf->thread_pool_value = NULL;
4458 #endif
4459 
4460     value = cf->args->elts;
4461 
4462     if (ngx_strcmp(value[1].data, "off") == 0) {
4463         clcf->aio = NGX_HTTP_AIO_OFF;
4464         return NGX_CONF_OK;
4465     }
4466 
4467     if (ngx_strcmp(value[1].data, "on") == 0) {
4468 #if (NGX_HAVE_FILE_AIO)
4469         clcf->aio = NGX_HTTP_AIO_ON;
4470         return NGX_CONF_OK;
4471 #else
4472         ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
4473                            "\"aio on\" "
4474                            "is unsupported on this platform");
4475         return NGX_CONF_ERROR;
4476 #endif
4477     }
4478 
4479 #if (NGX_HAVE_AIO_SENDFILE)
4480 
4481     if (ngx_strcmp(value[1].data, "sendfile") == 0) {
4482         clcf->aio = NGX_HTTP_AIO_ON;
4483 
4484         ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
4485                            "the \"sendfile\" parameter of "
4486                            "the \"aio\" directive is deprecated");
4487         return NGX_CONF_OK;
4488     }
4489 
4490 #endif
4491 
4492     if (ngx_strncmp(value[1].data, "threads", 7) == 0
4493         && (value[1].len == 7 || value[1].data[7] == '='))
4494     {
4495 #if (NGX_THREADS)
4496         ngx_str_t                          name;
4497         ngx_thread_pool_t                 *tp;
4498         ngx_http_complex_value_t           cv;
4499         ngx_http_compile_complex_value_t   ccv;
4500 
4501         clcf->aio = NGX_HTTP_AIO_THREADS;
4502 
4503         if (value[1].len >= 8) {
4504             name.len = value[1].len - 8;
4505             name.data = value[1].data + 8;
4506 
4507             ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
4508 
4509             ccv.cf = cf;
4510             ccv.value = &name;
4511             ccv.complex_value = &cv;
4512 
4513             if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
4514                 return NGX_CONF_ERROR;
4515             }
4516 
4517             if (cv.lengths != NULL) {
4518                 clcf->thread_pool_value = ngx_palloc(cf->pool,
4519                                     sizeof(ngx_http_complex_value_t));
4520                 if (clcf->thread_pool_value == NULL) {
4521                     return NGX_CONF_ERROR;
4522                 }
4523 
4524                 *clcf->thread_pool_value = cv;
4525 
4526                 return NGX_CONF_OK;
4527             }
4528 
4529             tp = ngx_thread_pool_add(cf, &name);
4530 
4531         } else {
4532             tp = ngx_thread_pool_add(cf, NULL);
4533         }
4534 
4535         if (tp == NULL) {
4536             return NGX_CONF_ERROR;
4537         }
4538 
4539         clcf->thread_pool = tp;
4540 
4541         return NGX_CONF_OK;
4542 #else
4543         ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
4544                            "\"aio threads\" "
4545                            "is unsupported on this platform");
4546         return NGX_CONF_ERROR;
4547 #endif
4548     }
4549 
4550     return "invalid value";
4551 }
4552 
4553 
4554 static char *
4555 ngx_http_core_directio(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
4556 {
4557     ngx_http_core_loc_conf_t *clcf = conf;
4558 
4559     ngx_str_t  *value;
4560 
4561     if (clcf->directio != NGX_CONF_UNSET) {
4562         return "is duplicate";
4563     }
4564 
4565     value = cf->args->elts;
4566 
4567     if (ngx_strcmp(value[1].data, "off") == 0) {
4568         clcf->directio = NGX_OPEN_FILE_DIRECTIO_OFF;
4569         return NGX_CONF_OK;
4570     }
4571 
4572     clcf->directio = ngx_parse_offset(&value[1]);
4573     if (clcf->directio == (off_t) NGX_ERROR) {
4574         return "invalid value";
4575     }
4576 
4577     return NGX_CONF_OK;
4578 }
4579 
4580 
4581 static char *
4582 ngx_http_core_error_page(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
4583 {
4584     ngx_http_core_loc_conf_t *clcf = conf;
4585 
4586     u_char                            *p;
4587     ngx_int_t                          overwrite;
4588     ngx_str_t                         *value, uri, args;
4589     ngx_uint_t                         i, n;
4590     ngx_http_err_page_t               *err;
4591     ngx_http_complex_value_t           cv;
4592     ngx_http_compile_complex_value_t   ccv;
4593 
4594     if (clcf->error_pages == NULL) {
4595         clcf->error_pages = ngx_array_create(cf->pool, 4,
4596                                              sizeof(ngx_http_err_page_t));
4597         if (clcf->error_pages == NULL) {
4598             return NGX_CONF_ERROR;
4599         }
4600     }
4601 
4602     value = cf->args->elts;
4603 
4604     i = cf->args->nelts - 2;
4605 
4606     if (value[i].data[0] == '=') {
4607         if (i == 1) {
4608             ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
4609                                "invalid value \"%V\"", &value[i]);
4610             return NGX_CONF_ERROR;
4611         }
4612 
4613         if (value[i].len > 1) {
4614             overwrite = ngx_atoi(&value[i].data[1], value[i].len - 1);
4615 
4616             if (overwrite == NGX_ERROR) {
4617                 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
4618                                    "invalid value \"%V\"", &value[i]);
4619                 return NGX_CONF_ERROR;
4620             }
4621 
4622         } else {
4623             overwrite = 0;
4624         }
4625 
4626         n = 2;
4627 
4628     } else {
4629         overwrite = -1;
4630         n = 1;
4631     }
4632 
4633     uri = value[cf->args->nelts - 1];
4634 
4635     ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
4636 
4637     ccv.cf = cf;
4638     ccv.value = &uri;
4639     ccv.complex_value = &cv;
4640 
4641     if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
4642         return NGX_CONF_ERROR;
4643     }
4644 
4645     ngx_str_null(&args);
4646 
4647     if (cv.lengths == NULL && uri.len && uri.data[0] == '/') {
4648         p = (u_char *) ngx_strchr(uri.data, '?');
4649 
4650         if (p) {
4651             cv.value.len = p - uri.data;
4652             cv.value.data = uri.data;
4653             p++;
4654             args.len = (uri.data + uri.len) - p;
4655             args.data = p;
4656         }
4657     }
4658 
4659     for (i = 1; i < cf->args->nelts - n; i++) {
4660         err = ngx_array_push(clcf->error_pages);
4661         if (err == NULL) {
4662             return NGX_CONF_ERROR;
4663         }
4664 
4665         err->status = ngx_atoi(value[i].data, value[i].len);
4666 
4667         if (err->status == NGX_ERROR || err->status == 499) {
4668             ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
4669                                "invalid value \"%V\"", &value[i]);
4670             return NGX_CONF_ERROR;
4671         }
4672 
4673         if (err->status < 300 || err->status > 599) {
4674             ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
4675                                "value \"%V\" must be between 300 and 599",
4676                                &value[i]);
4677             return NGX_CONF_ERROR;
4678         }
4679 
4680         err->overwrite = overwrite;
4681 
4682         if (overwrite == -1) {
4683             switch (err->status) {
4684                 case NGX_HTTP_TO_HTTPS:
4685                 case NGX_HTTPS_CERT_ERROR:
4686                 case NGX_HTTPS_NO_CERT:
4687                     err->overwrite = NGX_HTTP_BAD_REQUEST;
4688             }
4689         }
4690 
4691         err->value = cv;
4692         err->args = args;
4693     }
4694 
4695     return NGX_CONF_OK;
4696 }
4697 
4698 
4699 static char *
4700 ngx_http_core_open_file_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
4701 {
4702     ngx_http_core_loc_conf_t *clcf = conf;
4703 
4704     time_t       inactive;
4705     ngx_str_t   *value, s;
4706     ngx_int_t    max;
4707     ngx_uint_t   i;
4708 
4709     if (clcf->open_file_cache != NGX_CONF_UNSET_PTR) {
4710         return "is duplicate";
4711     }
4712 
4713     value = cf->args->elts;
4714 
4715     max = 0;
4716     inactive = 60;
4717 
4718     for (i = 1; i < cf->args->nelts; i++) {
4719 
4720         if (ngx_strncmp(value[i].data, "max=", 4) == 0) {
4721 
4722             max = ngx_atoi(value[i].data + 4, value[i].len - 4);
4723             if (max <= 0) {
4724                 goto failed;
4725             }
4726 
4727             continue;
4728         }
4729 
4730         if (ngx_strncmp(value[i].data, "inactive=", 9) == 0) {
4731 
4732             s.len = value[i].len - 9;
4733             s.data = value[i].data + 9;
4734 
4735             inactive = ngx_parse_time(&s, 1);
4736             if (inactive == (time_t) NGX_ERROR) {
4737                 goto failed;
4738             }
4739 
4740             continue;
4741         }
4742 
4743         if (ngx_strcmp(value[i].data, "off") == 0) {
4744 
4745             clcf->open_file_cache = NULL;
4746 
4747             continue;
4748         }
4749 
4750     failed:
4751 
4752         ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
4753                            "invalid \"open_file_cache\" parameter \"%V\"",
4754                            &value[i]);
4755         return NGX_CONF_ERROR;
4756     }
4757 
4758     if (clcf->open_file_cache == NULL) {
4759         return NGX_CONF_OK;
4760     }
4761 
4762     if (max == 0) {
4763         ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
4764                         "\"open_file_cache\" must have the \"max\" parameter");
4765         return NGX_CONF_ERROR;
4766     }
4767 
4768     clcf->open_file_cache = ngx_open_file_cache_init(cf->pool, max, inactive);
4769     if (clcf->open_file_cache) {
4770         return NGX_CONF_OK;
4771     }
4772 
4773     return NGX_CONF_ERROR;
4774 }
4775 
4776 
4777 static char *
4778 ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
4779 {
4780     ngx_http_core_loc_conf_t *clcf = conf;
4781 
4782     return ngx_log_set_log(cf, &clcf->error_log);
4783 }
4784 
4785 
4786 static char *
4787 ngx_http_core_keepalive(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
4788 {
4789     ngx_http_core_loc_conf_t *clcf = conf;
4790 
4791     ngx_str_t  *value;
4792 
4793     if (clcf->keepalive_timeout != NGX_CONF_UNSET_MSEC) {
4794         return "is duplicate";
4795     }
4796 
4797     value = cf->args->elts;
4798 
4799     clcf->keepalive_timeout = ngx_parse_time(&value[1], 0);
4800 
4801     if (clcf->keepalive_timeout == (ngx_msec_t) NGX_ERROR) {
4802         return "invalid value";
4803     }
4804 
4805     if (cf->args->nelts == 2) {
4806         return NGX_CONF_OK;
4807     }
4808 
4809     clcf->keepalive_header = ngx_parse_time(&value[2], 1);
4810 
4811     if (clcf->keepalive_header == (time_t) NGX_ERROR) {
4812         return "invalid value";
4813     }
4814 
4815     return NGX_CONF_OK;
4816 }
4817 
4818 
4819 static char *
4820 ngx_http_core_internal(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
4821 {
4822     ngx_http_core_loc_conf_t *clcf = conf;
4823 
4824     if (clcf->internal != NGX_CONF_UNSET) {
4825         return "is duplicate";
4826     }
4827 
4828     clcf->internal = 1;
4829 
4830     return NGX_CONF_OK;
4831 }
4832 
4833 
4834 static char *
4835 ngx_http_core_resolver(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
4836 {
4837     ngx_http_core_loc_conf_t  *clcf = conf;
4838 
4839     ngx_str_t  *value;
4840 
4841     if (clcf->resolver) {
4842         return "is duplicate";
4843     }
4844 
4845     value = cf->args->elts;
4846 
4847     clcf->resolver = ngx_resolver_create(cf, &value[1], cf->args->nelts - 1);
4848     if (clcf->resolver == NULL) {
4849         return NGX_CONF_ERROR;
4850     }
4851 
4852     return NGX_CONF_OK;
4853 }
4854 
4855 
4856 #if (NGX_HTTP_GZIP)
4857 
4858 static char *
4859 ngx_http_gzip_disable(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
4860 {
4861     ngx_http_core_loc_conf_t  *clcf = conf;
4862 
4863 #if (NGX_PCRE)
4864 
4865     ngx_str_t            *value;
4866     ngx_uint_t            i;
4867     ngx_regex_elt_t      *re;
4868     ngx_regex_compile_t   rc;
4869     u_char                errstr[NGX_MAX_CONF_ERRSTR];
4870 
4871     if (clcf->gzip_disable == NGX_CONF_UNSET_PTR) {
4872         clcf->gzip_disable = ngx_array_create(cf->pool, 2,
4873                                               sizeof(ngx_regex_elt_t));
4874         if (clcf->gzip_disable == NULL) {
4875             return NGX_CONF_ERROR;
4876         }
4877     }
4878 
4879     value = cf->args->elts;
4880 
4881     ngx_memzero(&rc, sizeof(ngx_regex_compile_t));
4882 
4883     rc.pool = cf->pool;
4884     rc.err.len = NGX_MAX_CONF_ERRSTR;
4885     rc.err.data = errstr;
4886 
4887     for (i = 1; i < cf->args->nelts; i++) {
4888 
4889         if (ngx_strcmp(value[i].data, "msie6") == 0) {
4890             clcf->gzip_disable_msie6 = 1;
4891             continue;
4892         }
4893 
4894 #if (NGX_HTTP_DEGRADATION)
4895 
4896         if (ngx_strcmp(value[i].data, "degradation") == 0) {
4897             clcf->gzip_disable_degradation = 1;
4898             continue;
4899         }
4900 
4901 #endif
4902 
4903         re = ngx_array_push(clcf->gzip_disable);
4904         if (re == NULL) {
4905             return NGX_CONF_ERROR;
4906         }
4907 
4908         rc.pattern = value[i];
4909         rc.options = NGX_REGEX_CASELESS;
4910 
4911         if (ngx_regex_compile(&rc) != NGX_OK) {
4912             ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%V", &rc.err);
4913             return NGX_CONF_ERROR;
4914         }
4915 
4916         re->regex = rc.regex;
4917         re->name = value[i].data;
4918     }
4919 
4920     return NGX_CONF_OK;
4921 
4922 #else
4923     ngx_str_t   *value;
4924     ngx_uint_t   i;
4925 
4926     value = cf->args->elts;
4927 
4928     for (i = 1; i < cf->args->nelts; i++) {
4929         if (ngx_strcmp(value[i].data, "msie6") == 0) {
4930             clcf->gzip_disable_msie6 = 1;
4931             continue;
4932         }
4933 
4934 #if (NGX_HTTP_DEGRADATION)
4935 
4936         if (ngx_strcmp(value[i].data, "degradation") == 0) {
4937             clcf->gzip_disable_degradation = 1;
4938             continue;
4939         }
4940 
4941 #endif
4942 
4943         ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
4944                            "without PCRE library \"gzip_disable\" supports "
4945                            "builtin \"msie6\" and \"degradation\" mask only");
4946 
4947         return NGX_CONF_ERROR;
4948     }
4949 
4950     return NGX_CONF_OK;
4951 
4952 #endif
4953 }
4954 
4955 #endif
4956 
4957 
4958 #if (NGX_HAVE_OPENAT)
4959 
4960 static char *
4961 ngx_http_disable_symlinks(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
4962 {
4963     ngx_http_core_loc_conf_t *clcf = conf;
4964 
4965     ngx_str_t                         *value;
4966     ngx_uint_t                         i;
4967     ngx_http_compile_complex_value_t   ccv;
4968 
4969     if (clcf->disable_symlinks != NGX_CONF_UNSET_UINT) {
4970         return "is duplicate";
4971     }
4972 
4973     value = cf->args->elts;
4974 
4975     for (i = 1; i < cf->args->nelts; i++) {
4976 
4977         if (ngx_strcmp(value[i].data, "off") == 0) {
4978             clcf->disable_symlinks = NGX_DISABLE_SYMLINKS_OFF;
4979             continue;
4980         }
4981 
4982         if (ngx_strcmp(value[i].data, "if_not_owner") == 0) {
4983             clcf->disable_symlinks = NGX_DISABLE_SYMLINKS_NOTOWNER;
4984             continue;
4985         }
4986 
4987         if (ngx_strcmp(value[i].data, "on") == 0) {
4988             clcf->disable_symlinks = NGX_DISABLE_SYMLINKS_ON;
4989             continue;
4990         }
4991 
4992         if (ngx_strncmp(value[i].data, "from=", 5) == 0) {
4993             value[i].len -= 5;
4994             value[i].data += 5;
4995 
4996             ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
4997 
4998             ccv.cf = cf;
4999             ccv.value = &value[i];
5000             ccv.complex_value = ngx_palloc(cf->pool,
5001                                            sizeof(ngx_http_complex_value_t));
5002             if (ccv.complex_value == NULL) {
5003                 return NGX_CONF_ERROR;
5004             }
5005 
5006             if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
5007                 return NGX_CONF_ERROR;
5008             }
5009 
5010             clcf->disable_symlinks_from = ccv.complex_value;
5011 
5012             continue;
5013         }
5014 
5015         ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
5016                            "invalid parameter \"%V\"", &value[i]);
5017         return NGX_CONF_ERROR;
5018     }
5019 
5020     if (clcf->disable_symlinks == NGX_CONF_UNSET_UINT) {
5021         ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
5022                            "\"%V\" must have \"off\", \"on\" "
5023                            "or \"if_not_owner\" parameter",
5024                            &cmd->name);
5025         return NGX_CONF_ERROR;
5026     }
5027 
5028     if (cf->args->nelts == 2) {
5029         clcf->disable_symlinks_from = NULL;
5030         return NGX_CONF_OK;
5031     }
5032 
5033     if (clcf->disable_symlinks_from == NGX_CONF_UNSET_PTR) {
5034         ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
5035                            "duplicate parameters \"%V %V\"",
5036                            &value[1], &value[2]);
5037         return NGX_CONF_ERROR;
5038     }
5039 
5040     if (clcf->disable_symlinks == NGX_DISABLE_SYMLINKS_OFF) {
5041         ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
5042                            "\"from=\" cannot be used with \"off\" parameter");
5043         return NGX_CONF_ERROR;
5044     }
5045 
5046     return NGX_CONF_OK;
5047 }
5048 
5049 #endif
5050 
5051 
5052 static char *
5053 ngx_http_core_lowat_check(ngx_conf_t *cf, void *post, void *data)
5054 {
5055 #if (NGX_FREEBSD)
5056     ssize_t *np = data;
5057 
5058     if ((u_long) *np >= ngx_freebsd_net_inet_tcp_sendspace) {
5059         ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
5060                            "\"send_lowat\" must be less than %d "
5061                            "(sysctl net.inet.tcp.sendspace)",
5062                            ngx_freebsd_net_inet_tcp_sendspace);
5063 
5064         return NGX_CONF_ERROR;
5065     }
5066 
5067 #elif !(NGX_HAVE_SO_SNDLOWAT)
5068     ssize_t *np = data;
5069 
5070     ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
5071                        "\"send_lowat\" is not supported, ignored");
5072 
5073     *np = 0;
5074 
5075 #endif
5076 
5077     return NGX_CONF_OK;
5078 }
5079 
5080 
5081 static char *
5082 ngx_http_core_pool_size(ngx_conf_t *cf, void *post, void *data)
5083 {
5084     size_t *sp = data;
5085 
5086     if (*sp < NGX_MIN_POOL_SIZE) {
5087         ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
5088                            "the pool size must be no less than %uz",
5089                            NGX_MIN_POOL_SIZE);
5090         return NGX_CONF_ERROR;
5091     }
5092 
5093     if (*sp % NGX_POOL_ALIGNMENT) {
5094         ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
5095                            "the pool size must be a multiple of %uz",
5096                            NGX_POOL_ALIGNMENT);
5097         return NGX_CONF_ERROR;
5098     }
5099 
5100     return NGX_CONF_OK;
5101 }