blob: 5c19167a91212d5d84bbb78bee118284d84b8556 [file] [log] [blame]
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001
Igor Sysoevd90282d2004-09-28 08:34:51 +00002/*
Igor Sysoevff8da912004-09-29 16:00:49 +00003 * Copyright (C) Igor Sysoev
Igor Sysoevd90282d2004-09-28 08:34:51 +00004 */
5
6
Igor Sysoev4e9393a2003-01-09 05:36:00 +00007#include <ngx_config.h>
Igor Sysoev4e9393a2003-01-09 05:36:00 +00008#include <ngx_core.h>
Igor Sysoevb3e73d82003-10-10 15:10:50 +00009#include <ngx_event.h>
Igor Sysoev6253ca12003-05-27 12:18:54 +000010#include <ngx_http.h>
Igor Sysoeva9830112003-05-19 16:39:14 +000011#include <nginx.h>
Igor Sysoev4e9393a2003-01-09 05:36:00 +000012
Igor Sysoev1b735832004-11-11 14:07:14 +000013
Igor Sysoev94e32ce2006-04-07 14:08:04 +000014typedef struct {
15 char *name;
16 uint32_t method;
17} ngx_http_method_name_t;
18
19
Igor Sysoev74a5ddb2004-07-18 19:11:20 +000020#define NGX_HTTP_LOCATION_EXACT 1
21#define NGX_HTTP_LOCATION_AUTO_REDIRECT 2
Igor Sysoevd43bee82004-11-20 19:52:20 +000022#define NGX_HTTP_LOCATION_NOREGEX 3
23#define NGX_HTTP_LOCATION_REGEX 4
Igor Sysoev74a5ddb2004-07-18 19:11:20 +000024
Igor Sysoev6253ca12003-05-27 12:18:54 +000025
Igor Sysoev805d9db2005-02-03 19:33:37 +000026static void ngx_http_core_run_phases(ngx_http_request_t *r);
27static ngx_int_t ngx_http_core_find_location(ngx_http_request_t *r,
Igor Sysoevaa828612005-02-09 14:31:07 +000028 ngx_array_t *locations, size_t len);
Igor Sysoev4e9393a2003-01-09 05:36:00 +000029
Igor Sysoev899b44e2005-05-12 14:58:06 +000030static ngx_int_t ngx_http_core_preconfiguration(ngx_conf_t *cf);
Igor Sysoev890fc962003-07-20 21:15:59 +000031static void *ngx_http_core_create_main_conf(ngx_conf_t *cf);
32static char *ngx_http_core_init_main_conf(ngx_conf_t *cf, void *conf);
33static void *ngx_http_core_create_srv_conf(ngx_conf_t *cf);
34static char *ngx_http_core_merge_srv_conf(ngx_conf_t *cf,
Igor Sysoevaa828612005-02-09 14:31:07 +000035 void *parent, void *child);
Igor Sysoev890fc962003-07-20 21:15:59 +000036static void *ngx_http_core_create_loc_conf(ngx_conf_t *cf);
37static char *ngx_http_core_merge_loc_conf(ngx_conf_t *cf,
Igor Sysoevaa828612005-02-09 14:31:07 +000038 void *parent, void *child);
Igor Sysoevdc479b42003-03-20 16:09:44 +000039
Igor Sysoev805d9db2005-02-03 19:33:37 +000040static char *ngx_http_core_server(ngx_conf_t *cf, ngx_command_t *cmd,
Igor Sysoevaa828612005-02-09 14:31:07 +000041 void *dummy);
Igor Sysoev805d9db2005-02-03 19:33:37 +000042static char *ngx_http_core_location(ngx_conf_t *cf, ngx_command_t *cmd,
Igor Sysoevaa828612005-02-09 14:31:07 +000043 void *dummy);
Igor Sysoev4d656dc2005-03-22 16:02:46 +000044static int ngx_libc_cdecl ngx_http_core_cmp_locations(const void *first,
45 const void *second);
Igor Sysoev805d9db2005-02-03 19:33:37 +000046
47static char *ngx_http_core_types(ngx_conf_t *cf, ngx_command_t *cmd,
Igor Sysoevaa828612005-02-09 14:31:07 +000048 void *conf);
Igor Sysoev805d9db2005-02-03 19:33:37 +000049static char *ngx_http_core_type(ngx_conf_t *cf, ngx_command_t *dummy,
Igor Sysoevaa828612005-02-09 14:31:07 +000050 void *conf);
Igor Sysoev4e9393a2003-01-09 05:36:00 +000051
Igor Sysoev805d9db2005-02-03 19:33:37 +000052static char *ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd,
Igor Sysoevaa828612005-02-09 14:31:07 +000053 void *conf);
Igor Sysoev805d9db2005-02-03 19:33:37 +000054static char *ngx_http_core_server_name(ngx_conf_t *cf, ngx_command_t *cmd,
Igor Sysoevaa828612005-02-09 14:31:07 +000055 void *conf);
Igor Sysoev805d9db2005-02-03 19:33:37 +000056static char *ngx_http_core_root(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
Igor Sysoev94e32ce2006-04-07 14:08:04 +000057static char *ngx_http_core_limit_except(ngx_conf_t *cf, ngx_command_t *cmd,
58 void *conf);
Igor Sysoev805d9db2005-02-03 19:33:37 +000059static char *ngx_http_core_error_page(ngx_conf_t *cf, ngx_command_t *cmd,
Igor Sysoevaa828612005-02-09 14:31:07 +000060 void *conf);
Igor Sysoev805d9db2005-02-03 19:33:37 +000061static char *ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd,
Igor Sysoevaa828612005-02-09 14:31:07 +000062 void *conf);
Igor Sysoev805d9db2005-02-03 19:33:37 +000063static char *ngx_http_core_keepalive(ngx_conf_t *cf, ngx_command_t *cmd,
Igor Sysoevaa828612005-02-09 14:31:07 +000064 void *conf);
Igor Sysoev899b44e2005-05-12 14:58:06 +000065static char *ngx_http_core_internal(ngx_conf_t *cf, ngx_command_t *cmd,
66 void *conf);
Igor Sysoevb5faed22003-10-29 08:30:44 +000067
Igor Sysoev805d9db2005-02-03 19:33:37 +000068static char *ngx_http_core_lowat_check(ngx_conf_t *cf, void *post, void *data);
69
70static ngx_conf_post_t ngx_http_core_lowat_post =
71 { ngx_http_core_lowat_check };
Igor Sysoevb5faed22003-10-29 08:30:44 +000072
Igor Sysoev8290d282006-02-03 12:58:48 +000073static ngx_conf_deprecated_t ngx_conf_deprecated_optimize_host_names = {
74 ngx_conf_deprecated, "optimize_host_names", "optimize_server_names"
75};
76
Igor Sysoev4e9393a2003-01-09 05:36:00 +000077
78static ngx_command_t ngx_http_core_commands[] = {
79
Igor Sysoevffe71442006-02-08 15:33:12 +000080 { ngx_string("variables_hash_max_size"),
81 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
82 ngx_conf_set_num_slot,
83 NGX_HTTP_MAIN_CONF_OFFSET,
84 offsetof(ngx_http_core_main_conf_t, variables_hash_max_size),
85 NULL },
86
87 { ngx_string("variables_hash_bucket_size"),
88 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
89 ngx_conf_set_num_slot,
90 NGX_HTTP_MAIN_CONF_OFFSET,
91 offsetof(ngx_http_core_main_conf_t, variables_hash_bucket_size),
92 NULL },
93
Igor Sysoev305a9d82005-12-26 17:07:48 +000094 { ngx_string("server_names_hash_max_size"),
Igor Sysoevb1dfe472004-12-21 12:30:30 +000095 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
96 ngx_conf_set_num_slot,
97 NGX_HTTP_MAIN_CONF_OFFSET,
Igor Sysoev305a9d82005-12-26 17:07:48 +000098 offsetof(ngx_http_core_main_conf_t, server_names_hash_max_size),
Igor Sysoevb1dfe472004-12-21 12:30:30 +000099 NULL },
100
Igor Sysoev305a9d82005-12-26 17:07:48 +0000101 { ngx_string("server_names_hash_bucket_size"),
Igor Sysoevb1dfe472004-12-21 12:30:30 +0000102 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
103 ngx_conf_set_num_slot,
104 NGX_HTTP_MAIN_CONF_OFFSET,
Igor Sysoev305a9d82005-12-26 17:07:48 +0000105 offsetof(ngx_http_core_main_conf_t, server_names_hash_bucket_size),
Igor Sysoevb1dfe472004-12-21 12:30:30 +0000106 NULL },
107
Igor Sysoev865c1502003-11-30 20:03:18 +0000108 { ngx_string("server"),
Igor Sysoev6f134cc2006-05-23 14:54:58 +0000109 NGX_HTTP_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_MULTI|NGX_CONF_NOARGS,
Igor Sysoev805d9db2005-02-03 19:33:37 +0000110 ngx_http_core_server,
Igor Sysoev865c1502003-11-30 20:03:18 +0000111 0,
112 0,
113 NULL },
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000114
Igor Sysoev865c1502003-11-30 20:03:18 +0000115 { ngx_string("connection_pool_size"),
116 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
117 ngx_conf_set_size_slot,
118 NGX_HTTP_SRV_CONF_OFFSET,
119 offsetof(ngx_http_core_srv_conf_t, connection_pool_size),
120 NULL },
Igor Sysoev6a644c62003-03-04 06:33:48 +0000121
Igor Sysoev865c1502003-11-30 20:03:18 +0000122 { ngx_string("request_pool_size"),
123 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
124 ngx_conf_set_size_slot,
125 NGX_HTTP_SRV_CONF_OFFSET,
126 offsetof(ngx_http_core_srv_conf_t, request_pool_size),
127 NULL },
Igor Sysoev187fcd82003-05-23 11:53:01 +0000128
Igor Sysoev865c1502003-11-30 20:03:18 +0000129 { ngx_string("client_header_timeout"),
130 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
131 ngx_conf_set_msec_slot,
132 NGX_HTTP_SRV_CONF_OFFSET,
133 offsetof(ngx_http_core_srv_conf_t, client_header_timeout),
134 NULL },
Igor Sysoev6a644c62003-03-04 06:33:48 +0000135
Igor Sysoev865c1502003-11-30 20:03:18 +0000136 { ngx_string("client_header_buffer_size"),
137 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
138 ngx_conf_set_size_slot,
139 NGX_HTTP_SRV_CONF_OFFSET,
140 offsetof(ngx_http_core_srv_conf_t, client_header_buffer_size),
141 NULL },
Igor Sysoev6a644c62003-03-04 06:33:48 +0000142
Igor Sysoevf7abd722004-09-23 06:32:00 +0000143 { ngx_string("large_client_header_buffers"),
Igor Sysoev85080d02004-09-22 16:18:21 +0000144 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE2,
145 ngx_conf_set_bufs_slot,
146 NGX_HTTP_SRV_CONF_OFFSET,
Igor Sysoevf7abd722004-09-23 06:32:00 +0000147 offsetof(ngx_http_core_srv_conf_t, large_client_header_buffers),
Igor Sysoev865c1502003-11-30 20:03:18 +0000148 NULL },
Igor Sysoev6a644c62003-03-04 06:33:48 +0000149
Igor Sysoev8290d282006-02-03 12:58:48 +0000150 { ngx_string("optimize_server_names"),
151 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_FLAG,
152 ngx_conf_set_flag_slot,
153 NGX_HTTP_SRV_CONF_OFFSET,
154 offsetof(ngx_http_core_srv_conf_t, optimize_server_names),
155 NULL },
156
Igor Sysoev34303462006-01-24 16:08:27 +0000157 { ngx_string("optimize_host_names"),
158 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_FLAG,
159 ngx_conf_set_flag_slot,
160 NGX_HTTP_SRV_CONF_OFFSET,
Igor Sysoev8290d282006-02-03 12:58:48 +0000161 offsetof(ngx_http_core_srv_conf_t, optimize_server_names),
162 &ngx_conf_deprecated_optimize_host_names },
Igor Sysoev34303462006-01-24 16:08:27 +0000163
Igor Sysoev3362b8d2005-05-14 18:42:03 +0000164 { ngx_string("ignore_invalid_headers"),
165 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_FLAG,
166 ngx_conf_set_flag_slot,
167 NGX_HTTP_SRV_CONF_OFFSET,
168 offsetof(ngx_http_core_srv_conf_t, ignore_invalid_headers),
169 NULL },
170
Igor Sysoev865c1502003-11-30 20:03:18 +0000171 { ngx_string("location"),
Igor Sysoev74a5ddb2004-07-18 19:11:20 +0000172 NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_BLOCK|NGX_CONF_TAKE12,
Igor Sysoev805d9db2005-02-03 19:33:37 +0000173 ngx_http_core_location,
Igor Sysoev865c1502003-11-30 20:03:18 +0000174 NGX_HTTP_SRV_CONF_OFFSET,
175 0,
176 NULL },
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000177
Igor Sysoev865c1502003-11-30 20:03:18 +0000178 { ngx_string("listen"),
Igor Sysoevb145b062005-06-15 18:33:41 +0000179 NGX_HTTP_SRV_CONF|NGX_CONF_1MORE,
Igor Sysoev805d9db2005-02-03 19:33:37 +0000180 ngx_http_core_listen,
Igor Sysoev865c1502003-11-30 20:03:18 +0000181 NGX_HTTP_SRV_CONF_OFFSET,
182 0,
183 NULL },
Igor Sysoeva19a85e2003-01-28 15:56:37 +0000184
Igor Sysoev865c1502003-11-30 20:03:18 +0000185 { ngx_string("server_name"),
186 NGX_HTTP_SRV_CONF|NGX_CONF_1MORE,
Igor Sysoev805d9db2005-02-03 19:33:37 +0000187 ngx_http_core_server_name,
Igor Sysoev865c1502003-11-30 20:03:18 +0000188 NGX_HTTP_SRV_CONF_OFFSET,
189 0,
190 NULL },
Igor Sysoev13933252003-05-29 13:02:09 +0000191
Igor Sysoev24025022005-12-16 15:07:08 +0000192 { ngx_string("types_hash_max_size"),
193 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
194 ngx_conf_set_num_slot,
195 NGX_HTTP_LOC_CONF_OFFSET,
196 offsetof(ngx_http_core_loc_conf_t, types_hash_max_size),
197 NULL },
198
199 { ngx_string("types_hash_bucket_size"),
200 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
201 ngx_conf_set_num_slot,
202 NGX_HTTP_LOC_CONF_OFFSET,
203 offsetof(ngx_http_core_loc_conf_t, types_hash_bucket_size),
204 NULL },
205
Igor Sysoev865c1502003-11-30 20:03:18 +0000206 { ngx_string("types"),
207 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF
208 |NGX_CONF_BLOCK|NGX_CONF_NOARGS,
Igor Sysoev805d9db2005-02-03 19:33:37 +0000209 ngx_http_core_types,
Igor Sysoev865c1502003-11-30 20:03:18 +0000210 NGX_HTTP_LOC_CONF_OFFSET,
211 0,
212 NULL },
Igor Sysoev79a80482003-05-14 17:13:13 +0000213
Igor Sysoev865c1502003-11-30 20:03:18 +0000214 { ngx_string("default_type"),
215 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
216 ngx_conf_set_str_slot,
217 NGX_HTTP_LOC_CONF_OFFSET,
218 offsetof(ngx_http_core_loc_conf_t, default_type),
219 NULL },
Igor Sysoev6253ca12003-05-27 12:18:54 +0000220
Igor Sysoev865c1502003-11-30 20:03:18 +0000221 { ngx_string("root"),
Igor Sysoev899b44e2005-05-12 14:58:06 +0000222 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
223 |NGX_CONF_TAKE1,
Igor Sysoev805d9db2005-02-03 19:33:37 +0000224 ngx_http_core_root,
Igor Sysoev865c1502003-11-30 20:03:18 +0000225 NGX_HTTP_LOC_CONF_OFFSET,
Igor Sysoev10a543a2004-03-16 07:10:12 +0000226 0,
227 NULL },
228
229 { ngx_string("alias"),
230 NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
Igor Sysoev805d9db2005-02-03 19:33:37 +0000231 ngx_http_core_root,
Igor Sysoev10a543a2004-03-16 07:10:12 +0000232 NGX_HTTP_LOC_CONF_OFFSET,
233 0,
Igor Sysoev865c1502003-11-30 20:03:18 +0000234 NULL },
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000235
Igor Sysoev94e32ce2006-04-07 14:08:04 +0000236 { ngx_string("limit_except"),
237 NGX_HTTP_LOC_CONF|NGX_CONF_BLOCK|NGX_CONF_1MORE,
238 ngx_http_core_limit_except,
239 NGX_HTTP_LOC_CONF_OFFSET,
240 0,
241 NULL },
242
Igor Sysoevae02c192004-03-19 05:25:53 +0000243 { ngx_string("client_max_body_size"),
244 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
Igor Sysoev1765f472006-07-07 16:33:19 +0000245 ngx_conf_set_off_slot,
Igor Sysoevae02c192004-03-19 05:25:53 +0000246 NGX_HTTP_LOC_CONF_OFFSET,
247 offsetof(ngx_http_core_loc_conf_t, client_max_body_size),
248 NULL },
249
Igor Sysoevdbb27762004-04-01 16:20:53 +0000250 { ngx_string("client_body_buffer_size"),
251 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
252 ngx_conf_set_size_slot,
253 NGX_HTTP_LOC_CONF_OFFSET,
254 offsetof(ngx_http_core_loc_conf_t, client_body_buffer_size),
255 NULL },
256
Igor Sysoev865c1502003-11-30 20:03:18 +0000257 { ngx_string("client_body_timeout"),
258 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
259 ngx_conf_set_msec_slot,
260 NGX_HTTP_LOC_CONF_OFFSET,
261 offsetof(ngx_http_core_loc_conf_t, client_body_timeout),
262 NULL },
Igor Sysoev2b0c76c2003-10-27 21:01:00 +0000263
Igor Sysoev02025fd2005-01-18 13:03:58 +0000264 { ngx_string("client_body_temp_path"),
265 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1234,
266 ngx_conf_set_path_slot,
267 NGX_HTTP_LOC_CONF_OFFSET,
268 offsetof(ngx_http_core_loc_conf_t, client_body_temp_path),
269 (void *) ngx_garbage_collector_temp_handler },
270
Igor Sysoev8a2b2fb2006-04-14 09:53:38 +0000271 { ngx_string("client_body_in_file_only"),
272 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
273 ngx_conf_set_flag_slot,
274 NGX_HTTP_LOC_CONF_OFFSET,
275 offsetof(ngx_http_core_loc_conf_t, client_body_in_file_only),
276 NULL },
277
Igor Sysoev865c1502003-11-30 20:03:18 +0000278 { ngx_string("sendfile"),
279 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
280 ngx_conf_set_flag_slot,
281 NGX_HTTP_LOC_CONF_OFFSET,
282 offsetof(ngx_http_core_loc_conf_t, sendfile),
283 NULL },
Igor Sysoev5bf3d252003-10-22 07:05:29 +0000284
Igor Sysoev3c3ca172004-01-05 20:55:48 +0000285 { ngx_string("tcp_nopush"),
286 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
287 ngx_conf_set_flag_slot,
288 NGX_HTTP_LOC_CONF_OFFSET,
289 offsetof(ngx_http_core_loc_conf_t, tcp_nopush),
290 NULL },
291
Igor Sysoev924bd792004-10-11 15:07:03 +0000292 { ngx_string("tcp_nodelay"),
293 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
294 ngx_conf_set_flag_slot,
295 NGX_HTTP_LOC_CONF_OFFSET,
296 offsetof(ngx_http_core_loc_conf_t, tcp_nodelay),
297 NULL },
298
Igor Sysoev865c1502003-11-30 20:03:18 +0000299 { ngx_string("send_timeout"),
300 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
301 ngx_conf_set_msec_slot,
302 NGX_HTTP_LOC_CONF_OFFSET,
303 offsetof(ngx_http_core_loc_conf_t, send_timeout),
304 NULL },
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000305
Igor Sysoev865c1502003-11-30 20:03:18 +0000306 { ngx_string("send_lowat"),
307 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
308 ngx_conf_set_size_slot,
309 NGX_HTTP_LOC_CONF_OFFSET,
310 offsetof(ngx_http_core_loc_conf_t, send_lowat),
Igor Sysoev805d9db2005-02-03 19:33:37 +0000311 &ngx_http_core_lowat_post },
Igor Sysoevb5faed22003-10-29 08:30:44 +0000312
Igor Sysoev7823cc32004-07-14 16:01:42 +0000313 { ngx_string("postpone_output"),
314 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
315 ngx_conf_set_size_slot,
316 NGX_HTTP_LOC_CONF_OFFSET,
317 offsetof(ngx_http_core_loc_conf_t, postpone_output),
318 NULL },
319
320 { ngx_string("limit_rate"),
Igor Sysoev805d9db2005-02-03 19:33:37 +0000321 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
322 |NGX_CONF_TAKE1,
Igor Sysoev7823cc32004-07-14 16:01:42 +0000323 ngx_conf_set_size_slot,
324 NGX_HTTP_LOC_CONF_OFFSET,
325 offsetof(ngx_http_core_loc_conf_t, limit_rate),
326 NULL },
327
Igor Sysoev865c1502003-11-30 20:03:18 +0000328 { ngx_string("keepalive_timeout"),
Igor Sysoev307c3ad2004-09-17 16:07:35 +0000329 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE12,
Igor Sysoev805d9db2005-02-03 19:33:37 +0000330 ngx_http_core_keepalive,
Igor Sysoev865c1502003-11-30 20:03:18 +0000331 NGX_HTTP_LOC_CONF_OFFSET,
Igor Sysoev307c3ad2004-09-17 16:07:35 +0000332 0,
Igor Sysoev865c1502003-11-30 20:03:18 +0000333 NULL },
Igor Sysoevfa73aac2003-05-21 13:28:21 +0000334
Igor Sysoev31eb8c02005-09-23 11:02:22 +0000335 { ngx_string("satisfy_any"),
336 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
337 ngx_conf_set_flag_slot,
338 NGX_HTTP_LOC_CONF_OFFSET,
339 offsetof(ngx_http_core_loc_conf_t, satisfy_any),
340 NULL },
341
Igor Sysoev899b44e2005-05-12 14:58:06 +0000342 { ngx_string("internal"),
343 NGX_HTTP_LOC_CONF|NGX_CONF_NOARGS,
344 ngx_http_core_internal,
345 NGX_HTTP_LOC_CONF_OFFSET,
346 0,
347 NULL },
348
Igor Sysoev865c1502003-11-30 20:03:18 +0000349 { ngx_string("lingering_time"),
350 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
351 ngx_conf_set_msec_slot,
352 NGX_HTTP_LOC_CONF_OFFSET,
353 offsetof(ngx_http_core_loc_conf_t, lingering_time),
354 NULL },
Igor Sysoevb7387572003-03-11 20:38:13 +0000355
Igor Sysoev865c1502003-11-30 20:03:18 +0000356 { ngx_string("lingering_timeout"),
357 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
358 ngx_conf_set_msec_slot,
359 NGX_HTTP_LOC_CONF_OFFSET,
360 offsetof(ngx_http_core_loc_conf_t, lingering_timeout),
361 NULL },
Igor Sysoevb7387572003-03-11 20:38:13 +0000362
Igor Sysoev0ab91b92004-06-06 19:49:18 +0000363 { ngx_string("reset_timedout_connection"),
364 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
365 ngx_conf_set_flag_slot,
366 NGX_HTTP_LOC_CONF_OFFSET,
367 offsetof(ngx_http_core_loc_conf_t, reset_timedout_connection),
368 NULL },
369
Igor Sysoev7b190b42005-06-07 15:56:31 +0000370 { ngx_string("port_in_redirect"),
371 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
372 ngx_conf_set_flag_slot,
373 NGX_HTTP_LOC_CONF_OFFSET,
374 offsetof(ngx_http_core_loc_conf_t, port_in_redirect),
375 NULL },
376
Igor Sysoev865c1502003-11-30 20:03:18 +0000377 { ngx_string("msie_padding"),
378 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
379 ngx_conf_set_flag_slot,
380 NGX_HTTP_LOC_CONF_OFFSET,
381 offsetof(ngx_http_core_loc_conf_t, msie_padding),
382 NULL },
Igor Sysoev12b4b002003-10-24 06:53:41 +0000383
Igor Sysoev5192b362005-07-08 14:34:20 +0000384 { ngx_string("log_not_found"),
385 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
386 ngx_conf_set_flag_slot,
387 NGX_HTTP_LOC_CONF_OFFSET,
388 offsetof(ngx_http_core_loc_conf_t, log_not_found),
389 NULL },
390
Igor Sysoev865c1502003-11-30 20:03:18 +0000391 { ngx_string("error_page"),
Igor Sysoev899b44e2005-05-12 14:58:06 +0000392 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
393 |NGX_CONF_2MORE,
Igor Sysoev805d9db2005-02-03 19:33:37 +0000394 ngx_http_core_error_page,
Igor Sysoev865c1502003-11-30 20:03:18 +0000395 NGX_HTTP_LOC_CONF_OFFSET,
396 0,
397 NULL },
Igor Sysoev74e95c22003-11-09 20:03:38 +0000398
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +0000399 { ngx_string("post_action"),
400 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
401 |NGX_CONF_TAKE1,
402 ngx_conf_set_str_slot,
403 NGX_HTTP_LOC_CONF_OFFSET,
404 offsetof(ngx_http_core_loc_conf_t, post_action),
405 NULL },
406
Igor Sysoev865c1502003-11-30 20:03:18 +0000407 { ngx_string("error_log"),
Igor Sysoev03420a62004-01-20 20:40:08 +0000408 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
Igor Sysoev805d9db2005-02-03 19:33:37 +0000409 ngx_http_core_error_log,
Igor Sysoev865c1502003-11-30 20:03:18 +0000410 NGX_HTTP_LOC_CONF_OFFSET,
411 0,
412 NULL },
Igor Sysoev890fc962003-07-20 21:15:59 +0000413
Igor Sysoev67f88e92004-03-12 16:57:08 +0000414#if (NGX_HTTP_CACHE)
415
Igor Sysoev865c1502003-11-30 20:03:18 +0000416 { ngx_string("open_file_cache"),
417 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE4,
418 ngx_http_set_cache_slot,
419 NGX_HTTP_LOC_CONF_OFFSET,
420 offsetof(ngx_http_core_loc_conf_t, open_files),
421 NULL },
422
Igor Sysoev67f88e92004-03-12 16:57:08 +0000423#endif
424
Igor Sysoev865c1502003-11-30 20:03:18 +0000425 ngx_null_command
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000426};
427
428
Igor Sysoev8f125582006-07-28 15:16:17 +0000429static ngx_http_module_t ngx_http_core_module_ctx = {
Igor Sysoev899b44e2005-05-12 14:58:06 +0000430 ngx_http_core_preconfiguration, /* preconfiguration */
Igor Sysoev09c684b2005-11-09 17:25:55 +0000431 NULL, /* postconfiguration */
Igor Sysoev78329332003-11-10 17:17:31 +0000432
Igor Sysoeva9830112003-05-19 16:39:14 +0000433 ngx_http_core_create_main_conf, /* create main configuration */
434 ngx_http_core_init_main_conf, /* init main configuration */
Igor Sysoevdc479b42003-03-20 16:09:44 +0000435
Igor Sysoeva9830112003-05-19 16:39:14 +0000436 ngx_http_core_create_srv_conf, /* create server configuration */
437 ngx_http_core_merge_srv_conf, /* merge server configuration */
438
439 ngx_http_core_create_loc_conf, /* create location configuration */
440 ngx_http_core_merge_loc_conf /* merge location configuration */
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000441};
442
443
444ngx_module_t ngx_http_core_module = {
Igor Sysoev899b44e2005-05-12 14:58:06 +0000445 NGX_MODULE_V1,
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000446 &ngx_http_core_module_ctx, /* module context */
447 ngx_http_core_commands, /* module directives */
Igor Sysoev6253ca12003-05-27 12:18:54 +0000448 NGX_HTTP_MODULE, /* module type */
Igor Sysoeve5733802005-09-08 14:36:09 +0000449 NULL, /* init master */
Igor Sysoev899b44e2005-05-12 14:58:06 +0000450 NULL, /* init module */
Igor Sysoeve5733802005-09-08 14:36:09 +0000451 NULL, /* init process */
452 NULL, /* init thread */
453 NULL, /* exit thread */
454 NULL, /* exit process */
455 NULL, /* exit master */
456 NGX_MODULE_V1_PADDING
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000457};
458
459
Igor Sysoevaa828612005-02-09 14:31:07 +0000460void
461ngx_http_handler(ngx_http_request_t *r)
Igor Sysoev6ddfbf02003-05-15 15:42:53 +0000462{
Igor Sysoeve5a222c2005-01-25 12:27:35 +0000463 r->connection->log->action = NULL;
Igor Sysoev6ddfbf02003-05-15 15:42:53 +0000464
465 r->connection->unexpected_eof = 0;
466
Igor Sysoevef316432006-08-16 13:09:33 +0000467 if (!r->internal) {
Igor Sysoev31eb8c02005-09-23 11:02:22 +0000468 switch (r->headers_in.connection_type) {
469 case 0:
470 if (r->http_version > NGX_HTTP_VERSION_10) {
471 r->keepalive = 1;
472 } else {
473 r->keepalive = 0;
474 }
475 break;
476
477 case NGX_HTTP_CONNECTION_CLOSE:
478 r->keepalive = 0;
479 break;
480
481 case NGX_HTTP_CONNECTION_KEEP_ALIVE:
Igor Sysoev419f9ac2003-10-21 16:49:56 +0000482 r->keepalive = 1;
Igor Sysoev31eb8c02005-09-23 11:02:22 +0000483 break;
484 }
485
486 if (r->keepalive && r->headers_in.msie && r->method == NGX_HTTP_POST) {
487
488 /*
Igor Sysoevcdf609a2006-04-17 19:55:41 +0000489 * MSIE may wait for some time if the response for
490 * the POST request is sent over the keepalive connection
Igor Sysoev31eb8c02005-09-23 11:02:22 +0000491 */
492
Igor Sysoev9760a132003-10-21 07:47:21 +0000493 r->keepalive = 0;
494 }
Igor Sysoev419f9ac2003-10-21 16:49:56 +0000495
Igor Sysoev31eb8c02005-09-23 11:02:22 +0000496 if (r->headers_in.content_length_n > 0) {
497 r->lingering_close = 1;
Igor Sysoev419f9ac2003-10-21 16:49:56 +0000498
Igor Sysoev31eb8c02005-09-23 11:02:22 +0000499 } else {
500 r->lingering_close = 0;
501 }
Igor Sysoev9760a132003-10-21 07:47:21 +0000502 }
503
Igor Sysoev899b44e2005-05-12 14:58:06 +0000504 r->write_event_handler = ngx_http_core_run_phases;
Igor Sysoev6ddfbf02003-05-15 15:42:53 +0000505
Igor Sysoevc04deca2005-03-28 14:43:02 +0000506 r->valid_unparsed_uri = 1;
Igor Sysoev899b44e2005-05-12 14:58:06 +0000507 r->valid_location = 1;
Igor Sysoev805d9db2005-02-03 19:33:37 +0000508 r->uri_changed = 1;
Igor Sysoevc04deca2005-03-28 14:43:02 +0000509
Igor Sysoev5fede1e2006-08-18 14:17:54 +0000510 r->phase = (!r->internal) ? NGX_HTTP_POST_READ_PHASE:
Igor Sysoev09c684b2005-11-09 17:25:55 +0000511 NGX_HTTP_SERVER_REWRITE_PHASE;
Igor Sysoev1ebfead2005-02-16 13:40:36 +0000512 r->phase_handler = 0;
Igor Sysoev805d9db2005-02-03 19:33:37 +0000513
514 ngx_http_core_run_phases(r);
Igor Sysoevb3e73d82003-10-10 15:10:50 +0000515}
Igor Sysoeve2a31542003-04-08 15:40:10 +0000516
517
Igor Sysoevaa828612005-02-09 14:31:07 +0000518static void
Igor Sysoevaa828612005-02-09 14:31:07 +0000519ngx_http_core_run_phases(ngx_http_request_t *r)
Igor Sysoevb3e73d82003-10-10 15:10:50 +0000520{
Igor Sysoev865c1502003-11-30 20:03:18 +0000521 ngx_int_t rc;
Igor Sysoevef809b82006-06-28 16:00:26 +0000522 ngx_str_t path;
Igor Sysoevb3e73d82003-10-10 15:10:50 +0000523 ngx_http_handler_pt *h;
Igor Sysoev865c1502003-11-30 20:03:18 +0000524 ngx_http_core_loc_conf_t *clcf;
Igor Sysoevb3e73d82003-10-10 15:10:50 +0000525 ngx_http_core_main_conf_t *cmcf;
526
Igor Sysoev899b44e2005-05-12 14:58:06 +0000527 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
528 "http phase handler");
529
Igor Sysoevb3e73d82003-10-10 15:10:50 +0000530 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
531
Igor Sysoevc31a9bb2005-11-26 10:11:11 +0000532 for (/* void */; r->phase < NGX_HTTP_LOG_PHASE; r->phase++) {
Igor Sysoevb3e73d82003-10-10 15:10:50 +0000533
Igor Sysoev1ebfead2005-02-16 13:40:36 +0000534 if (r->phase == NGX_HTTP_REWRITE_PHASE + 1 && r->uri_changed) {
Igor Sysoev805d9db2005-02-03 19:33:37 +0000535
536 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
537 "uri changes: %d", r->uri_changes);
538
539 /*
540 * gcc before 3.3 compiles the broken code for
541 * if (r->uri_changes-- == 0)
542 * if the r->uri_changes is defined as
543 * unsigned uri_changes:4
544 */
545
546 r->uri_changes--;
547
548 if (r->uri_changes == 0) {
549 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
Igor Sysoev6f134cc2006-05-23 14:54:58 +0000550 "rewrite or internal redirection cycle");
Igor Sysoev805d9db2005-02-03 19:33:37 +0000551 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
552 return;
553 }
554
Igor Sysoev1ebfead2005-02-16 13:40:36 +0000555 r->phase = NGX_HTTP_FIND_CONFIG_PHASE;
Igor Sysoev805d9db2005-02-03 19:33:37 +0000556 }
557
Igor Sysoevdf3254a2006-01-11 15:26:57 +0000558 if (r->phase == NGX_HTTP_ACCESS_PHASE && r != r->main) {
Igor Sysoev31eb8c02005-09-23 11:02:22 +0000559 continue;
560 }
561
Igor Sysoev865c1502003-11-30 20:03:18 +0000562 if (r->phase == NGX_HTTP_CONTENT_PHASE && r->content_handler) {
Igor Sysoev899b44e2005-05-12 14:58:06 +0000563 r->write_event_handler = ngx_http_request_empty_handler;
Igor Sysoev805d9db2005-02-03 19:33:37 +0000564 ngx_http_finalize_request(r, r->content_handler(r));
Igor Sysoev865c1502003-11-30 20:03:18 +0000565 return;
566 }
567
Igor Sysoevb3e73d82003-10-10 15:10:50 +0000568 h = cmcf->phases[r->phase].handlers.elts;
569 for (r->phase_handler = cmcf->phases[r->phase].handlers.nelts - 1;
570 r->phase_handler >= 0;
571 r->phase_handler--)
572 {
573 rc = h[r->phase_handler](r);
574
Igor Sysoev9760a132003-10-21 07:47:21 +0000575 if (rc == NGX_DONE) {
Igor Sysoev865c1502003-11-30 20:03:18 +0000576
577 /*
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +0000578 * we should never use r here because
Igor Sysoev31eb8c02005-09-23 11:02:22 +0000579 * it may point to already freed data
Igor Sysoev865c1502003-11-30 20:03:18 +0000580 */
581
Igor Sysoev9760a132003-10-21 07:47:21 +0000582 return;
583 }
584
Igor Sysoevb3e73d82003-10-10 15:10:50 +0000585 if (rc == NGX_DECLINED) {
586 continue;
587 }
588
Igor Sysoev31eb8c02005-09-23 11:02:22 +0000589 if (r->phase == NGX_HTTP_ACCESS_PHASE) {
590 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
591
592 if (clcf->satisfy_any) {
593
594 if (rc == NGX_OK) {
595 r->access_code = 0;
596
597 if (r->headers_out.www_authenticate) {
598 r->headers_out.www_authenticate->hash = 0;
599 }
600
601 break;
602 }
603
604 if (rc == NGX_HTTP_FORBIDDEN || rc == NGX_HTTP_UNAUTHORIZED)
605 {
606 r->access_code = rc;
607
608 continue;
609 }
610 }
611 }
612
Igor Sysoev3362b8d2005-05-14 18:42:03 +0000613 if (rc >= NGX_HTTP_SPECIAL_RESPONSE
614 || rc == NGX_HTTP_NO_CONTENT
615 || rc == NGX_ERROR)
616 {
Igor Sysoevb3e73d82003-10-10 15:10:50 +0000617 ngx_http_finalize_request(r, rc);
618 return;
619 }
620
Igor Sysoeve3466a42003-12-15 13:57:13 +0000621 if (r->phase == NGX_HTTP_CONTENT_PHASE) {
622 ngx_http_finalize_request(r, rc);
623 return;
624 }
625
626 if (rc == NGX_AGAIN) {
Igor Sysoev865c1502003-11-30 20:03:18 +0000627 return;
628 }
629
Igor Sysoevb3e73d82003-10-10 15:10:50 +0000630 if (rc == NGX_OK && cmcf->phases[r->phase].type == NGX_OK) {
631 break;
632 }
Igor Sysoev31eb8c02005-09-23 11:02:22 +0000633
634 }
635
636 if (r->phase == NGX_HTTP_ACCESS_PHASE && r->access_code) {
Igor Sysoev1765f472006-07-07 16:33:19 +0000637
638 if (r->access_code == NGX_HTTP_FORBIDDEN) {
639 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
640 "access forbidden by rule");
641 }
642
Igor Sysoev31eb8c02005-09-23 11:02:22 +0000643 ngx_http_finalize_request(r, r->access_code);
644 return;
Igor Sysoevb3e73d82003-10-10 15:10:50 +0000645 }
Igor Sysoevb3e73d82003-10-10 15:10:50 +0000646 }
647
Igor Sysoev805d9db2005-02-03 19:33:37 +0000648 /* no content handler was found */
Igor Sysoev865c1502003-11-30 20:03:18 +0000649
Igor Sysoev1ebfead2005-02-16 13:40:36 +0000650 if (r->uri.data[r->uri.len - 1] == '/' && !r->zero_in_uri) {
Igor Sysoev865c1502003-11-30 20:03:18 +0000651
Igor Sysoevef809b82006-06-28 16:00:26 +0000652 if (ngx_http_map_uri_to_path(r, &path, 0) != NULL) {
653 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
654 "directory index of \"%V\" is forbidden", &path);
655 }
Igor Sysoev865c1502003-11-30 20:03:18 +0000656
657 ngx_http_finalize_request(r, NGX_HTTP_FORBIDDEN);
Igor Sysoevb3e73d82003-10-10 15:10:50 +0000658 return;
659 }
660
Igor Sysoev865c1502003-11-30 20:03:18 +0000661 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "no handler found");
662
663 ngx_http_finalize_request(r, NGX_HTTP_NOT_FOUND);
Igor Sysoevb3e73d82003-10-10 15:10:50 +0000664}
665
666
Igor Sysoevaa828612005-02-09 14:31:07 +0000667ngx_int_t
668ngx_http_find_location_config(ngx_http_request_t *r)
Igor Sysoevb3e73d82003-10-10 15:10:50 +0000669{
Igor Sysoev74a5ddb2004-07-18 19:11:20 +0000670 ngx_int_t rc;
671 ngx_http_core_loc_conf_t *clcf;
672 ngx_http_core_srv_conf_t *cscf;
Igor Sysoeve2a31542003-04-08 15:40:10 +0000673
Igor Sysoev1ebfead2005-02-16 13:40:36 +0000674 r->content_handler = NULL;
675 r->uri_changed = 0;
676
Igor Sysoev6253ca12003-05-27 12:18:54 +0000677 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
Igor Sysoeve2a31542003-04-08 15:40:10 +0000678
Igor Sysoev805d9db2005-02-03 19:33:37 +0000679 rc = ngx_http_core_find_location(r, &cscf->locations, 0);
Igor Sysoeva8fa0a62003-11-25 20:44:56 +0000680
Igor Sysoev74a5ddb2004-07-18 19:11:20 +0000681 if (rc == NGX_HTTP_INTERNAL_SERVER_ERROR) {
682 return rc;
Igor Sysoeva8fa0a62003-11-25 20:44:56 +0000683 }
684
Igor Sysoev419f9ac2003-10-21 16:49:56 +0000685 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
686
Igor Sysoev899b44e2005-05-12 14:58:06 +0000687 if (!r->internal && clcf->internal) {
688 return NGX_HTTP_NOT_FOUND;
689 }
690
Igor Sysoeva2573672005-10-05 14:46:21 +0000691 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
692 "using configuration \"%s%V\"",
693 (clcf->noname ? "*" : (clcf->exact_match ? "=" : "")),
694 &clcf->name);
695
Igor Sysoevb85fd592005-08-23 15:36:54 +0000696 ngx_http_update_location_config(r);
Igor Sysoev89690bf2004-03-23 06:01:52 +0000697
698 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
Igor Sysoev1765f472006-07-07 16:33:19 +0000699 "http cl:%O max:%O",
Igor Sysoev1b735832004-11-11 14:07:14 +0000700 r->headers_in.content_length_n, clcf->client_max_body_size);
Igor Sysoev89690bf2004-03-23 06:01:52 +0000701
702 if (r->headers_in.content_length_n != -1
Igor Sysoev08e63d42006-08-14 15:09:38 +0000703 && !r->discard_body
Igor Sysoev89690bf2004-03-23 06:01:52 +0000704 && clcf->client_max_body_size
Igor Sysoev1765f472006-07-07 16:33:19 +0000705 && clcf->client_max_body_size < r->headers_in.content_length_n)
Igor Sysoev89690bf2004-03-23 06:01:52 +0000706 {
707 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
Igor Sysoev1765f472006-07-07 16:33:19 +0000708 "client intented to send too large body: %O bytes",
Igor Sysoev89690bf2004-03-23 06:01:52 +0000709 r->headers_in.content_length_n);
710
711 return NGX_HTTP_REQUEST_ENTITY_TOO_LARGE;
712 }
713
714
Igor Sysoev74a5ddb2004-07-18 19:11:20 +0000715 if (rc == NGX_HTTP_LOCATION_AUTO_REDIRECT) {
Igor Sysoevaab4d8c2004-09-06 18:45:00 +0000716 r->headers_out.location = ngx_list_push(&r->headers_out.headers);
717 if (r->headers_out.location == NULL) {
Igor Sysoev1b138ed2003-11-18 21:34:08 +0000718 return NGX_HTTP_INTERNAL_SERVER_ERROR;
719 }
720
Igor Sysoev899b44e2005-05-12 14:58:06 +0000721 /*
722 * we do not need to set the r->headers_out.location->hash and
723 * r->headers_out.location->key fields
724 */
725
Igor Sysoev74a5ddb2004-07-18 19:11:20 +0000726 r->headers_out.location->value = clcf->name;
Igor Sysoev1b138ed2003-11-18 21:34:08 +0000727
728 return NGX_HTTP_MOVED_PERMANENTLY;
729 }
730
Igor Sysoevb85fd592005-08-23 15:36:54 +0000731 return NGX_OK;
732}
733
734
735void
736ngx_http_update_location_config(ngx_http_request_t *r)
737{
738 ngx_http_core_loc_conf_t *clcf;
739
740 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
741
Igor Sysoev94e32ce2006-04-07 14:08:04 +0000742 if (r->method & clcf->limit_except) {
743 r->loc_conf = clcf->limit_except_loc_conf;
744 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
745 }
746
Igor Sysoevb0518172006-04-26 15:21:08 +0000747 if (r == r->main) {
748 r->connection->log->file = clcf->err_log->file;
749 if (!(r->connection->log->log_level & NGX_LOG_DEBUG_CONNECTION)) {
750 r->connection->log->log_level = clcf->err_log->log_level;
751 }
Igor Sysoevb85fd592005-08-23 15:36:54 +0000752 }
753
754 if ((ngx_io.flags & NGX_IO_SENDFILE) && clcf->sendfile) {
755 r->connection->sendfile = 1;
756
757 } else {
758 r->connection->sendfile = 0;
759 }
760
Igor Sysoev8a2b2fb2006-04-14 09:53:38 +0000761 if (clcf->client_body_in_file_only) {
762 r->request_body_in_file_only = 1;
763 r->request_body_in_persistent_file = 1;
Igor Sysoev7bdb7202006-04-19 15:30:56 +0000764 r->request_body_file_log_level = NGX_LOG_NOTICE;
765
766 } else {
767 r->request_body_file_log_level = NGX_LOG_WARN;
Igor Sysoev8a2b2fb2006-04-14 09:53:38 +0000768 }
769
Igor Sysoevb85fd592005-08-23 15:36:54 +0000770 if (r->keepalive && clcf->keepalive_timeout == 0) {
771 r->keepalive = 0;
772 }
773
774 if (!clcf->tcp_nopush) {
775 /* disable TCP_NOPUSH/TCP_CORK use */
776 r->connection->tcp_nopush = NGX_TCP_NOPUSH_DISABLED;
777 }
778
Igor Sysoevc2807ec2006-02-16 15:26:46 +0000779 if (r->limit_rate == 0) {
780 r->limit_rate = clcf->limit_rate;
781 }
Igor Sysoev5192b362005-07-08 14:34:20 +0000782
Igor Sysoev6253ca12003-05-27 12:18:54 +0000783 if (clcf->handler) {
Igor Sysoevb3e73d82003-10-10 15:10:50 +0000784 r->content_handler = clcf->handler;
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000785 }
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000786}
787
788
Igor Sysoevaa828612005-02-09 14:31:07 +0000789static ngx_int_t
790ngx_http_core_find_location(ngx_http_request_t *r,
791 ngx_array_t *locations, size_t len)
Igor Sysoev74a5ddb2004-07-18 19:11:20 +0000792{
793 ngx_int_t n, rc;
Igor Sysoevd43bee82004-11-20 19:52:20 +0000794 ngx_uint_t i, found, noregex;
Igor Sysoev74a5ddb2004-07-18 19:11:20 +0000795 ngx_http_core_loc_conf_t *clcf, **clcfp;
796
Igor Sysoeva2573672005-10-05 14:46:21 +0000797 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
798 "find location for \"%V\"", &r->uri);
Igor Sysoev74a5ddb2004-07-18 19:11:20 +0000799
800 found = 0;
Igor Sysoevd43bee82004-11-20 19:52:20 +0000801 noregex = 0;
Igor Sysoev74a5ddb2004-07-18 19:11:20 +0000802
803 clcfp = locations->elts;
804 for (i = 0; i < locations->nelts; i++) {
805
Igor Sysoevc0edbcc2004-10-21 15:34:38 +0000806#if (NGX_PCRE)
Igor Sysoev74a5ddb2004-07-18 19:11:20 +0000807 if (clcfp[i]->regex) {
808 break;
809 }
810#endif
811
Igor Sysoev805d9db2005-02-03 19:33:37 +0000812 if (clcfp[i]->noname) {
813 break;
814 }
815
Igor Sysoev74a5ddb2004-07-18 19:11:20 +0000816 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
Igor Sysoev1b735832004-11-11 14:07:14 +0000817 "find location: %s\"%V\"",
818 clcfp[i]->exact_match ? "= " : "", &clcfp[i]->name);
Igor Sysoev74a5ddb2004-07-18 19:11:20 +0000819
820 if (clcfp[i]->auto_redirect
821 && r->uri.len == clcfp[i]->name.len - 1
822 && ngx_strncmp(r->uri.data, clcfp[i]->name.data,
823 clcfp[i]->name.len - 1) == 0)
824 {
825 /* the locations are lexicographically sorted */
826
827 r->loc_conf = clcfp[i]->loc_conf;
828
829 return NGX_HTTP_LOCATION_AUTO_REDIRECT;
830 }
831
832 if (r->uri.len < clcfp[i]->name.len) {
833 continue;
834 }
835
836 n = ngx_strncmp(r->uri.data, clcfp[i]->name.data, clcfp[i]->name.len);
837
838 if (n < 0) {
839 /* the locations are lexicographically sorted */
840 break;
841 }
842
843 if (n == 0) {
Igor Sysoev805d9db2005-02-03 19:33:37 +0000844 if (clcfp[i]->exact_match) {
845
846 if (r->uri.len == clcfp[i]->name.len) {
847 r->loc_conf = clcfp[i]->loc_conf;
848 return NGX_HTTP_LOCATION_EXACT;
849 }
850
851 continue;
Igor Sysoevea521232004-07-26 16:21:18 +0000852 }
853
Igor Sysoev71057632004-08-30 19:24:51 +0000854 if (len > clcfp[i]->name.len) {
Igor Sysoev74a5ddb2004-07-18 19:11:20 +0000855 /* the previous match is longer */
856 break;
857 }
858
859 r->loc_conf = clcfp[i]->loc_conf;
Igor Sysoevd43bee82004-11-20 19:52:20 +0000860 noregex = clcfp[i]->noregex;
Igor Sysoev74a5ddb2004-07-18 19:11:20 +0000861 found = 1;
862 }
863 }
864
865 if (found) {
866 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
867
868 if (clcf->locations.nelts) {
Igor Sysoev805d9db2005-02-03 19:33:37 +0000869 rc = ngx_http_core_find_location(r, &clcf->locations, len);
Igor Sysoev74a5ddb2004-07-18 19:11:20 +0000870
871 if (rc != NGX_OK) {
872 return rc;
873 }
874 }
875 }
876
Igor Sysoevc0edbcc2004-10-21 15:34:38 +0000877#if (NGX_PCRE)
Igor Sysoev74a5ddb2004-07-18 19:11:20 +0000878
Igor Sysoevd43bee82004-11-20 19:52:20 +0000879 if (noregex) {
880 return NGX_HTTP_LOCATION_NOREGEX;
881 }
882
Igor Sysoev74a5ddb2004-07-18 19:11:20 +0000883 /* regex matches */
884
885 for (/* void */; i < locations->nelts; i++) {
886
887 if (!clcfp[i]->regex) {
888 continue;
889 }
890
Igor Sysoev805d9db2005-02-03 19:33:37 +0000891 if (clcfp[i]->noname) {
892 break;
893 }
894
Igor Sysoev74a5ddb2004-07-18 19:11:20 +0000895 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
Igor Sysoev1b735832004-11-11 14:07:14 +0000896 "find location: ~ \"%V\"", &clcfp[i]->name);
Igor Sysoev74a5ddb2004-07-18 19:11:20 +0000897
898 n = ngx_regex_exec(clcfp[i]->regex, &r->uri, NULL, 0);
899
Igor Sysoev3259e852005-01-19 13:10:56 +0000900 if (n == NGX_REGEX_NO_MATCHED) {
Igor Sysoev74a5ddb2004-07-18 19:11:20 +0000901 continue;
902 }
903
904 if (n < 0) {
905 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
906 ngx_regex_exec_n
Igor Sysoev1b735832004-11-11 14:07:14 +0000907 " failed: %d on \"%V\" using \"%V\"",
908 n, &r->uri, &clcfp[i]->name);
Igor Sysoev74a5ddb2004-07-18 19:11:20 +0000909 return NGX_HTTP_INTERNAL_SERVER_ERROR;
910 }
911
912 /* match */
913
914 r->loc_conf = clcfp[i]->loc_conf;
915
916 return NGX_HTTP_LOCATION_REGEX;
917 }
918
Igor Sysoevc0edbcc2004-10-21 15:34:38 +0000919#endif /* NGX_PCRE */
Igor Sysoev74a5ddb2004-07-18 19:11:20 +0000920
921 return NGX_OK;
922}
923
924
Igor Sysoevaa828612005-02-09 14:31:07 +0000925ngx_int_t
926ngx_http_set_content_type(ngx_http_request_t *r)
Igor Sysoev865c1502003-11-30 20:03:18 +0000927{
Igor Sysoev805d9db2005-02-03 19:33:37 +0000928 u_char c, *p, *exten;
Igor Sysoev24025022005-12-16 15:07:08 +0000929 ngx_str_t *type;
Igor Sysoev3338cfd2006-05-11 14:43:47 +0000930 ngx_uint_t i, hash;
Igor Sysoev865c1502003-11-30 20:03:18 +0000931 ngx_http_core_loc_conf_t *clcf;
932
Igor Sysoev08e63d42006-08-14 15:09:38 +0000933 if (r->headers_out.content_type.len) {
934 return NGX_OK;
935 }
936
Igor Sysoev865c1502003-11-30 20:03:18 +0000937 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
938
939 if (r->exten.len) {
Igor Sysoev805d9db2005-02-03 19:33:37 +0000940
Igor Sysoev3338cfd2006-05-11 14:43:47 +0000941 hash = 0;
Igor Sysoev805d9db2005-02-03 19:33:37 +0000942
Igor Sysoev3338cfd2006-05-11 14:43:47 +0000943 for (i = 0; i < r->exten.len; i++) {
944 c = r->exten.data[i];
945
946 if (c >= 'A' && c <= 'Z') {
947
Igor Sysoevc1571722005-03-19 12:38:37 +0000948 p = ngx_palloc(r->pool, r->exten.len);
949 if (p == NULL) {
Igor Sysoev805d9db2005-02-03 19:33:37 +0000950 return NGX_HTTP_INTERNAL_SERVER_ERROR;
951 }
952
Igor Sysoev3338cfd2006-05-11 14:43:47 +0000953 hash = 0;
Igor Sysoev805d9db2005-02-03 19:33:37 +0000954 exten = p;
955
956 for (i = 0; i < r->exten.len; i++) {
Igor Sysoev3338cfd2006-05-11 14:43:47 +0000957 c = ngx_tolower(r->exten.data[i]);
958 hash = ngx_hash(hash, c);
959 *p++ = c;
Igor Sysoev805d9db2005-02-03 19:33:37 +0000960 }
961
962 r->exten.data = exten;
Igor Sysoev3338cfd2006-05-11 14:43:47 +0000963
964 break;
Igor Sysoev805d9db2005-02-03 19:33:37 +0000965 }
966
Igor Sysoev3338cfd2006-05-11 14:43:47 +0000967 hash = ngx_hash(hash, c);
Igor Sysoev805d9db2005-02-03 19:33:37 +0000968 }
969
Igor Sysoev3338cfd2006-05-11 14:43:47 +0000970 type = ngx_hash_find(&clcf->types_hash, hash,
Igor Sysoev24025022005-12-16 15:07:08 +0000971 r->exten.data, r->exten.len);
Igor Sysoev865c1502003-11-30 20:03:18 +0000972
Igor Sysoev24025022005-12-16 15:07:08 +0000973 if (type) {
Igor Sysoevef809b82006-06-28 16:00:26 +0000974 r->headers_out.content_type_len = type->len;
Igor Sysoev24025022005-12-16 15:07:08 +0000975 r->headers_out.content_type = *type;
Igor Sysoevef809b82006-06-28 16:00:26 +0000976
Igor Sysoev24025022005-12-16 15:07:08 +0000977 return NGX_OK;
Igor Sysoev865c1502003-11-30 20:03:18 +0000978 }
979 }
980
Igor Sysoevef809b82006-06-28 16:00:26 +0000981 r->headers_out.content_type_len = clcf->default_type.len;
Igor Sysoev24025022005-12-16 15:07:08 +0000982 r->headers_out.content_type = clcf->default_type;
Igor Sysoev865c1502003-11-30 20:03:18 +0000983
984 return NGX_OK;
985}
986
987
Igor Sysoevaa828612005-02-09 14:31:07 +0000988ngx_int_t
Igor Sysoevaa828612005-02-09 14:31:07 +0000989ngx_http_set_exten(ngx_http_request_t *r)
Igor Sysoev3b30a902003-12-25 20:26:58 +0000990{
991 ngx_int_t i;
992
993 r->exten.len = 0;
994 r->exten.data = NULL;
995
996 for (i = r->uri.len - 1; i > 1; i--) {
997 if (r->uri.data[i] == '.' && r->uri.data[i - 1] != '/') {
Igor Sysoev3338cfd2006-05-11 14:43:47 +0000998
Igor Sysoev3b30a902003-12-25 20:26:58 +0000999 r->exten.len = r->uri.len - i - 1;
Igor Sysoev3338cfd2006-05-11 14:43:47 +00001000 r->exten.data = &r->uri.data[i + 1];
Igor Sysoev3b30a902003-12-25 20:26:58 +00001001
1002 break;
1003
1004 } else if (r->uri.data[i] == '/') {
1005 break;
1006 }
1007 }
1008
1009 return NGX_OK;
1010}
1011
1012
Igor Sysoevaa828612005-02-09 14:31:07 +00001013ngx_int_t
Igor Sysoev208eed22005-10-07 13:30:52 +00001014ngx_http_send_header(ngx_http_request_t *r)
1015{
1016 if (r->err_status) {
1017 r->headers_out.status = r->err_status;
1018 r->headers_out.status_line.len = 0;
1019 }
1020
1021 return ngx_http_top_header_filter(r);
1022}
1023
1024
1025ngx_int_t
1026ngx_http_output_filter(ngx_http_request_t *r, ngx_chain_t *in)
1027{
1028 ngx_int_t rc;
1029
Igor Sysoevd3283ff2005-12-05 13:18:09 +00001030 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1031 "http output filter \"%V?%V\"", &r->uri, &r->args);
Igor Sysoev208eed22005-10-07 13:30:52 +00001032
1033 rc = ngx_http_top_body_filter(r, in);
1034
1035 if (rc == NGX_ERROR) {
1036 /* NGX_ERROR may be returned by any filter */
Igor Sysoevd3283ff2005-12-05 13:18:09 +00001037 r->connection->error = 1;
Igor Sysoev208eed22005-10-07 13:30:52 +00001038 }
1039
1040 return rc;
1041}
1042
1043
1044u_char *
1045ngx_http_map_uri_to_path(ngx_http_request_t *r, ngx_str_t *path,
1046 size_t reserved)
1047{
Igor Sysoev8fea8852006-03-15 09:53:04 +00001048 u_char *last;
1049 size_t alias;
1050 ngx_http_core_loc_conf_t *clcf;
Igor Sysoev208eed22005-10-07 13:30:52 +00001051
1052 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
1053
1054 alias = clcf->alias ? clcf->name.len : 0;
1055
Igor Sysoev34303462006-01-24 16:08:27 +00001056 if (alias && !r->valid_location) {
1057 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
1058 "\"alias\" could not be used in location \"%V\" "
1059 "where URI was rewritten", &clcf->name);
1060 return NULL;
1061 }
1062
Igor Sysoev8fea8852006-03-15 09:53:04 +00001063 reserved += r->uri.len - alias + 1;
1064
Igor Sysoev3ca233e2005-12-28 14:23:52 +00001065 if (clcf->root_lengths == NULL) {
Igor Sysoev208eed22005-10-07 13:30:52 +00001066
Igor Sysoev3ca233e2005-12-28 14:23:52 +00001067 r->root_length = clcf->root.len;
1068
Igor Sysoev8fea8852006-03-15 09:53:04 +00001069 path->len = clcf->root.len + reserved;
Igor Sysoev3ca233e2005-12-28 14:23:52 +00001070
1071 path->data = ngx_palloc(r->pool, path->len);
1072 if (path->data == NULL) {
1073 return NULL;
1074 }
1075
1076 last = ngx_copy(path->data, clcf->root.data, clcf->root.len);
Igor Sysoev3ca233e2005-12-28 14:23:52 +00001077
Igor Sysoev8fea8852006-03-15 09:53:04 +00001078 } else {
Igor Sysoev8f125582006-07-28 15:16:17 +00001079 if (ngx_http_script_run(r, path, clcf->root_lengths->elts, reserved,
Igor Sysoevc55a1042006-08-09 19:59:45 +00001080 clcf->root_values->elts)
Igor Sysoev8f125582006-07-28 15:16:17 +00001081 == NULL)
1082 {
1083 return NULL;
1084 }
1085
1086 if (ngx_conf_full_name((ngx_cycle_t *) ngx_cycle, path) == NGX_ERROR) {
Igor Sysoev8fea8852006-03-15 09:53:04 +00001087 return NULL;
1088 }
1089
1090 r->root_length = path->len - reserved;
Igor Sysoev8f125582006-07-28 15:16:17 +00001091 last = path->data + r->root_length;
Igor Sysoev3ca233e2005-12-28 14:23:52 +00001092 }
1093
Igor Sysoev8fea8852006-03-15 09:53:04 +00001094 last = ngx_cpystrn(last, r->uri.data + alias, r->uri.len - alias + 1);
Igor Sysoev208eed22005-10-07 13:30:52 +00001095
1096 return last;
1097}
1098
1099
1100ngx_int_t
Igor Sysoevceb99292005-09-06 16:09:32 +00001101ngx_http_auth_basic_user(ngx_http_request_t *r)
1102{
1103 ngx_str_t auth, encoded;
1104 ngx_uint_t len;
1105
1106 if (r->headers_in.user.len == 0 && r->headers_in.user.data != NULL) {
1107 return NGX_DECLINED;
1108 }
1109
1110 if (r->headers_in.authorization == NULL) {
1111 r->headers_in.user.data = (u_char *) "";
1112 return NGX_DECLINED;
1113 }
1114
1115 encoded = r->headers_in.authorization->value;
1116
1117 if (encoded.len < sizeof("Basic ") - 1
1118 || ngx_strncasecmp(encoded.data, "Basic ", sizeof("Basic ") - 1) != 0)
1119 {
1120 r->headers_in.user.data = (u_char *) "";
1121 return NGX_DECLINED;
1122 }
1123
1124 encoded.len -= sizeof("Basic ") - 1;
1125 encoded.data += sizeof("Basic ") - 1;
1126
1127 while (encoded.len && encoded.data[0] == ' ') {
1128 encoded.len--;
1129 encoded.data++;
1130 }
1131
1132 if (encoded.len == 0) {
1133 r->headers_in.user.data = (u_char *) "";
1134 return NGX_DECLINED;
1135 }
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +00001136
Igor Sysoevceb99292005-09-06 16:09:32 +00001137 auth.len = ngx_base64_decoded_length(encoded.len);
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +00001138 auth.data = ngx_palloc(r->pool, auth.len + 1);
Igor Sysoevceb99292005-09-06 16:09:32 +00001139 if (auth.data == NULL) {
1140 return NGX_ERROR;
1141 }
1142
1143 if (ngx_decode_base64(&auth, &encoded) != NGX_OK) {
1144 r->headers_in.user.data = (u_char *) "";
1145 return NGX_DECLINED;
1146 }
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +00001147
Igor Sysoevceb99292005-09-06 16:09:32 +00001148 auth.data[auth.len] = '\0';
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +00001149
1150 for (len = 0; len < auth.len; len++) {
Igor Sysoevceb99292005-09-06 16:09:32 +00001151 if (auth.data[len] == ':') {
1152 break;
1153 }
1154 }
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +00001155
Igor Sysoev09c684b2005-11-09 17:25:55 +00001156 if (len == 0 || len == auth.len) {
Igor Sysoevceb99292005-09-06 16:09:32 +00001157 r->headers_in.user.data = (u_char *) "";
1158 return NGX_DECLINED;
1159 }
1160
1161 r->headers_in.user.len = len;
1162 r->headers_in.user.data = auth.data;
1163 r->headers_in.passwd.len = auth.len - len - 1;
1164 r->headers_in.passwd.data = &auth.data[len + 1];
1165
1166 return NGX_OK;
1167}
1168
1169
1170ngx_int_t
Igor Sysoev899b44e2005-05-12 14:58:06 +00001171ngx_http_subrequest(ngx_http_request_t *r,
Igor Sysoev8f125582006-07-28 15:16:17 +00001172 ngx_str_t *uri, ngx_str_t *args, ngx_chain_t *out, ngx_uint_t flags)
Igor Sysoev899b44e2005-05-12 14:58:06 +00001173{
Igor Sysoevd3283ff2005-12-05 13:18:09 +00001174 ngx_connection_t *c;
Igor Sysoev899b44e2005-05-12 14:58:06 +00001175 ngx_http_request_t *sr;
Igor Sysoevbb28b6d2006-07-11 13:20:19 +00001176 ngx_http_log_ctx_t *ctx;
Igor Sysoev899b44e2005-05-12 14:58:06 +00001177 ngx_http_core_srv_conf_t *cscf;
1178 ngx_http_postponed_request_t *pr, *p;
1179
Igor Sysoevef809b82006-06-28 16:00:26 +00001180 r->main->subrequests--;
1181
1182 if (r->main->subrequests == 0) {
1183 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
1184 "subrequests cycle");
1185 return NGX_ERROR;
1186 }
1187
Igor Sysoev899b44e2005-05-12 14:58:06 +00001188 sr = ngx_pcalloc(r->pool, sizeof(ngx_http_request_t));
1189 if (sr == NULL) {
Igor Sysoevac72bd12006-05-04 15:32:46 +00001190 return NGX_ERROR;
Igor Sysoev899b44e2005-05-12 14:58:06 +00001191 }
1192
1193 sr->signature = NGX_HTTP_MODULE;
Igor Sysoevd3283ff2005-12-05 13:18:09 +00001194
1195 c = r->connection;
1196 sr->connection = c;
Igor Sysoev899b44e2005-05-12 14:58:06 +00001197
1198 sr->ctx = ngx_pcalloc(r->pool, sizeof(void *) * ngx_http_max_module);
1199 if (sr->ctx == NULL) {
Igor Sysoevac72bd12006-05-04 15:32:46 +00001200 return NGX_ERROR;
Igor Sysoev899b44e2005-05-12 14:58:06 +00001201 }
1202
1203 if (ngx_list_init(&sr->headers_out.headers, r->pool, 20,
Igor Sysoevc31a9bb2005-11-26 10:11:11 +00001204 sizeof(ngx_table_elt_t))
1205 == NGX_ERROR)
Igor Sysoev899b44e2005-05-12 14:58:06 +00001206 {
Igor Sysoevac72bd12006-05-04 15:32:46 +00001207 return NGX_ERROR;
Igor Sysoev899b44e2005-05-12 14:58:06 +00001208 }
1209
1210 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
1211 sr->main_conf = cscf->ctx->main_conf;
1212 sr->srv_conf = cscf->ctx->srv_conf;
1213 sr->loc_conf = cscf->ctx->loc_conf;
1214
1215 sr->pool = r->pool;
1216
1217 sr->headers_in = r->headers_in;
1218
1219 sr->start_time = ngx_time();
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +00001220
1221 ngx_http_clear_content_length(sr);
1222 ngx_http_clear_accept_ranges(sr);
1223 ngx_http_clear_last_modified(sr);
Igor Sysoev899b44e2005-05-12 14:58:06 +00001224
1225 sr->request_body = r->request_body;
1226
1227 sr->method = NGX_HTTP_GET;
1228 sr->http_version = r->http_version;
1229 sr->http_major = r->http_minor;
1230
1231 sr->request_line = r->request_line;
1232 sr->uri = *uri;
Igor Sysoev09c684b2005-11-09 17:25:55 +00001233
Igor Sysoev899b44e2005-05-12 14:58:06 +00001234 if (args) {
1235 sr->args = *args;
1236 }
Igor Sysoev09c684b2005-11-09 17:25:55 +00001237
Igor Sysoevd3283ff2005-12-05 13:18:09 +00001238 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
1239 "http subrequest \"%V?%V\"", uri, &sr->args);
1240
Igor Sysoev09c684b2005-11-09 17:25:55 +00001241 if (flags & NGX_HTTP_ZERO_IN_URI) {
1242 sr->zero_in_uri = 1;
1243 }
1244
Igor Sysoev899b44e2005-05-12 14:58:06 +00001245 sr->unparsed_uri = r->unparsed_uri;
1246 sr->method_name = r->method_name;
1247 sr->http_protocol = r->http_protocol;
1248
1249 if (ngx_http_set_exten(sr) != NGX_OK) {
Igor Sysoevac72bd12006-05-04 15:32:46 +00001250 return NGX_ERROR;
Igor Sysoev899b44e2005-05-12 14:58:06 +00001251 }
1252
Igor Sysoev8f125582006-07-28 15:16:17 +00001253 sr->out = out;
Igor Sysoevf6e1fe32005-10-04 10:38:53 +00001254 sr->main = r->main;
Igor Sysoev899b44e2005-05-12 14:58:06 +00001255 sr->parent = r;
1256 sr->read_event_handler = ngx_http_request_empty_handler;
1257 sr->write_event_handler = ngx_http_request_empty_handler;
1258
Igor Sysoevd3283ff2005-12-05 13:18:09 +00001259 if (c->data == r) {
1260 c->data = sr;
Igor Sysoev899b44e2005-05-12 14:58:06 +00001261 }
1262
1263 sr->in_addr = r->in_addr;
1264 sr->port = r->port;
1265 sr->port_text = r->port_text;
1266 sr->server_name = r->server_name;
1267
1268 sr->variables = r->variables;
1269
1270 sr->log_handler = r->log_handler;
1271
1272 pr = ngx_palloc(r->pool, sizeof(ngx_http_postponed_request_t));
1273 if (pr == NULL) {
Igor Sysoevac72bd12006-05-04 15:32:46 +00001274 return NGX_ERROR;
Igor Sysoev899b44e2005-05-12 14:58:06 +00001275 }
1276
1277 pr->request = sr;
1278 pr->out = NULL;
1279 pr->next = NULL;
1280
1281 if (r->postponed) {
1282 for (p = r->postponed; p->next; p = p->next) { /* void */ }
1283 p->next = pr;
1284
1285 } else {
1286 r->postponed = pr;
1287 }
1288
Igor Sysoevbb28b6d2006-07-11 13:20:19 +00001289 ctx = c->log->data;
1290 ctx->current_request = sr;
1291
Igor Sysoev899b44e2005-05-12 14:58:06 +00001292 sr->internal = 1;
Igor Sysoevdf3254a2006-01-11 15:26:57 +00001293 sr->fast_subrequest = 1;
Igor Sysoev899b44e2005-05-12 14:58:06 +00001294
Igor Sysoev31eb8c02005-09-23 11:02:22 +00001295 sr->discard_body = r->discard_body;
Igor Sysoevd52477f2005-05-16 13:53:20 +00001296 sr->main_filter_need_in_memory = r->main_filter_need_in_memory;
1297
Igor Sysoev6f134cc2006-05-23 14:54:58 +00001298 sr->uri_changes = NGX_HTTP_MAX_URI_CHANGES + 1;
1299
Igor Sysoev899b44e2005-05-12 14:58:06 +00001300 ngx_http_handler(sr);
1301
Igor Sysoevd3283ff2005-12-05 13:18:09 +00001302 if (!c->destroyed) {
1303 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
1304 "http subrequest done \"%V?%V\"", uri, &sr->args);
Igor Sysoevac72bd12006-05-04 15:32:46 +00001305
1306 if (sr->fast_subrequest) {
1307 sr->fast_subrequest = 0;
1308
1309 if (sr->done) {
1310 return NGX_OK;
1311 }
1312 }
1313
1314 return NGX_AGAIN;
Igor Sysoevd3283ff2005-12-05 13:18:09 +00001315 }
Igor Sysoev899b44e2005-05-12 14:58:06 +00001316
1317 return NGX_OK;
1318}
1319
1320
1321ngx_int_t
Igor Sysoevaa828612005-02-09 14:31:07 +00001322ngx_http_internal_redirect(ngx_http_request_t *r,
1323 ngx_str_t *uri, ngx_str_t *args)
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001324{
Igor Sysoevaa828612005-02-09 14:31:07 +00001325 ngx_http_core_srv_conf_t *cscf;
1326
Igor Sysoev5fede1e2006-08-18 14:17:54 +00001327 r->uri_changes--;
1328
1329 if (r->uri_changes == 0) {
1330 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
1331 "rewrite or internal redirection cycle");
1332 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
1333 return NGX_DONE;
1334 }
1335
Igor Sysoev1b735832004-11-11 14:07:14 +00001336 r->uri = *uri;
Igor Sysoev13933252003-05-29 13:02:09 +00001337
1338 if (args) {
Igor Sysoev1b735832004-11-11 14:07:14 +00001339 r->args = *args;
Igor Sysoev899b44e2005-05-12 14:58:06 +00001340
1341 } else {
1342 r->args.len = 0;
1343 r->args.data = NULL;
Igor Sysoev13933252003-05-29 13:02:09 +00001344 }
1345
Igor Sysoevd3283ff2005-12-05 13:18:09 +00001346 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1347 "internal redirect: \"%V?%V\"", uri, &r->args);
1348
Igor Sysoev3b30a902003-12-25 20:26:58 +00001349 if (ngx_http_set_exten(r) != NGX_OK) {
Igor Sysoev5fede1e2006-08-18 14:17:54 +00001350 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
1351 return NGX_DONE;
Igor Sysoev13933252003-05-29 13:02:09 +00001352 }
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001353
Igor Sysoevef316432006-08-16 13:09:33 +00001354 /* clear the modules contexts */
1355 ngx_memzero(r->ctx, sizeof(void *) * ngx_http_max_module);
Igor Sysoev0a280a32003-10-12 16:49:16 +00001356
Igor Sysoevaa828612005-02-09 14:31:07 +00001357 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
1358 r->loc_conf = cscf->ctx->loc_conf;
1359
Igor Sysoevb85fd592005-08-23 15:36:54 +00001360 ngx_http_update_location_config(r);
1361
Igor Sysoev899b44e2005-05-12 14:58:06 +00001362 r->internal = 1;
1363
Igor Sysoev79a80482003-05-14 17:13:13 +00001364 ngx_http_handler(r);
Igor Sysoev13933252003-05-29 13:02:09 +00001365
Igor Sysoev9760a132003-10-21 07:47:21 +00001366 return NGX_DONE;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001367}
1368
1369
Igor Sysoev9ac946b2005-10-24 15:09:41 +00001370ngx_http_cleanup_t *
1371ngx_http_cleanup_add(ngx_http_request_t *r, size_t size)
Igor Sysoev0a280a32003-10-12 16:49:16 +00001372{
Igor Sysoev9ac946b2005-10-24 15:09:41 +00001373 ngx_http_cleanup_t *cln;
Igor Sysoev0a280a32003-10-12 16:49:16 +00001374
Igor Sysoev9ac946b2005-10-24 15:09:41 +00001375 r = r->main;
1376
1377 cln = ngx_palloc(r->pool, sizeof(ngx_http_cleanup_t));
1378 if (cln == NULL) {
1379 return NULL;
Igor Sysoev0a280a32003-10-12 16:49:16 +00001380 }
1381
Igor Sysoev9ac946b2005-10-24 15:09:41 +00001382 if (size) {
1383 cln->data = ngx_palloc(r->pool, size);
1384 if (cln->data == NULL) {
1385 return NULL;
1386 }
Igor Sysoev0a280a32003-10-12 16:49:16 +00001387
Igor Sysoev9ac946b2005-10-24 15:09:41 +00001388 } else {
1389 cln->data = NULL;
1390 }
1391
1392 cln->handler = NULL;
1393 cln->next = r->cleanup;
1394
1395 r->cleanup = cln;
1396
1397 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1398 "http cleanup add: %p", cln);
1399
1400 return cln;
1401}
Igor Sysoev0a280a32003-10-12 16:49:16 +00001402
1403
Igor Sysoevaa828612005-02-09 14:31:07 +00001404static char *
1405ngx_http_core_server(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001406{
Igor Sysoevaa828612005-02-09 14:31:07 +00001407 char *rv;
1408 void *mconf;
Igor Sysoev7b190b42005-06-07 15:56:31 +00001409 ngx_uint_t m;
1410 ngx_conf_t pcf;
Igor Sysoevaa828612005-02-09 14:31:07 +00001411 ngx_http_module_t *module;
1412 ngx_http_conf_ctx_t *ctx, *http_ctx;
1413 ngx_http_core_srv_conf_t *cscf, **cscfp;
1414 ngx_http_core_main_conf_t *cmcf;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001415
Igor Sysoevc1571722005-03-19 12:38:37 +00001416 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t));
1417 if (ctx == NULL) {
Igor Sysoevaa828612005-02-09 14:31:07 +00001418 return NGX_CONF_ERROR;
1419 }
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001420
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001421 http_ctx = cf->ctx;
1422 ctx->main_conf = http_ctx->main_conf;
Igor Sysoevbb4ec5c2003-05-16 15:27:48 +00001423
Igor Sysoeva9830112003-05-19 16:39:14 +00001424 /* the server{}'s srv_conf */
Igor Sysoevbb4ec5c2003-05-16 15:27:48 +00001425
Igor Sysoevaa828612005-02-09 14:31:07 +00001426 ctx->srv_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
1427 if (ctx->srv_conf == NULL) {
1428 return NGX_CONF_ERROR;
1429 }
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001430
Igor Sysoeva9830112003-05-19 16:39:14 +00001431 /* the server{}'s loc_conf */
Igor Sysoevbb4ec5c2003-05-16 15:27:48 +00001432
Igor Sysoevaa828612005-02-09 14:31:07 +00001433 ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
1434 if (ctx->loc_conf == NULL) {
1435 return NGX_CONF_ERROR;
1436 }
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001437
Igor Sysoev1c13c662003-05-20 15:37:55 +00001438 for (m = 0; ngx_modules[m]; m++) {
Igor Sysoev6253ca12003-05-27 12:18:54 +00001439 if (ngx_modules[m]->type != NGX_HTTP_MODULE) {
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001440 continue;
1441 }
1442
Igor Sysoev6253ca12003-05-27 12:18:54 +00001443 module = ngx_modules[m]->ctx;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001444
1445 if (module->create_srv_conf) {
Igor Sysoevc1571722005-03-19 12:38:37 +00001446 mconf = module->create_srv_conf(cf);
1447 if (mconf == NULL) {
Igor Sysoevaa828612005-02-09 14:31:07 +00001448 return NGX_CONF_ERROR;
1449 }
1450
1451 ctx->srv_conf[ngx_modules[m]->ctx_index] = mconf;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001452 }
1453
1454 if (module->create_loc_conf) {
Igor Sysoevc1571722005-03-19 12:38:37 +00001455 mconf = module->create_loc_conf(cf);
1456 if (mconf == NULL) {
Igor Sysoevaa828612005-02-09 14:31:07 +00001457 return NGX_CONF_ERROR;
1458 }
1459
1460 ctx->loc_conf[ngx_modules[m]->ctx_index] = mconf;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001461 }
1462 }
1463
Igor Sysoevaa828612005-02-09 14:31:07 +00001464
1465 /* the server configuration context */
Igor Sysoeva9830112003-05-19 16:39:14 +00001466
Igor Sysoev6253ca12003-05-27 12:18:54 +00001467 cscf = ctx->srv_conf[ngx_http_core_module.ctx_index];
Igor Sysoeva9830112003-05-19 16:39:14 +00001468 cscf->ctx = ctx;
1469
Igor Sysoevaa828612005-02-09 14:31:07 +00001470
Igor Sysoev6253ca12003-05-27 12:18:54 +00001471 cmcf = ctx->main_conf[ngx_http_core_module.ctx_index];
Igor Sysoevaa828612005-02-09 14:31:07 +00001472
Igor Sysoevc1571722005-03-19 12:38:37 +00001473 cscfp = ngx_array_push(&cmcf->servers);
1474 if (cscfp == NULL) {
Igor Sysoevaa828612005-02-09 14:31:07 +00001475 return NGX_CONF_ERROR;
1476 }
1477
Igor Sysoeva9830112003-05-19 16:39:14 +00001478 *cscfp = cscf;
1479
Igor Sysoevaa828612005-02-09 14:31:07 +00001480
Igor Sysoeva9830112003-05-19 16:39:14 +00001481 /* parse inside server{} */
1482
Igor Sysoev7b190b42005-06-07 15:56:31 +00001483 pcf = *cf;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001484 cf->ctx = ctx;
Igor Sysoev79a80482003-05-14 17:13:13 +00001485 cf->cmd_type = NGX_HTTP_SRV_CONF;
Igor Sysoev805d9db2005-02-03 19:33:37 +00001486
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001487 rv = ngx_conf_parse(cf, NULL);
Igor Sysoev805d9db2005-02-03 19:33:37 +00001488
Igor Sysoev7b190b42005-06-07 15:56:31 +00001489 *cf = pcf;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001490
Igor Sysoev13933252003-05-29 13:02:09 +00001491 if (rv != NGX_CONF_OK) {
1492 return rv;
1493 }
1494
Igor Sysoevd9d0ca12003-11-21 06:30:49 +00001495 ngx_qsort(cscf->locations.elts, (size_t) cscf->locations.nelts,
Igor Sysoev805d9db2005-02-03 19:33:37 +00001496 sizeof(ngx_http_core_loc_conf_t *), ngx_http_core_cmp_locations);
Igor Sysoev13933252003-05-29 13:02:09 +00001497
Igor Sysoeva9830112003-05-19 16:39:14 +00001498 return rv;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001499}
1500
1501
Igor Sysoevaa828612005-02-09 14:31:07 +00001502static char *
1503ngx_http_core_location(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001504{
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001505 char *rv;
Igor Sysoeva8fa0a62003-11-25 20:44:56 +00001506 ngx_int_t m;
Igor Sysoevfc5a10a2004-03-09 19:47:07 +00001507 ngx_str_t *value;
Igor Sysoev805d9db2005-02-03 19:33:37 +00001508 ngx_conf_t save;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001509 ngx_http_module_t *module;
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001510 ngx_http_conf_ctx_t *ctx, *pctx;
Igor Sysoeva9830112003-05-19 16:39:14 +00001511 ngx_http_core_srv_conf_t *cscf;
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001512 ngx_http_core_loc_conf_t *clcf, *pclcf, **clcfp;
Igor Sysoevc0edbcc2004-10-21 15:34:38 +00001513#if (NGX_PCRE)
Igor Sysoevfc5a10a2004-03-09 19:47:07 +00001514 ngx_str_t err;
Igor Sysoev10a543a2004-03-16 07:10:12 +00001515 u_char errstr[NGX_MAX_CONF_ERRSTR];
Igor Sysoevfc5a10a2004-03-09 19:47:07 +00001516#endif
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001517
Igor Sysoevc1571722005-03-19 12:38:37 +00001518 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t));
1519 if (ctx == NULL) {
Igor Sysoeva8fa0a62003-11-25 20:44:56 +00001520 return NGX_CONF_ERROR;
1521 }
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001522
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001523 pctx = cf->ctx;
1524 ctx->main_conf = pctx->main_conf;
1525 ctx->srv_conf = pctx->srv_conf;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001526
Igor Sysoeva8fa0a62003-11-25 20:44:56 +00001527 ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
1528 if (ctx->loc_conf == NULL) {
1529 return NGX_CONF_ERROR;
1530 }
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001531
Igor Sysoev6253ca12003-05-27 12:18:54 +00001532 for (m = 0; ngx_modules[m]; m++) {
1533 if (ngx_modules[m]->type != NGX_HTTP_MODULE) {
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001534 continue;
1535 }
1536
Igor Sysoev6253ca12003-05-27 12:18:54 +00001537 module = ngx_modules[m]->ctx;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001538
1539 if (module->create_loc_conf) {
Igor Sysoeva8fa0a62003-11-25 20:44:56 +00001540 ctx->loc_conf[ngx_modules[m]->ctx_index] =
1541 module->create_loc_conf(cf);
1542 if (ctx->loc_conf[ngx_modules[m]->ctx_index] == NULL) {
1543 return NGX_CONF_ERROR;
1544 }
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001545 }
1546 }
1547
Igor Sysoev6253ca12003-05-27 12:18:54 +00001548 clcf = ctx->loc_conf[ngx_http_core_module.ctx_index];
Igor Sysoeva9830112003-05-19 16:39:14 +00001549 clcf->loc_conf = ctx->loc_conf;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001550
Igor Sysoev3b30a902003-12-25 20:26:58 +00001551 value = cf->args->elts;
Igor Sysoeva8fa0a62003-11-25 20:44:56 +00001552
1553 if (cf->args->nelts == 3) {
1554 if (value[1].len == 1 && value[1].data[0] == '=') {
Igor Sysoev2a3f4902004-11-11 20:58:09 +00001555 clcf->name = value[2];
Igor Sysoeva8fa0a62003-11-25 20:44:56 +00001556 clcf->exact_match = 1;
1557
Igor Sysoevd43bee82004-11-20 19:52:20 +00001558 } else if (value[1].len == 2
1559 && value[1].data[0] == '^'
1560 && value[1].data[1] == '~')
1561 {
1562 clcf->name = value[2];
1563 clcf->noregex = 1;
1564
Igor Sysoeva8fa0a62003-11-25 20:44:56 +00001565 } else if ((value[1].len == 1 && value[1].data[0] == '~')
1566 || (value[1].len == 2
1567 && value[1].data[0] == '~'
1568 && value[1].data[1] == '*'))
1569 {
Igor Sysoevc0edbcc2004-10-21 15:34:38 +00001570#if (NGX_PCRE)
Igor Sysoeva8fa0a62003-11-25 20:44:56 +00001571 err.len = NGX_MAX_CONF_ERRSTR;
1572 err.data = errstr;
1573
1574 clcf->regex = ngx_regex_compile(&value[2],
1575 value[1].len == 2 ? NGX_REGEX_CASELESS: 0,
1576 cf->pool, &err);
1577
1578 if (clcf->regex == NULL) {
1579 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", err.data);
1580 return NGX_CONF_ERROR;
1581 }
1582
Igor Sysoev3b30a902003-12-25 20:26:58 +00001583 clcf->name = value[2];
Igor Sysoevdc867cd2003-12-14 20:10:27 +00001584#else
1585 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
Igor Sysoev1b735832004-11-11 14:07:14 +00001586 "the using of the regex \"%V\" "
1587 "requires PCRE library", &value[2]);
Igor Sysoevdc867cd2003-12-14 20:10:27 +00001588 return NGX_CONF_ERROR;
1589#endif
Igor Sysoeva8fa0a62003-11-25 20:44:56 +00001590
1591 } else {
1592 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
Igor Sysoev1b735832004-11-11 14:07:14 +00001593 "invalid location modifier \"%V\"", &value[1]);
Igor Sysoeva8fa0a62003-11-25 20:44:56 +00001594 return NGX_CONF_ERROR;
1595 }
1596
1597 } else {
Igor Sysoev2a3f4902004-11-11 20:58:09 +00001598 clcf->name = value[1];
Igor Sysoeva8fa0a62003-11-25 20:44:56 +00001599 }
1600
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001601 pclcf = pctx->loc_conf[ngx_http_core_module.ctx_index];
1602
1603 if (pclcf->name.len == 0) {
1604 cscf = ctx->srv_conf[ngx_http_core_module.ctx_index];
Igor Sysoevc1571722005-03-19 12:38:37 +00001605
1606 clcfp = ngx_array_push(&cscf->locations);
1607 if (clcfp == NULL) {
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001608 return NGX_CONF_ERROR;
1609 }
1610
1611 } else {
Igor Sysoev805d9db2005-02-03 19:33:37 +00001612#if 0
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001613 clcf->prev_location = pclcf;
Igor Sysoev805d9db2005-02-03 19:33:37 +00001614#endif
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001615
1616 if (pclcf->exact_match) {
1617 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
Igor Sysoev1b735832004-11-11 14:07:14 +00001618 "location \"%V\" could not be inside "
1619 "the exact location \"%V\"",
1620 &clcf->name, &pclcf->name);
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001621 return NGX_CONF_ERROR;
1622 }
1623
Igor Sysoevc0edbcc2004-10-21 15:34:38 +00001624#if (NGX_PCRE)
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001625 if (clcf->regex == NULL
1626 && ngx_strncmp(clcf->name.data, pclcf->name.data, pclcf->name.len)
1627 != 0)
Igor Sysoevea521232004-07-26 16:21:18 +00001628#else
1629 if (ngx_strncmp(clcf->name.data, pclcf->name.data, pclcf->name.len)
1630 != 0)
1631#endif
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001632 {
1633 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
Igor Sysoev1b735832004-11-11 14:07:14 +00001634 "location \"%V\" is outside location \"%V\"",
1635 &clcf->name, &pclcf->name);
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001636 return NGX_CONF_ERROR;
1637 }
1638
1639 if (pclcf->locations.elts == NULL) {
Igor Sysoevc1571722005-03-19 12:38:37 +00001640 if (ngx_array_init(&pclcf->locations, cf->pool, 4, sizeof(void *))
1641 != NGX_OK)
1642 {
1643 return NGX_CONF_ERROR;
1644 }
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001645 }
1646
Igor Sysoevc1571722005-03-19 12:38:37 +00001647 clcfp = ngx_array_push(&pclcf->locations);
1648 if (clcfp == NULL) {
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001649 return NGX_CONF_ERROR;
1650 }
Igor Sysoeva8fa0a62003-11-25 20:44:56 +00001651 }
Igor Sysoev74a5ddb2004-07-18 19:11:20 +00001652
Igor Sysoeva9830112003-05-19 16:39:14 +00001653 *clcfp = clcf;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001654
Igor Sysoev805d9db2005-02-03 19:33:37 +00001655 save = *cf;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001656 cf->ctx = ctx;
Igor Sysoev79a80482003-05-14 17:13:13 +00001657 cf->cmd_type = NGX_HTTP_LOC_CONF;
Igor Sysoev805d9db2005-02-03 19:33:37 +00001658
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001659 rv = ngx_conf_parse(cf, NULL);
Igor Sysoev805d9db2005-02-03 19:33:37 +00001660
1661 *cf = save;
1662
1663 if (rv != NGX_CONF_OK) {
1664 return rv;
1665 }
1666
1667 ngx_qsort(clcf->locations.elts, (size_t) clcf->locations.nelts,
1668 sizeof(ngx_http_core_loc_conf_t *), ngx_http_core_cmp_locations);
Igor Sysoev79a80482003-05-14 17:13:13 +00001669
1670 return rv;
1671}
1672
1673
Igor Sysoev4d656dc2005-03-22 16:02:46 +00001674static int ngx_libc_cdecl
Igor Sysoevaa828612005-02-09 14:31:07 +00001675ngx_http_core_cmp_locations(const void *one, const void *two)
Igor Sysoev805d9db2005-02-03 19:33:37 +00001676{
1677 ngx_int_t rc;
1678 ngx_http_core_loc_conf_t *first, *second;
1679
1680 first = *(ngx_http_core_loc_conf_t **) one;
1681 second = *(ngx_http_core_loc_conf_t **) two;
1682
1683 if (first->noname && !second->noname) {
1684 /* shift no named locations to the end */
1685 return 1;
1686 }
1687
1688 if (!first->noname && second->noname) {
1689 /* shift no named locations to the end */
1690 return -1;
1691 }
1692
1693 if (first->noname || second->noname) {
1694 /* do not sort no named locations */
1695 return 0;
1696 }
1697
1698#if (NGX_PCRE)
1699
1700 if (first->regex && !second->regex) {
1701 /* shift the regex matches to the end */
1702 return 1;
1703 }
1704
1705 if (!first->regex && second->regex) {
1706 /* shift the regex matches to the end */
1707 return -1;
1708 }
1709
1710 if (first->regex || second->regex) {
1711 /* do not sort the regex matches */
1712 return 0;
1713 }
1714
1715#endif
1716
1717 rc = ngx_strcmp(first->name.data, second->name.data);
1718
1719 if (rc == 0 && second->exact_match) {
1720 /* an exact match must be before the same inclusive one */
1721 return 1;
1722 }
1723
1724 return (int) rc;
1725}
1726
1727
Igor Sysoevaa828612005-02-09 14:31:07 +00001728static char *
1729ngx_http_core_types(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
Igor Sysoev79a80482003-05-14 17:13:13 +00001730{
Igor Sysoev7bdb7202006-04-19 15:30:56 +00001731 ngx_http_core_loc_conf_t *lcf = conf;
1732
Igor Sysoevaa3436c2003-05-30 14:27:59 +00001733 char *rv;
Igor Sysoev805d9db2005-02-03 19:33:37 +00001734 ngx_conf_t save;
Igor Sysoevaa3436c2003-05-30 14:27:59 +00001735
Igor Sysoev7bdb7202006-04-19 15:30:56 +00001736 if (lcf->types == NULL) {
1737 lcf->types = ngx_array_create(cf->pool, 64, sizeof(ngx_hash_key_t));
1738 if (lcf->types == NULL) {
1739 return NGX_CONF_ERROR;
1740 }
1741 }
1742
Igor Sysoev805d9db2005-02-03 19:33:37 +00001743 save = *cf;
1744 cf->handler = ngx_http_core_type;
Igor Sysoevaa3436c2003-05-30 14:27:59 +00001745 cf->handler_conf = conf;
Igor Sysoev805d9db2005-02-03 19:33:37 +00001746
Igor Sysoevaa3436c2003-05-30 14:27:59 +00001747 rv = ngx_conf_parse(cf, NULL);
Igor Sysoev805d9db2005-02-03 19:33:37 +00001748
1749 *cf = save;
Igor Sysoevaa3436c2003-05-30 14:27:59 +00001750
1751 return rv;
1752}
1753
1754
Igor Sysoevaa828612005-02-09 14:31:07 +00001755static char *
1756ngx_http_core_type(ngx_conf_t *cf, ngx_command_t *dummy, void *conf)
Igor Sysoevaa3436c2003-05-30 14:27:59 +00001757{
1758 ngx_http_core_loc_conf_t *lcf = conf;
Igor Sysoev79a80482003-05-14 17:13:13 +00001759
Igor Sysoev24025022005-12-16 15:07:08 +00001760 ngx_str_t *value, *content_type, *old;
1761 ngx_uint_t i, n;
1762 ngx_hash_key_t *type;
Igor Sysoev79a80482003-05-14 17:13:13 +00001763
Igor Sysoev24025022005-12-16 15:07:08 +00001764 content_type = ngx_palloc(cf->pool, sizeof(ngx_str_t));
1765 if (content_type == NULL) {
1766 return NGX_CONF_ERROR;
Igor Sysoev79a80482003-05-14 17:13:13 +00001767 }
1768
Igor Sysoev805d9db2005-02-03 19:33:37 +00001769 value = cf->args->elts;
Igor Sysoev24025022005-12-16 15:07:08 +00001770 *content_type = value[0];
Igor Sysoev79a80482003-05-14 17:13:13 +00001771
1772 for (i = 1; i < cf->args->nelts; i++) {
Igor Sysoev79a80482003-05-14 17:13:13 +00001773
Igor Sysoev24025022005-12-16 15:07:08 +00001774 for (n = 0; n < value[i].len; n++) {
1775 value[i].data[n] = ngx_tolower(value[i].data[n]);
1776 }
1777
1778 type = lcf->types->elts;
1779 for (n = 0; n < lcf->types->nelts; n++) {
1780 if (ngx_strcmp(value[i].data, type[n].key.data) == 0) {
1781 old = type[n].value;
1782 type[n].value = content_type;
1783
1784 ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
1785 "duplicate extention \"%V\", "
1786 "content type: \"%V\", "
1787 "old content type: \"%V\"",
1788 &value[i], content_type, old);
1789 continue;
1790 }
1791 }
1792
1793
1794 type = ngx_array_push(lcf->types);
Igor Sysoevc1571722005-03-19 12:38:37 +00001795 if (type == NULL) {
Igor Sysoevdc3b2a72004-09-14 19:39:54 +00001796 return NGX_CONF_ERROR;
1797 }
1798
Igor Sysoev24025022005-12-16 15:07:08 +00001799 type->key = value[i];
1800 type->key_hash = ngx_hash_key(value[i].data, value[i].len);
1801 type->value = content_type;
Igor Sysoev79a80482003-05-14 17:13:13 +00001802 }
1803
1804 return NGX_CONF_OK;
1805}
1806
1807
Igor Sysoev899b44e2005-05-12 14:58:06 +00001808static ngx_int_t
1809ngx_http_core_preconfiguration(ngx_conf_t *cf)
1810{
1811 return ngx_http_variables_add_core_vars(cf);
1812}
1813
1814
Igor Sysoevaa828612005-02-09 14:31:07 +00001815static void *
1816ngx_http_core_create_main_conf(ngx_conf_t *cf)
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001817{
Igor Sysoev805d9db2005-02-03 19:33:37 +00001818 ngx_http_core_main_conf_t *cmcf;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001819
Igor Sysoevc1571722005-03-19 12:38:37 +00001820 cmcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_main_conf_t));
1821 if (cmcf == NULL) {
Igor Sysoev805d9db2005-02-03 19:33:37 +00001822 return NGX_CONF_ERROR;
1823 }
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001824
Igor Sysoev8184d1b2005-03-04 14:06:57 +00001825 if (ngx_array_init(&cmcf->servers, cf->pool, 4,
Igor Sysoev9ac946b2005-10-24 15:09:41 +00001826 sizeof(ngx_http_core_srv_conf_t *))
Igor Sysoev6f134cc2006-05-23 14:54:58 +00001827 != NGX_OK)
Igor Sysoev805d9db2005-02-03 19:33:37 +00001828 {
1829 return NGX_CONF_ERROR;
1830 }
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001831
Igor Sysoev305a9d82005-12-26 17:07:48 +00001832 cmcf->server_names_hash_max_size = NGX_CONF_UNSET_UINT;
1833 cmcf->server_names_hash_bucket_size = NGX_CONF_UNSET_UINT;
Igor Sysoevb1dfe472004-12-21 12:30:30 +00001834
Igor Sysoevffe71442006-02-08 15:33:12 +00001835 cmcf->variables_hash_max_size = NGX_CONF_UNSET_UINT;
1836 cmcf->variables_hash_bucket_size = NGX_CONF_UNSET_UINT;
1837
Igor Sysoeva9830112003-05-19 16:39:14 +00001838 return cmcf;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001839}
1840
1841
Igor Sysoevaa828612005-02-09 14:31:07 +00001842static char *
1843ngx_http_core_init_main_conf(ngx_conf_t *cf, void *conf)
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001844{
Igor Sysoev6253ca12003-05-27 12:18:54 +00001845 ngx_http_core_main_conf_t *cmcf = conf;
Igor Sysoeva9830112003-05-19 16:39:14 +00001846
Igor Sysoev305a9d82005-12-26 17:07:48 +00001847 if (cmcf->server_names_hash_max_size == NGX_CONF_UNSET_UINT) {
1848 cmcf->server_names_hash_max_size = 512;
Igor Sysoevb1dfe472004-12-21 12:30:30 +00001849 }
1850
Igor Sysoev305a9d82005-12-26 17:07:48 +00001851 if (cmcf->server_names_hash_bucket_size == NGX_CONF_UNSET_UINT) {
1852 cmcf->server_names_hash_bucket_size = ngx_cacheline_size;
Igor Sysoevb1dfe472004-12-21 12:30:30 +00001853 }
Igor Sysoeva9830112003-05-19 16:39:14 +00001854
Igor Sysoev305a9d82005-12-26 17:07:48 +00001855 cmcf->server_names_hash_bucket_size =
1856 ngx_align(cmcf->server_names_hash_bucket_size, ngx_cacheline_size);
1857
Igor Sysoevffe71442006-02-08 15:33:12 +00001858
1859 if (cmcf->variables_hash_max_size == NGX_CONF_UNSET_UINT) {
1860 cmcf->variables_hash_max_size = 512;
1861 }
1862
1863 if (cmcf->variables_hash_bucket_size == NGX_CONF_UNSET_UINT) {
1864 cmcf->variables_hash_bucket_size = 64;
1865 }
1866
1867 cmcf->variables_hash_bucket_size =
1868 ngx_align(cmcf->variables_hash_bucket_size, ngx_cacheline_size);
1869
Igor Sysoeva9830112003-05-19 16:39:14 +00001870 return NGX_CONF_OK;
1871}
1872
1873
Igor Sysoevaa828612005-02-09 14:31:07 +00001874static void *
1875ngx_http_core_create_srv_conf(ngx_conf_t *cf)
Igor Sysoeva9830112003-05-19 16:39:14 +00001876{
1877 ngx_http_core_srv_conf_t *cscf;
1878
Igor Sysoevc1571722005-03-19 12:38:37 +00001879 cscf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_srv_conf_t));
1880 if (cscf == NULL) {
Igor Sysoevaa828612005-02-09 14:31:07 +00001881 return NGX_CONF_ERROR;
1882 }
1883
Igor Sysoev85080d02004-09-22 16:18:21 +00001884 /*
Igor Sysoev02025fd2005-01-18 13:03:58 +00001885 * set by ngx_pcalloc():
Igor Sysoevaa828612005-02-09 14:31:07 +00001886 *
Igor Sysoev02025fd2005-01-18 13:03:58 +00001887 * conf->client_large_buffers.num = 0;
1888 */
Igor Sysoev85080d02004-09-22 16:18:21 +00001889
Igor Sysoev8184d1b2005-03-04 14:06:57 +00001890 if (ngx_array_init(&cscf->locations, cf->pool, 4, sizeof(void *))
Igor Sysoev305a9d82005-12-26 17:07:48 +00001891 == NGX_ERROR)
Igor Sysoevaa828612005-02-09 14:31:07 +00001892 {
1893 return NGX_CONF_ERROR;
1894 }
1895
Igor Sysoev8184d1b2005-03-04 14:06:57 +00001896 if (ngx_array_init(&cscf->listen, cf->pool, 4, sizeof(ngx_http_listen_t))
Igor Sysoev305a9d82005-12-26 17:07:48 +00001897 == NGX_ERROR)
Igor Sysoevaa828612005-02-09 14:31:07 +00001898 {
1899 return NGX_CONF_ERROR;
1900 }
1901
Igor Sysoev8184d1b2005-03-04 14:06:57 +00001902 if (ngx_array_init(&cscf->server_names, cf->pool, 4,
Igor Sysoev305a9d82005-12-26 17:07:48 +00001903 sizeof(ngx_http_server_name_t))
1904 == NGX_ERROR)
Igor Sysoevaa828612005-02-09 14:31:07 +00001905 {
1906 return NGX_CONF_ERROR;
1907 }
Igor Sysoeva9830112003-05-19 16:39:14 +00001908
Igor Sysoev10a543a2004-03-16 07:10:12 +00001909 cscf->connection_pool_size = NGX_CONF_UNSET_SIZE;
Igor Sysoev10a543a2004-03-16 07:10:12 +00001910 cscf->request_pool_size = NGX_CONF_UNSET_SIZE;
1911 cscf->client_header_timeout = NGX_CONF_UNSET_MSEC;
1912 cscf->client_header_buffer_size = NGX_CONF_UNSET_SIZE;
Igor Sysoev8290d282006-02-03 12:58:48 +00001913 cscf->optimize_server_names = NGX_CONF_UNSET;
Igor Sysoev3362b8d2005-05-14 18:42:03 +00001914 cscf->ignore_invalid_headers = NGX_CONF_UNSET;
Igor Sysoev187fcd82003-05-23 11:53:01 +00001915
Igor Sysoeva9830112003-05-19 16:39:14 +00001916 return cscf;
1917}
1918
1919
Igor Sysoevaa828612005-02-09 14:31:07 +00001920static char *
1921ngx_http_core_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
Igor Sysoeva9830112003-05-19 16:39:14 +00001922{
Igor Sysoevaa3436c2003-05-30 14:27:59 +00001923 ngx_http_core_srv_conf_t *prev = parent;
1924 ngx_http_core_srv_conf_t *conf = child;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001925
Igor Sysoev305a9d82005-12-26 17:07:48 +00001926 ngx_http_listen_t *ls;
1927 ngx_http_server_name_t *sn;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001928
Igor Sysoev7578ec92003-06-02 15:24:30 +00001929 /* TODO: it does not merge, it inits only */
Igor Sysoeva9830112003-05-19 16:39:14 +00001930
1931 if (conf->listen.nelts == 0) {
Igor Sysoevc1571722005-03-19 12:38:37 +00001932 ls = ngx_array_push(&conf->listen);
1933 if (ls == NULL) {
Igor Sysoevaa828612005-02-09 14:31:07 +00001934 return NGX_CONF_ERROR;
1935 }
1936
Igor Sysoevb145b062005-06-15 18:33:41 +00001937 ngx_memzero(ls, sizeof(ngx_http_listen_t));
1938
Igor Sysoevaa828612005-02-09 14:31:07 +00001939 ls->addr = INADDR_ANY;
Igor Sysoev1b735832004-11-11 14:07:14 +00001940#if (NGX_WIN32)
Igor Sysoevaa828612005-02-09 14:31:07 +00001941 ls->port = 80;
Igor Sysoev1c104622003-06-03 15:42:58 +00001942#else
Igor Sysoev7578ec92003-06-02 15:24:30 +00001943 /* STUB: getuid() should be cached */
Igor Sysoevaa828612005-02-09 14:31:07 +00001944 ls->port = (getuid() == 0) ? 80 : 8000;
Igor Sysoev1c104622003-06-03 15:42:58 +00001945#endif
Igor Sysoevaa828612005-02-09 14:31:07 +00001946 ls->family = AF_INET;
Igor Sysoev9ac946b2005-10-24 15:09:41 +00001947
1948 ls->conf.backlog = -1;
1949 ls->conf.rcvbuf = -1;
1950 ls->conf.sndbuf = -1;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00001951 }
1952
Igor Sysoev9e580192006-02-01 18:22:15 +00001953 if (conf->server_name.data == NULL) {
1954 conf->server_name.data = ngx_palloc(cf->pool, NGX_MAXHOSTNAMELEN);
1955 if (conf->server_name.data == NULL) {
Igor Sysoevaa828612005-02-09 14:31:07 +00001956 return NGX_CONF_ERROR;
1957 }
Igor Sysoev13933252003-05-29 13:02:09 +00001958
Igor Sysoev9e580192006-02-01 18:22:15 +00001959 if (gethostname((char *) conf->server_name.data, NGX_MAXHOSTNAMELEN)
1960 == -1)
1961 {
Igor Sysoev8e1fbe62003-07-18 14:44:05 +00001962 ngx_conf_log_error(NGX_LOG_EMERG, cf, ngx_errno,
1963 "gethostname() failed");
1964 return NGX_CONF_ERROR;
Igor Sysoevad22e012003-01-15 07:02:27 +00001965 }
Igor Sysoev13933252003-05-29 13:02:09 +00001966
Igor Sysoev9e580192006-02-01 18:22:15 +00001967 conf->server_name.len = ngx_strlen(conf->server_name.data);
1968
1969 sn = ngx_array_push(&conf->server_names);
1970 if (sn == NULL) {
1971 return NGX_CONF_ERROR;
1972 }
1973
1974 sn->name.len = conf->server_name.len;
1975 sn->name.data = conf->server_name.data;
Igor Sysoevaa828612005-02-09 14:31:07 +00001976 sn->core_srv_conf = conf;
Igor Sysoevad22e012003-01-15 07:02:27 +00001977 }
1978
Igor Sysoev239baac2003-06-11 15:28:34 +00001979 ngx_conf_merge_size_value(conf->connection_pool_size,
Igor Sysoev8035fd22004-10-01 15:53:53 +00001980 prev->connection_pool_size, 256);
Igor Sysoev187fcd82003-05-23 11:53:01 +00001981 ngx_conf_merge_size_value(conf->request_pool_size,
Igor Sysoev8035fd22004-10-01 15:53:53 +00001982 prev->request_pool_size, 4096);
Igor Sysoev187fcd82003-05-23 11:53:01 +00001983 ngx_conf_merge_msec_value(conf->client_header_timeout,
1984 prev->client_header_timeout, 60000);
1985 ngx_conf_merge_size_value(conf->client_header_buffer_size,
1986 prev->client_header_buffer_size, 1024);
Igor Sysoevf7abd722004-09-23 06:32:00 +00001987 ngx_conf_merge_bufs_value(conf->large_client_header_buffers,
1988 prev->large_client_header_buffers,
1989 4, ngx_pagesize);
1990
1991 if (conf->large_client_header_buffers.size < conf->connection_pool_size) {
1992 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
1993 "the \"large_client_header_buffers\" size must be "
1994 "equal to or bigger than \"connection_pool_size\"");
1995 return NGX_CONF_ERROR;
1996 }
1997
Igor Sysoev8290d282006-02-03 12:58:48 +00001998 ngx_conf_merge_value(conf->optimize_server_names,
1999 prev->optimize_server_names, 1);
Igor Sysoev34303462006-01-24 16:08:27 +00002000
Igor Sysoev3362b8d2005-05-14 18:42:03 +00002001 ngx_conf_merge_value(conf->ignore_invalid_headers,
2002 prev->ignore_invalid_headers, 1);
2003
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002004 return NGX_CONF_OK;
2005}
2006
2007
Igor Sysoevaa828612005-02-09 14:31:07 +00002008static void *
2009ngx_http_core_create_loc_conf(ngx_conf_t *cf)
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002010{
Igor Sysoev805d9db2005-02-03 19:33:37 +00002011 ngx_http_core_loc_conf_t *lcf;
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002012
Igor Sysoevc1571722005-03-19 12:38:37 +00002013 lcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_loc_conf_t));
2014 if (lcf == NULL) {
Igor Sysoevaa828612005-02-09 14:31:07 +00002015 return NGX_CONF_ERROR;
2016 }
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002017
Igor Sysoev02025fd2005-01-18 13:03:58 +00002018 /*
2019 * set by ngx_pcalloc():
2020 *
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +00002021 * lcf->root = { 0, NULL };
Igor Sysoev94e32ce2006-04-07 14:08:04 +00002022 * lcf->limit_except = 0;
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +00002023 * lcf->post_action = { 0, NULL };
Igor Sysoev02025fd2005-01-18 13:03:58 +00002024 * lcf->types = NULL;
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +00002025 * lcf->default_type = { 0, NULL };
Igor Sysoev02025fd2005-01-18 13:03:58 +00002026 * lcf->err_log = NULL;
2027 * lcf->error_pages = NULL;
2028 * lcf->client_body_path = NULL;
2029 * lcf->regex = NULL;
2030 * lcf->exact_match = 0;
2031 * lcf->auto_redirect = 0;
2032 * lcf->alias = 0;
2033 */
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002034
Igor Sysoev1765f472006-07-07 16:33:19 +00002035 lcf->client_max_body_size = NGX_CONF_UNSET;
Igor Sysoevdbb27762004-04-01 16:20:53 +00002036 lcf->client_body_buffer_size = NGX_CONF_UNSET_SIZE;
Igor Sysoev10a543a2004-03-16 07:10:12 +00002037 lcf->client_body_timeout = NGX_CONF_UNSET_MSEC;
Igor Sysoev31eb8c02005-09-23 11:02:22 +00002038 lcf->satisfy_any = NGX_CONF_UNSET;
Igor Sysoev899b44e2005-05-12 14:58:06 +00002039 lcf->internal = NGX_CONF_UNSET;
Igor Sysoev8a2b2fb2006-04-14 09:53:38 +00002040 lcf->client_body_in_file_only = NGX_CONF_UNSET;
Igor Sysoev5bf3d252003-10-22 07:05:29 +00002041 lcf->sendfile = NGX_CONF_UNSET;
Igor Sysoev3c3ca172004-01-05 20:55:48 +00002042 lcf->tcp_nopush = NGX_CONF_UNSET;
Igor Sysoev924bd792004-10-11 15:07:03 +00002043 lcf->tcp_nodelay = NGX_CONF_UNSET;
Igor Sysoev10a543a2004-03-16 07:10:12 +00002044 lcf->send_timeout = NGX_CONF_UNSET_MSEC;
2045 lcf->send_lowat = NGX_CONF_UNSET_SIZE;
Igor Sysoev7823cc32004-07-14 16:01:42 +00002046 lcf->postpone_output = NGX_CONF_UNSET_SIZE;
2047 lcf->limit_rate = NGX_CONF_UNSET_SIZE;
Igor Sysoev10a543a2004-03-16 07:10:12 +00002048 lcf->keepalive_timeout = NGX_CONF_UNSET_MSEC;
Igor Sysoev307c3ad2004-09-17 16:07:35 +00002049 lcf->keepalive_header = NGX_CONF_UNSET;
Igor Sysoev10a543a2004-03-16 07:10:12 +00002050 lcf->lingering_time = NGX_CONF_UNSET_MSEC;
2051 lcf->lingering_timeout = NGX_CONF_UNSET_MSEC;
Igor Sysoev0ab91b92004-06-06 19:49:18 +00002052 lcf->reset_timedout_connection = NGX_CONF_UNSET;
Igor Sysoev7b190b42005-06-07 15:56:31 +00002053 lcf->port_in_redirect = NGX_CONF_UNSET;
Igor Sysoev12b4b002003-10-24 06:53:41 +00002054 lcf->msie_padding = NGX_CONF_UNSET;
Igor Sysoev5192b362005-07-08 14:34:20 +00002055 lcf->log_not_found = NGX_CONF_UNSET;
Igor Sysoev24025022005-12-16 15:07:08 +00002056 lcf->types_hash_max_size = NGX_CONF_UNSET_UINT;
2057 lcf->types_hash_bucket_size = NGX_CONF_UNSET_UINT;
Igor Sysoev12b4b002003-10-24 06:53:41 +00002058
Igor Sysoev4e9393a2003-01-09 05:36:00 +00002059 return lcf;
2060}
Igor Sysoeva19a85e2003-01-28 15:56:37 +00002061
Igor Sysoev79a80482003-05-14 17:13:13 +00002062
Igor Sysoev24025022005-12-16 15:07:08 +00002063static ngx_str_t ngx_http_core_text_html_type = ngx_string("text/html");
2064static ngx_str_t ngx_http_core_image_gif_type = ngx_string("image/gif");
2065static ngx_str_t ngx_http_core_image_jpeg_type = ngx_string("image/jpeg");
2066
2067static ngx_hash_key_t ngx_http_core_default_types[] = {
2068 { ngx_string("html"), 0, &ngx_http_core_text_html_type },
2069 { ngx_string("gif"), 0, &ngx_http_core_image_gif_type },
2070 { ngx_string("jpg"), 0, &ngx_http_core_image_jpeg_type },
2071 { ngx_null_string, 0, NULL }
Igor Sysoev79a80482003-05-14 17:13:13 +00002072};
2073
2074
Igor Sysoevaa828612005-02-09 14:31:07 +00002075static char *
Igor Sysoev24025022005-12-16 15:07:08 +00002076ngx_http_core_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
Igor Sysoeve2a31542003-04-08 15:40:10 +00002077{
Igor Sysoevaa3436c2003-05-30 14:27:59 +00002078 ngx_http_core_loc_conf_t *prev = parent;
2079 ngx_http_core_loc_conf_t *conf = child;
Igor Sysoev79a80482003-05-14 17:13:13 +00002080
Igor Sysoevaa828612005-02-09 14:31:07 +00002081 ngx_uint_t i;
Igor Sysoev24025022005-12-16 15:07:08 +00002082 ngx_hash_key_t *type;
2083 ngx_hash_init_t types_hash;
Igor Sysoev79a80482003-05-14 17:13:13 +00002084
Igor Sysoev34303462006-01-24 16:08:27 +00002085 if (conf->root.data == NULL) {
Igor Sysoev79a80482003-05-14 17:13:13 +00002086
Igor Sysoev455a7fc2006-03-21 08:20:41 +00002087 conf->alias = prev->alias;
Igor Sysoev34303462006-01-24 16:08:27 +00002088 conf->root = prev->root;
2089 conf->root_lengths = prev->root_lengths;
2090 conf->root_values = prev->root_values;
2091
2092 if (prev->root.data == NULL) {
2093 conf->root.len = sizeof("html") - 1;
2094 conf->root.data = (u_char *) "html";
2095
2096 if (ngx_conf_full_name(cf->cycle, &conf->root) == NGX_ERROR) {
2097 return NGX_CONF_ERROR;
2098 }
2099 }
Igor Sysoev6d2a14a2004-09-27 16:03:21 +00002100 }
2101
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +00002102 if (conf->post_action.data == NULL) {
2103 conf->post_action = prev->post_action;
2104 }
2105
Igor Sysoev1765f472006-07-07 16:33:19 +00002106 ngx_conf_merge_uint_value(conf->types_hash_max_size,
2107 prev->types_hash_max_size, 1024);
Igor Sysoev79a80482003-05-14 17:13:13 +00002108
Igor Sysoev1765f472006-07-07 16:33:19 +00002109 ngx_conf_merge_uint_value(conf->types_hash_bucket_size,
2110 prev->types_hash_bucket_size,
2111 ngx_cacheline_size);
Igor Sysoev24025022005-12-16 15:07:08 +00002112
2113 conf->types_hash_bucket_size = ngx_align(conf->types_hash_bucket_size,
2114 ngx_cacheline_size);
2115
2116 /*
2117 * the special handling the "types" directive in the "http" section
2118 * to inherit the http's conf->types_hash to all servers
2119 */
2120
2121 if (prev->types && prev->types_hash.buckets == NULL) {
2122
2123 types_hash.hash = &prev->types_hash;
2124 types_hash.key = ngx_hash_key_lc;
2125 types_hash.max_size = conf->types_hash_max_size;
2126 types_hash.bucket_size = conf->types_hash_bucket_size;
Igor Sysoev3ca233e2005-12-28 14:23:52 +00002127 types_hash.name = "types_hash";
Igor Sysoev24025022005-12-16 15:07:08 +00002128 types_hash.pool = cf->pool;
2129 types_hash.temp_pool = NULL;
2130
2131 if (ngx_hash_init(&types_hash, prev->types->elts, prev->types->nelts)
2132 != NGX_OK)
2133 {
2134 return NGX_CONF_ERROR;
2135 }
2136 }
2137
2138 if (conf->types == NULL) {
2139 conf->types = prev->types;
2140 conf->types_hash = prev->types_hash;
2141 }
2142
2143 if (conf->types == NULL) {
2144 conf->types = ngx_array_create(cf->pool, 4, sizeof(ngx_hash_key_t));
2145 if (conf->types == NULL) {
2146 return NGX_CONF_ERROR;
2147 }
2148
2149 for (i = 0; ngx_http_core_default_types[i].key.len; i++) {
2150 type = ngx_array_push(conf->types);
2151 if (type == NULL) {
Igor Sysoevaa828612005-02-09 14:31:07 +00002152 return NGX_CONF_ERROR;
Igor Sysoev79a80482003-05-14 17:13:13 +00002153 }
2154
Igor Sysoev24025022005-12-16 15:07:08 +00002155 type->key = ngx_http_core_default_types[i].key;
2156 type->key_hash =
2157 ngx_hash_key_lc(ngx_http_core_default_types[i].key.data,
2158 ngx_http_core_default_types[i].key.len);
2159 type->value = ngx_http_core_default_types[i].value;
2160 }
2161 }
Igor Sysoev79a80482003-05-14 17:13:13 +00002162
Igor Sysoev24025022005-12-16 15:07:08 +00002163 if (conf->types_hash.buckets == NULL) {
Igor Sysoevaa828612005-02-09 14:31:07 +00002164
Igor Sysoev24025022005-12-16 15:07:08 +00002165 types_hash.hash = &conf->types_hash;
2166 types_hash.key = ngx_hash_key_lc;
2167 types_hash.max_size = conf->types_hash_max_size;
2168 types_hash.bucket_size = conf->types_hash_bucket_size;
Igor Sysoev3ca233e2005-12-28 14:23:52 +00002169 types_hash.name = "mime_types_hash";
Igor Sysoev24025022005-12-16 15:07:08 +00002170 types_hash.pool = cf->pool;
2171 types_hash.temp_pool = NULL;
Igor Sysoevaa828612005-02-09 14:31:07 +00002172
Igor Sysoev24025022005-12-16 15:07:08 +00002173 if (ngx_hash_init(&types_hash, conf->types->elts, conf->types->nelts)
2174 != NGX_OK)
2175 {
2176 return NGX_CONF_ERROR;
Igor Sysoev79a80482003-05-14 17:13:13 +00002177 }
2178 }
2179
Igor Sysoev890fc962003-07-20 21:15:59 +00002180 if (conf->err_log == NULL) {
2181 if (prev->err_log) {
2182 conf->err_log = prev->err_log;
2183 } else {
Igor Sysoev630ad0c2004-04-16 05:14:16 +00002184 conf->err_log = cf->cycle->new_log;
Igor Sysoev890fc962003-07-20 21:15:59 +00002185 }
2186 }
2187
Igor Sysoev74e95c22003-11-09 20:03:38 +00002188 if (conf->error_pages == NULL && prev->error_pages) {
2189 conf->error_pages = prev->error_pages;
2190 }
2191
Igor Sysoev6253ca12003-05-27 12:18:54 +00002192 ngx_conf_merge_str_value(conf->default_type,
Igor Sysoevaa828612005-02-09 14:31:07 +00002193 prev->default_type, "text/plain");
Igor Sysoev6253ca12003-05-27 12:18:54 +00002194
Igor Sysoev1765f472006-07-07 16:33:19 +00002195 ngx_conf_merge_off_value(conf->client_max_body_size,
Igor Sysoev8035fd22004-10-01 15:53:53 +00002196 prev->client_max_body_size, 1 * 1024 * 1024);
Igor Sysoevdbb27762004-04-01 16:20:53 +00002197 ngx_conf_merge_size_value(conf->client_body_buffer_size,
Igor Sysoev8035fd22004-10-01 15:53:53 +00002198 prev->client_body_buffer_size,
2199 (size_t) 2 * ngx_pagesize);
Igor Sysoev2b0c76c2003-10-27 21:01:00 +00002200 ngx_conf_merge_msec_value(conf->client_body_timeout,
Igor Sysoev7af6b162004-02-09 07:46:43 +00002201 prev->client_body_timeout, 60000);
Igor Sysoev899b44e2005-05-12 14:58:06 +00002202
Igor Sysoev31eb8c02005-09-23 11:02:22 +00002203 ngx_conf_merge_value(conf->satisfy_any, prev->satisfy_any, 0);
Igor Sysoev899b44e2005-05-12 14:58:06 +00002204 ngx_conf_merge_value(conf->internal, prev->internal, 0);
Igor Sysoev8a2b2fb2006-04-14 09:53:38 +00002205 ngx_conf_merge_value(conf->client_body_in_file_only,
2206 prev->client_body_in_file_only, 0);
Igor Sysoev5bf3d252003-10-22 07:05:29 +00002207 ngx_conf_merge_value(conf->sendfile, prev->sendfile, 0);
Igor Sysoev3c3ca172004-01-05 20:55:48 +00002208 ngx_conf_merge_value(conf->tcp_nopush, prev->tcp_nopush, 0);
Igor Sysoev924bd792004-10-11 15:07:03 +00002209 ngx_conf_merge_value(conf->tcp_nodelay, prev->tcp_nodelay, 0);
Igor Sysoev899b44e2005-05-12 14:58:06 +00002210
Igor Sysoev7af6b162004-02-09 07:46:43 +00002211 ngx_conf_merge_msec_value(conf->send_timeout, prev->send_timeout, 60000);
Igor Sysoevb5faed22003-10-29 08:30:44 +00002212 ngx_conf_merge_size_value(conf->send_lowat, prev->send_lowat, 0);
Igor Sysoev7823cc32004-07-14 16:01:42 +00002213 ngx_conf_merge_size_value(conf->postpone_output, prev->postpone_output,
2214 1460);
2215 ngx_conf_merge_size_value(conf->limit_rate, prev->limit_rate, 0);
Igor Sysoev187fcd82003-05-23 11:53:01 +00002216 ngx_conf_merge_msec_value(conf->keepalive_timeout,
Igor Sysoev307c3ad2004-09-17 16:07:35 +00002217 prev->keepalive_timeout, 75000);
2218 ngx_conf_merge_sec_value(conf->keepalive_header,
2219 prev->keepalive_header, 0);
Igor Sysoev187fcd82003-05-23 11:53:01 +00002220 ngx_conf_merge_msec_value(conf->lingering_time,
2221 prev->lingering_time, 30000);
2222 ngx_conf_merge_msec_value(conf->lingering_timeout,
2223 prev->lingering_timeout, 5000);
Igor Sysoev79a80482003-05-14 17:13:13 +00002224
Igor Sysoev02025fd2005-01-18 13:03:58 +00002225 ngx_conf_merge_path_value(conf->client_body_temp_path,
2226 prev->client_body_temp_path,
2227 NGX_HTTP_CLIENT_TEMP_PATH, 0, 0, 0,
2228 ngx_garbage_collector_temp_handler, cf);
2229
Igor Sysoev0ab91b92004-06-06 19:49:18 +00002230 ngx_conf_merge_value(conf->reset_timedout_connection,
Igor Sysoevaa828612005-02-09 14:31:07 +00002231 prev->reset_timedout_connection, 0);
Igor Sysoev7b190b42005-06-07 15:56:31 +00002232 ngx_conf_merge_value(conf->port_in_redirect, prev->port_in_redirect, 1);
Igor Sysoev12b4b002003-10-24 06:53:41 +00002233 ngx_conf_merge_value(conf->msie_padding, prev->msie_padding, 1);
Igor Sysoev5192b362005-07-08 14:34:20 +00002234 ngx_conf_merge_value(conf->log_not_found, prev->log_not_found, 1);
Igor Sysoev12b4b002003-10-24 06:53:41 +00002235
Igor Sysoev865c1502003-11-30 20:03:18 +00002236 if (conf->open_files == NULL) {
2237 conf->open_files = prev->open_files;
2238 }
2239
Igor Sysoeve2a31542003-04-08 15:40:10 +00002240 return NGX_CONF_OK;
2241}
2242
Igor Sysoev79a80482003-05-14 17:13:13 +00002243
Igor Sysoevb145b062005-06-15 18:33:41 +00002244/* AF_INET only */
2245
Igor Sysoevaa828612005-02-09 14:31:07 +00002246static char *
2247ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
Igor Sysoeva19a85e2003-01-28 15:56:37 +00002248{
Igor Sysoevaa3436c2003-05-30 14:27:59 +00002249 ngx_http_core_srv_conf_t *scf = conf;
Igor Sysoeva9830112003-05-19 16:39:14 +00002250
Igor Sysoevb145b062005-06-15 18:33:41 +00002251 char *err;
Igor Sysoevc2068d02005-10-19 12:33:58 +00002252 ngx_str_t *value, size;
Igor Sysoevb145b062005-06-15 18:33:41 +00002253 ngx_uint_t n;
2254 struct hostent *h;
2255 ngx_http_listen_t *ls;
2256 ngx_inet_upstream_t inet_upstream;
Igor Sysoeva19a85e2003-01-28 15:56:37 +00002257
Igor Sysoeve2ff3ea2004-09-14 15:55:24 +00002258 /*
2259 * TODO: check duplicate 'listen' directives,
2260 * add resolved name to server names ???
2261 */
Igor Sysoev6ddfbf02003-05-15 15:42:53 +00002262
Igor Sysoevb145b062005-06-15 18:33:41 +00002263 value = cf->args->elts;
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +00002264
Igor Sysoevb145b062005-06-15 18:33:41 +00002265 ngx_memzero(&inet_upstream, sizeof(ngx_inet_upstream_t));
2266
2267 inet_upstream.url = value[1];
2268 inet_upstream.port_only = 1;
2269
2270 err = ngx_inet_parse_host_port(&inet_upstream);
2271
2272 if (err) {
2273 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2274 "%s in \"%V\" of the \"listen\" directive",
2275 err, &inet_upstream.url);
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +00002276 return NGX_CONF_ERROR;
Igor Sysoevb145b062005-06-15 18:33:41 +00002277 }
2278
Igor Sysoevc1571722005-03-19 12:38:37 +00002279 ls = ngx_array_push(&scf->listen);
2280 if (ls == NULL) {
Igor Sysoeve2ff3ea2004-09-14 15:55:24 +00002281 return NGX_CONF_ERROR;
2282 }
Igor Sysoeva19a85e2003-01-28 15:56:37 +00002283
Igor Sysoevb145b062005-06-15 18:33:41 +00002284 ngx_memzero(ls, sizeof(ngx_http_listen_t));
Igor Sysoeva19a85e2003-01-28 15:56:37 +00002285
2286 ls->family = AF_INET;
Igor Sysoevb145b062005-06-15 18:33:41 +00002287 ls->port = (in_port_t) (inet_upstream.default_port ?
Igor Sysoevffe71442006-02-08 15:33:12 +00002288 80 : inet_upstream.port);
Igor Sysoevfe5cb6b2003-01-29 07:25:51 +00002289 ls->file_name = cf->conf_file->file.name;
Igor Sysoeva19a85e2003-01-28 15:56:37 +00002290 ls->line = cf->conf_file->line;
Igor Sysoevb145b062005-06-15 18:33:41 +00002291 ls->conf.backlog = -1;
Igor Sysoevc2068d02005-10-19 12:33:58 +00002292 ls->conf.rcvbuf = -1;
2293 ls->conf.sndbuf = -1;
Igor Sysoeva19a85e2003-01-28 15:56:37 +00002294
Igor Sysoev13c68742006-03-10 12:51:52 +00002295 if (inet_upstream.host.len == 1 && inet_upstream.host.data[0] == '*') {
2296 inet_upstream.host.len = 0;
2297 }
2298
Igor Sysoevb145b062005-06-15 18:33:41 +00002299 if (inet_upstream.host.len) {
2300 inet_upstream.host.data[inet_upstream.host.len] = '\0';
Igor Sysoeva19a85e2003-01-28 15:56:37 +00002301
Igor Sysoevb145b062005-06-15 18:33:41 +00002302 ls->addr = inet_addr((const char *) inet_upstream.host.data);
2303
2304 if (ls->addr == INADDR_NONE) {
2305 h = gethostbyname((const char *) inet_upstream.host.data);
2306
2307 if (h == NULL || h->h_addr_list[0] == NULL) {
2308 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2309 "can not resolve host \"%s\" "
2310 "in the \"listen\" directive",
2311 inet_upstream.host.data);
2312 return NGX_CONF_ERROR;
2313 }
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +00002314
Igor Sysoevb145b062005-06-15 18:33:41 +00002315 ls->addr = *(in_addr_t *)(h->h_addr_list[0]);
Igor Sysoev6ddfbf02003-05-15 15:42:53 +00002316 }
Igor Sysoeva19a85e2003-01-28 15:56:37 +00002317
Igor Sysoev236e0452004-09-23 16:39:34 +00002318 } else {
Igor Sysoevb145b062005-06-15 18:33:41 +00002319 ls->addr = INADDR_ANY;
Igor Sysoev236e0452004-09-23 16:39:34 +00002320 }
Igor Sysoevf1602632004-09-21 19:55:00 +00002321
Igor Sysoev94e32ce2006-04-07 14:08:04 +00002322 n = ngx_inet_ntop(AF_INET, &ls->addr, ls->conf.addr, INET_ADDRSTRLEN + 6);
2323 ngx_sprintf(&ls->conf.addr[n], ":%ui", ls->port);
2324
Igor Sysoevb145b062005-06-15 18:33:41 +00002325 if (cf->args->nelts == 2) {
2326 return NGX_CONF_OK;
2327 }
Igor Sysoevaa828612005-02-09 14:31:07 +00002328
Igor Sysoevb145b062005-06-15 18:33:41 +00002329 if (ngx_strcmp(value[2].data, "default") == 0) {
2330 ls->conf.default_server = 1;
2331 n = 3;
Igor Sysoev24025022005-12-16 15:07:08 +00002332
Igor Sysoevb145b062005-06-15 18:33:41 +00002333 } else {
2334 n = 2;
2335 }
Igor Sysoev13933252003-05-29 13:02:09 +00002336
Igor Sysoevb145b062005-06-15 18:33:41 +00002337 for ( /* void */ ; n < cf->args->nelts; n++) {
2338
2339 if (ls->conf.default_server == 0) {
Igor Sysoev8e1fbe62003-07-18 14:44:05 +00002340 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
Igor Sysoevb145b062005-06-15 18:33:41 +00002341 "\"%V\" parameter can be specified for "
2342 "the default \"listen\" directive only",
2343 &value[n]);
Igor Sysoev8e1fbe62003-07-18 14:44:05 +00002344 return NGX_CONF_ERROR;
Igor Sysoev13933252003-05-29 13:02:09 +00002345 }
2346
Igor Sysoevb145b062005-06-15 18:33:41 +00002347 if (ngx_strcmp(value[n].data, "bind") == 0) {
2348 ls->conf.bind = 1;
2349 continue;
2350 }
2351
Igor Sysoevc2068d02005-10-19 12:33:58 +00002352 if (ngx_strncmp(value[n].data, "backlog=", 8) == 0) {
2353 ls->conf.backlog = ngx_atoi(value[n].data + 8, value[n].len - 8);
Igor Sysoevb145b062005-06-15 18:33:41 +00002354 ls->conf.bind = 1;
2355
2356 if (ls->conf.backlog == NGX_ERROR || ls->conf.backlog == 0) {
2357 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2358 "invalid backlog \"%V\"", &value[n]);
2359 return NGX_CONF_ERROR;
2360 }
2361
2362 continue;
2363 }
2364
Igor Sysoevc2068d02005-10-19 12:33:58 +00002365 if (ngx_strncmp(value[n].data, "rcvbuf=", 7) == 0) {
2366 size.len = value[n].len - 7;
2367 size.data = value[n].data + 7;
2368
2369 ls->conf.rcvbuf = ngx_parse_size(&size);
2370 ls->conf.bind = 1;
2371
2372 if (ls->conf.rcvbuf == NGX_ERROR) {
2373 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2374 "invalid rcvbuf \"%V\"", &value[n]);
2375 return NGX_CONF_ERROR;
2376 }
2377
2378 continue;
2379 }
2380
2381 if (ngx_strncmp(value[n].data, "sndbuf=", 7) == 0) {
2382 size.len = value[n].len - 7;
2383 size.data = value[n].data + 7;
2384
2385 ls->conf.sndbuf = ngx_parse_size(&size);
2386 ls->conf.bind = 1;
2387
2388 if (ls->conf.sndbuf == NGX_ERROR) {
2389 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2390 "invalid sndbuf \"%V\"", &value[n]);
2391 return NGX_CONF_ERROR;
2392 }
2393
2394 continue;
2395 }
2396
2397 if (ngx_strncmp(value[n].data, "accept_filter=", 14) == 0) {
Igor Sysoevb145b062005-06-15 18:33:41 +00002398#if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER)
Igor Sysoevc2068d02005-10-19 12:33:58 +00002399 ls->conf.accept_filter = (char *) &value[n].data[14];
Igor Sysoevb145b062005-06-15 18:33:41 +00002400 ls->conf.bind = 1;
2401#else
2402 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2403 "accept filters \"%V\" are not supported "
2404 "on this platform, ignored",
2405 &value[n]);
2406#endif
2407 continue;
2408 }
2409
2410 if (ngx_strcmp(value[n].data, "deferred") == 0) {
2411#if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT)
2412 ls->conf.deferred_accept = 1;
2413 ls->conf.bind = 1;
2414#else
2415 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2416 "the deferred accept is not supported "
2417 "on this platform, ignored");
2418#endif
2419 continue;
2420 }
2421
2422 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2423 "the invalid \"%V\" parameter", &value[n]);
2424 return NGX_CONF_ERROR;
Igor Sysoev13933252003-05-29 13:02:09 +00002425 }
2426
2427 return NGX_CONF_OK;
2428}
2429
2430
Igor Sysoevaa828612005-02-09 14:31:07 +00002431static char *
2432ngx_http_core_server_name(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
Igor Sysoev13933252003-05-29 13:02:09 +00002433{
Igor Sysoev305a9d82005-12-26 17:07:48 +00002434 ngx_http_core_srv_conf_t *cscf = conf;
Igor Sysoev13933252003-05-29 13:02:09 +00002435
Igor Sysoev305a9d82005-12-26 17:07:48 +00002436 u_char ch;
2437 ngx_str_t *value, name;
2438 ngx_uint_t i;
2439 ngx_http_server_name_t *sn;
Igor Sysoevb1af9bb2004-06-25 14:42:03 +00002440
Igor Sysoevaa3436c2003-05-30 14:27:59 +00002441 value = cf->args->elts;
Igor Sysoev13933252003-05-29 13:02:09 +00002442
Igor Sysoev305a9d82005-12-26 17:07:48 +00002443 ch = value[1].data[0];
2444
2445 if (cscf->server_name.data == NULL && value[1].len) {
2446 if (ch == '*') {
Igor Sysoev8e1fbe62003-07-18 14:44:05 +00002447 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
Igor Sysoev305a9d82005-12-26 17:07:48 +00002448 "first server name \"%V\" must not be wildcard",
2449 &value[1]);
Igor Sysoev8e1fbe62003-07-18 14:44:05 +00002450 return NGX_CONF_ERROR;
Igor Sysoevaa3436c2003-05-30 14:27:59 +00002451 }
Igor Sysoev13933252003-05-29 13:02:09 +00002452
Igor Sysoev305a9d82005-12-26 17:07:48 +00002453 name = value[1];
2454
2455 if (ch == '.') {
2456 name.len--;
2457 name.data++;
2458 }
2459
2460 cscf->server_name.len = name.len;
2461 cscf->server_name.data = ngx_pstrdup(cf->pool, &name);
2462 if (cscf->server_name.data == NULL) {
2463 return NGX_CONF_ERROR;
2464 }
2465 }
2466
2467 for (i = 1; i < cf->args->nelts; i++) {
2468
2469 ch = value[i].data[0];
2470
Igor Sysoev1765f472006-07-07 16:33:19 +00002471 if (value[i].len == 1 && ch == '*') {
2472 cscf->wildcard = 1;
2473 continue;
2474 }
2475
Igor Sysoev305a9d82005-12-26 17:07:48 +00002476 if (value[i].len == 0
2477 || (ch == '*' && (value[i].len < 3 || value[i].data[1] != '.'))
2478 || (ch == '.' && value[i].len < 2))
2479 {
2480 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2481 "server name \"%V\" is invalid", &value[i]);
2482 return NGX_CONF_ERROR;
2483 }
2484
2485 sn = ngx_array_push(&cscf->server_names);
Igor Sysoevc1571722005-03-19 12:38:37 +00002486 if (sn == NULL) {
Igor Sysoevc0edbcc2004-10-21 15:34:38 +00002487 return NGX_CONF_ERROR;
2488 }
Igor Sysoevaa3436c2003-05-30 14:27:59 +00002489
2490 sn->name.len = value[i].len;
2491 sn->name.data = value[i].data;
Igor Sysoev305a9d82005-12-26 17:07:48 +00002492 sn->core_srv_conf = cscf;
Igor Sysoevaa3436c2003-05-30 14:27:59 +00002493 }
Igor Sysoev13933252003-05-29 13:02:09 +00002494
Igor Sysoeva19a85e2003-01-28 15:56:37 +00002495 return NGX_CONF_OK;
2496}
Igor Sysoev9d639522003-07-07 06:11:50 +00002497
2498
Igor Sysoevaa828612005-02-09 14:31:07 +00002499static char *
2500ngx_http_core_root(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
Igor Sysoev10a543a2004-03-16 07:10:12 +00002501{
2502 ngx_http_core_loc_conf_t *lcf = conf;
2503
Igor Sysoev3ca233e2005-12-28 14:23:52 +00002504 ngx_str_t *value;
2505 ngx_uint_t alias, n;
2506 ngx_http_script_compile_t sc;
Igor Sysoev10a543a2004-03-16 07:10:12 +00002507
2508 alias = (cmd->name.len == sizeof("alias") - 1) ? 1 : 0;
2509
2510 if (lcf->root.data) {
Igor Sysoeva741f8d2004-03-30 20:31:58 +00002511
2512 /* the (ngx_uint_t) cast is required by gcc 2.7.2.3 */
2513
2514 if ((ngx_uint_t) lcf->alias == alias) {
Igor Sysoev10a543a2004-03-16 07:10:12 +00002515 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
Igor Sysoev1b735832004-11-11 14:07:14 +00002516 "\"%V\" directive is duplicate",
2517 &cmd->name);
Igor Sysoev10a543a2004-03-16 07:10:12 +00002518 } else {
2519 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
Igor Sysoev1b735832004-11-11 14:07:14 +00002520 "\"%V\" directive is duplicate, "
Igor Sysoev10a543a2004-03-16 07:10:12 +00002521 "\"%s\" directive is specified before",
Igor Sysoev1b735832004-11-11 14:07:14 +00002522 &cmd->name, lcf->alias ? "alias" : "root");
Igor Sysoev10a543a2004-03-16 07:10:12 +00002523 }
2524
2525 return NGX_CONF_ERROR;
2526 }
2527
2528 value = cf->args->elts;
2529
2530 lcf->alias = alias;
2531 lcf->root = value[1];
2532
Igor Sysoev71057632004-08-30 19:24:51 +00002533 if (!alias && lcf->root.data[lcf->root.len - 1] == '/') {
2534 lcf->root.len--;
2535 }
2536
Igor Sysoev8f125582006-07-28 15:16:17 +00002537 if (lcf->root.data[0] != '$') {
2538 if (ngx_conf_full_name(cf->cycle, &lcf->root) == NGX_ERROR) {
2539 return NGX_CONF_ERROR;
2540 }
Igor Sysoev34303462006-01-24 16:08:27 +00002541 }
2542
2543 n = ngx_http_script_variables_count(&lcf->root);
Igor Sysoev3ca233e2005-12-28 14:23:52 +00002544
2545 if (n == 0) {
2546 return NGX_CONF_OK;
2547 }
2548
2549 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
2550
2551 sc.cf = cf;
Igor Sysoev34303462006-01-24 16:08:27 +00002552 sc.source = &lcf->root;
Igor Sysoev3ca233e2005-12-28 14:23:52 +00002553 sc.lengths = &lcf->root_lengths;
2554 sc.values = &lcf->root_values;
2555 sc.variables = n;
2556 sc.complete_lengths = 1;
2557 sc.complete_values = 1;
2558
2559 if (ngx_http_script_compile(&sc) != NGX_OK) {
2560 return NGX_CONF_ERROR;
2561 }
2562
Igor Sysoev10a543a2004-03-16 07:10:12 +00002563 return NGX_CONF_OK;
2564}
2565
2566
Igor Sysoev94e32ce2006-04-07 14:08:04 +00002567static ngx_http_method_name_t ngx_methods_names[] = {
2568 { "GET", (uint32_t) ~NGX_HTTP_GET },
2569 { "HEAD", (uint32_t) ~NGX_HTTP_HEAD },
Igor Sysoev7f7846d2006-04-26 09:52:47 +00002570 { "POST", (uint32_t) ~NGX_HTTP_POST },
Igor Sysoev94e32ce2006-04-07 14:08:04 +00002571 { NULL, 0 }
2572};
2573
2574
2575static char *
2576ngx_http_core_limit_except(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
2577{
2578 ngx_http_core_loc_conf_t *clcf = conf;
2579
2580 char *rv;
2581 void *mconf;
2582 ngx_str_t *value;
2583 ngx_uint_t i;
2584 ngx_conf_t save;
2585 ngx_http_module_t *module;
2586 ngx_http_conf_ctx_t *ctx, *pctx;
2587 ngx_http_method_name_t *name;
2588 ngx_http_core_loc_conf_t *lcf, **clcfp;
2589
2590 if (clcf->limit_except) {
2591 return "duplicate";
2592 }
2593
2594 clcf->limit_except = 0xffffffff;
2595
2596 value = cf->args->elts;
2597
2598 for (i = 1; i < cf->args->nelts; i++) {
2599 for (name = ngx_methods_names; name->name; name++) {
2600
2601 if (ngx_strcasecmp(value[i].data, name->name) == 0) {
2602 clcf->limit_except &= name->method;
2603 goto next;
2604 }
2605 }
2606
2607 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2608 "invalid method \"%V\"", &value[i]);
2609 return NGX_CONF_ERROR;
2610
2611 next:
2612 continue;
2613 }
2614
2615 if (!(clcf->limit_except & NGX_HTTP_GET)) {
2616 clcf->limit_except &= (uint32_t) ~NGX_HTTP_HEAD;
2617 }
2618
2619 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t));
2620 if (ctx == NULL) {
2621 return NGX_CONF_ERROR;
2622 }
2623
2624 pctx = cf->ctx;
2625 ctx->main_conf = pctx->main_conf;
2626 ctx->srv_conf = pctx->srv_conf;
2627
2628 ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
2629 if (ctx->loc_conf == NULL) {
2630 return NGX_CONF_ERROR;
2631 }
2632
2633 for (i = 0; ngx_modules[i]; i++) {
2634 if (ngx_modules[i]->type != NGX_HTTP_MODULE) {
2635 continue;
2636 }
2637
2638 module = ngx_modules[i]->ctx;
2639
2640 if (module->create_loc_conf) {
2641
2642 mconf = module->create_loc_conf(cf);
2643 if (mconf == NULL) {
2644 return NGX_CONF_ERROR;
2645 }
2646
2647 ctx->loc_conf[ngx_modules[i]->ctx_index] = mconf;
2648 }
2649 }
2650
2651
2652 lcf = ctx->loc_conf[ngx_http_core_module.ctx_index];
2653 clcf->limit_except_loc_conf = ctx->loc_conf;
2654 lcf->loc_conf = ctx->loc_conf;
2655 lcf->name = clcf->name;
2656 lcf->noname = 1;
2657
2658 if (clcf->locations.elts == NULL) {
2659 if (ngx_array_init(&clcf->locations, cf->pool, 4, sizeof(void *))
2660 == NGX_ERROR)
2661 {
2662 return NGX_CONF_ERROR;
2663 }
2664 }
2665
2666 clcfp = ngx_array_push(&clcf->locations);
2667 if (clcfp == NULL) {
2668 return NGX_CONF_ERROR;
2669 }
2670
2671 *clcfp = lcf;
2672
2673
2674 save = *cf;
2675 cf->ctx = ctx;
2676 cf->cmd_type = NGX_HTTP_LMT_CONF;
2677
2678 rv = ngx_conf_parse(cf, NULL);
2679
2680 *cf = save;
2681
2682 return rv;
2683}
2684
2685
Igor Sysoevaa828612005-02-09 14:31:07 +00002686static char *
2687ngx_http_core_error_page(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
Igor Sysoev74e95c22003-11-09 20:03:38 +00002688{
2689 ngx_http_core_loc_conf_t *lcf = conf;
2690
Igor Sysoev08e63d42006-08-14 15:09:38 +00002691 ngx_int_t overwrite;
2692 ngx_str_t *value, uri;
2693 ngx_uint_t i, n, nvar;
2694 ngx_array_t *uri_lengths, *uri_values;
2695 ngx_http_err_page_t *err;
2696 ngx_http_script_compile_t sc;
Igor Sysoev74e95c22003-11-09 20:03:38 +00002697
2698 if (lcf->error_pages == NULL) {
Igor Sysoevaa828612005-02-09 14:31:07 +00002699 lcf->error_pages = ngx_array_create(cf->pool, 4,
Igor Sysoev74e95c22003-11-09 20:03:38 +00002700 sizeof(ngx_http_err_page_t));
2701 if (lcf->error_pages == NULL) {
2702 return NGX_CONF_ERROR;
2703 }
2704 }
2705
2706 value = cf->args->elts;
2707
Igor Sysoev732a2712004-04-21 18:54:33 +00002708 i = cf->args->nelts - 2;
2709
2710 if (value[i].data[0] == '=') {
2711 if (i == 1) {
2712 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
Igor Sysoev1b735832004-11-11 14:07:14 +00002713 "invalid value \"%V\"", &value[i]);
Igor Sysoev732a2712004-04-21 18:54:33 +00002714 return NGX_CONF_ERROR;
2715 }
2716
Igor Sysoeva2573672005-10-05 14:46:21 +00002717 if (value[i].len > 1) {
2718 overwrite = ngx_atoi(&value[i].data[1], value[i].len - 1);
Igor Sysoev732a2712004-04-21 18:54:33 +00002719
Igor Sysoeva2573672005-10-05 14:46:21 +00002720 if (overwrite == NGX_ERROR) {
2721 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2722 "invalid value \"%V\"", &value[i]);
2723 return NGX_CONF_ERROR;
2724 }
2725
2726 } else {
2727 overwrite = 0;
Igor Sysoev732a2712004-04-21 18:54:33 +00002728 }
2729
2730 n = 2;
2731
2732 } else {
Igor Sysoeva2573672005-10-05 14:46:21 +00002733 overwrite = -1;
Igor Sysoev732a2712004-04-21 18:54:33 +00002734 n = 1;
2735 }
2736
Igor Sysoev08e63d42006-08-14 15:09:38 +00002737 uri = value[cf->args->nelts - 1];
2738 uri_lengths = NULL;
2739 uri_values = NULL;
2740
2741 nvar = ngx_http_script_variables_count(&uri);
2742
2743 if (nvar) {
2744 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
2745
2746 sc.cf = cf;
2747 sc.source = &uri;
2748 sc.lengths = &uri_lengths;
2749 sc.values = &uri_values;
2750 sc.variables = nvar;
2751 sc.complete_lengths = 1;
2752 sc.complete_values = 1;
2753
2754 if (ngx_http_script_compile(&sc) != NGX_OK) {
2755 return NGX_CONF_ERROR;
2756 }
2757 }
2758
Igor Sysoev732a2712004-04-21 18:54:33 +00002759 for (i = 1; i < cf->args->nelts - n; i++) {
Igor Sysoevc1571722005-03-19 12:38:37 +00002760 err = ngx_array_push(lcf->error_pages);
2761 if (err == NULL) {
Igor Sysoev732a2712004-04-21 18:54:33 +00002762 return NGX_CONF_ERROR;
2763 }
2764
Igor Sysoev3f4685f2004-04-25 20:13:21 +00002765 err->status = ngx_atoi(value[i].data, value[i].len);
Igor Sysoevaa828612005-02-09 14:31:07 +00002766
Igor Sysoev3f4685f2004-04-25 20:13:21 +00002767 if (err->status == NGX_ERROR) {
Igor Sysoev74e95c22003-11-09 20:03:38 +00002768 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
Igor Sysoev1b735832004-11-11 14:07:14 +00002769 "invalid value \"%V\"", &value[i]);
Igor Sysoev74e95c22003-11-09 20:03:38 +00002770 return NGX_CONF_ERROR;
2771 }
2772
Igor Sysoev3f4685f2004-04-25 20:13:21 +00002773 if (err->status < 400 || err->status > 599) {
Igor Sysoev74e95c22003-11-09 20:03:38 +00002774 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
Igor Sysoev1b735832004-11-11 14:07:14 +00002775 "value \"%V\" must be between 400 and 599",
2776 &value[i]);
Igor Sysoev74e95c22003-11-09 20:03:38 +00002777 return NGX_CONF_ERROR;
2778 }
2779
Igor Sysoeva2573672005-10-05 14:46:21 +00002780 err->overwrite = (overwrite >= 0) ? overwrite : err->status;
2781
Igor Sysoev08e63d42006-08-14 15:09:38 +00002782 err->uri = uri;
2783 err->uri_lengths = uri_lengths;
2784 err->uri_values = uri_values;
Igor Sysoev74e95c22003-11-09 20:03:38 +00002785 }
2786
2787 return NGX_CONF_OK;
2788}
2789
2790
Igor Sysoevaa828612005-02-09 14:31:07 +00002791static char *
Igor Sysoev899b44e2005-05-12 14:58:06 +00002792ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
2793{
2794 ngx_http_core_loc_conf_t *lcf = conf;
2795
2796 lcf->err_log = ngx_log_create_errlog(cf->cycle, cf->args);
2797 if (lcf->err_log == NULL) {
2798 return NGX_CONF_ERROR;
2799 }
2800
2801 return ngx_set_error_log_levels(cf, lcf->err_log);
2802}
2803
2804
2805static char *
Igor Sysoevaa828612005-02-09 14:31:07 +00002806ngx_http_core_keepalive(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
Igor Sysoev307c3ad2004-09-17 16:07:35 +00002807{
2808 ngx_http_core_loc_conf_t *lcf = conf;
2809
2810 ngx_str_t *value;
2811
2812 if (lcf->keepalive_timeout != NGX_CONF_UNSET_MSEC) {
2813 return "is duplicate";
2814 }
2815
2816 value = cf->args->elts;
2817
2818 lcf->keepalive_timeout = ngx_parse_time(&value[1], 0);
Igor Sysoevaa828612005-02-09 14:31:07 +00002819
Igor Sysoev307c3ad2004-09-17 16:07:35 +00002820 if (lcf->keepalive_timeout == (ngx_msec_t) NGX_ERROR) {
2821 return "invalid value";
2822 }
2823
2824 if (lcf->keepalive_timeout == (ngx_msec_t) NGX_PARSE_LARGE_TIME) {
2825 return "value must be less than 597 hours";
2826 }
2827
2828 if (cf->args->nelts == 2) {
2829 return NGX_CONF_OK;
2830 }
2831
2832 lcf->keepalive_header = ngx_parse_time(&value[2], 1);
Igor Sysoevaa828612005-02-09 14:31:07 +00002833
Igor Sysoev307c3ad2004-09-17 16:07:35 +00002834 if (lcf->keepalive_header == NGX_ERROR) {
2835 return "invalid value";
2836 }
2837
2838 if (lcf->keepalive_header == NGX_PARSE_LARGE_TIME) {
2839 return "value must be less than 68 years";
2840 }
2841
2842 return NGX_CONF_OK;
2843}
2844
2845
Igor Sysoevaa828612005-02-09 14:31:07 +00002846static char *
Igor Sysoev899b44e2005-05-12 14:58:06 +00002847ngx_http_core_internal(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
Igor Sysoev9d639522003-07-07 06:11:50 +00002848{
2849 ngx_http_core_loc_conf_t *lcf = conf;
2850
Igor Sysoev899b44e2005-05-12 14:58:06 +00002851 if (lcf->internal != NGX_CONF_UNSET) {
2852 return "is duplicate";
Igor Sysoev03420a62004-01-20 20:40:08 +00002853 }
Igor Sysoev9d639522003-07-07 06:11:50 +00002854
Igor Sysoev899b44e2005-05-12 14:58:06 +00002855 lcf->internal = 1;
2856
2857 return NGX_CONF_OK;
Igor Sysoev9d639522003-07-07 06:11:50 +00002858}
Igor Sysoevb5faed22003-10-29 08:30:44 +00002859
2860
Igor Sysoevaa828612005-02-09 14:31:07 +00002861static char *
2862ngx_http_core_lowat_check(ngx_conf_t *cf, void *post, void *data)
Igor Sysoevb5faed22003-10-29 08:30:44 +00002863{
Igor Sysoevc0edbcc2004-10-21 15:34:38 +00002864#if (NGX_FREEBSD)
Igor Sysoev42b12b32004-12-02 18:40:46 +00002865 ssize_t *np = data;
Igor Sysoev924bd792004-10-11 15:07:03 +00002866
Igor Sysoev08e63d42006-08-14 15:09:38 +00002867 if ((u_long) *np >= ngx_freebsd_net_inet_tcp_sendspace) {
Igor Sysoevb5faed22003-10-29 08:30:44 +00002868 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2869 "\"send_lowat\" must be less than %d "
2870 "(sysctl net.inet.tcp.sendspace)",
2871 ngx_freebsd_net_inet_tcp_sendspace);
2872
2873 return NGX_CONF_ERROR;
2874 }
2875
Igor Sysoevf6906042004-11-25 16:17:31 +00002876#elif !(NGX_HAVE_SO_SNDLOWAT)
Igor Sysoev42b12b32004-12-02 18:40:46 +00002877 ssize_t *np = data;
Igor Sysoevb5faed22003-10-29 08:30:44 +00002878
2879 ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
2880 "\"send_lowat\" is not supported, ignored");
2881
Igor Sysoev924bd792004-10-11 15:07:03 +00002882 *np = 0;
2883
Igor Sysoevb5faed22003-10-29 08:30:44 +00002884#endif
2885
2886 return NGX_CONF_OK;
2887}