0
|
1
|
|
2 /*
|
|
3 * Copyright (C) Igor Sysoev
|
|
4 */
|
|
5
|
|
6
|
|
7 #ifndef _NGX_HTTP_CORE_H_INCLUDED_
|
|
8 #define _NGX_HTTP_CORE_H_INCLUDED_
|
|
9
|
|
10
|
406
|
11 #include <ngx_config.h>
|
|
12 #include <ngx_core.h>
|
0
|
13 #include <ngx_http.h>
|
|
14
|
|
15
|
358
|
16 #define NGX_HTTP_GZIP_PROXIED_OFF 0x0002
|
|
17 #define NGX_HTTP_GZIP_PROXIED_EXPIRED 0x0004
|
|
18 #define NGX_HTTP_GZIP_PROXIED_NO_CACHE 0x0008
|
|
19 #define NGX_HTTP_GZIP_PROXIED_NO_STORE 0x0010
|
|
20 #define NGX_HTTP_GZIP_PROXIED_PRIVATE 0x0020
|
|
21 #define NGX_HTTP_GZIP_PROXIED_NO_LM 0x0040
|
|
22 #define NGX_HTTP_GZIP_PROXIED_NO_ETAG 0x0080
|
|
23 #define NGX_HTTP_GZIP_PROXIED_AUTH 0x0100
|
|
24 #define NGX_HTTP_GZIP_PROXIED_ANY 0x0200
|
|
25
|
|
26
|
520
|
27 #define NGX_HTTP_AIO_OFF 0
|
|
28 #define NGX_HTTP_AIO_ON 1
|
|
29 #define NGX_HTTP_AIO_SENDFILE 2
|
|
30
|
|
31
|
362
|
32 #define NGX_HTTP_SATISFY_ALL 0
|
|
33 #define NGX_HTTP_SATISFY_ANY 1
|
|
34
|
|
35
|
444
|
36 #define NGX_HTTP_IMS_OFF 0
|
|
37 #define NGX_HTTP_IMS_EXACT 1
|
|
38 #define NGX_HTTP_IMS_BEFORE 2
|
|
39
|
|
40
|
378
|
41 typedef struct ngx_http_location_tree_node_s ngx_http_location_tree_node_t;
|
|
42 typedef struct ngx_http_core_loc_conf_s ngx_http_core_loc_conf_t;
|
|
43
|
|
44
|
0
|
45 typedef struct {
|
538
|
46 u_char sockaddr[NGX_SOCKADDRLEN];
|
|
47 socklen_t socklen;
|
|
48
|
|
49 unsigned set:1;
|
72
|
50 unsigned default_server:1;
|
|
51 unsigned bind:1;
|
448
|
52 unsigned wildcard:1;
|
404
|
53 #if (NGX_HTTP_SSL)
|
|
54 unsigned ssl:1;
|
|
55 #endif
|
460
|
56 #if (NGX_HAVE_INET6 && defined IPV6_V6ONLY)
|
|
57 unsigned ipv6only:2;
|
|
58 #endif
|
72
|
59
|
|
60 int backlog;
|
112
|
61 int rcvbuf;
|
|
62 int sndbuf;
|
72
|
63
|
|
64 #if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER)
|
|
65 char *accept_filter;
|
|
66 #endif
|
|
67 #if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT)
|
|
68 ngx_uint_t deferred_accept;
|
|
69 #endif
|
|
70
|
448
|
71 u_char addr[NGX_SOCKADDR_STRLEN + 1];
|
538
|
72 } ngx_http_listen_opt_t;
|
0
|
73
|
|
74
|
|
75 typedef enum {
|
122
|
76 NGX_HTTP_POST_READ_PHASE = 0,
|
0
|
77
|
122
|
78 NGX_HTTP_SERVER_REWRITE_PHASE,
|
230
|
79
|
122
|
80 NGX_HTTP_FIND_CONFIG_PHASE,
|
38
|
81 NGX_HTTP_REWRITE_PHASE,
|
230
|
82 NGX_HTTP_POST_REWRITE_PHASE,
|
0
|
83
|
130
|
84 NGX_HTTP_PREACCESS_PHASE,
|
|
85
|
0
|
86 NGX_HTTP_ACCESS_PHASE,
|
230
|
87 NGX_HTTP_POST_ACCESS_PHASE,
|
|
88
|
430
|
89 NGX_HTTP_TRY_FILES_PHASE,
|
0
|
90 NGX_HTTP_CONTENT_PHASE,
|
|
91
|
130
|
92 NGX_HTTP_LOG_PHASE
|
0
|
93 } ngx_http_phases;
|
|
94
|
230
|
95 typedef struct ngx_http_phase_handler_s ngx_http_phase_handler_t;
|
|
96
|
|
97 typedef ngx_int_t (*ngx_http_phase_handler_pt)(ngx_http_request_t *r,
|
|
98 ngx_http_phase_handler_t *ph);
|
|
99
|
|
100 struct ngx_http_phase_handler_s {
|
|
101 ngx_http_phase_handler_pt checker;
|
|
102 ngx_http_handler_pt handler;
|
|
103 ngx_uint_t next;
|
|
104 };
|
|
105
|
|
106
|
|
107 typedef struct {
|
|
108 ngx_http_phase_handler_t *handlers;
|
|
109 ngx_uint_t server_rewrite_index;
|
324
|
110 ngx_uint_t location_rewrite_index;
|
230
|
111 } ngx_http_phase_engine_t;
|
|
112
|
0
|
113
|
|
114 typedef struct {
|
26
|
115 ngx_array_t handlers;
|
0
|
116 } ngx_http_phase_t;
|
|
117
|
|
118
|
|
119 typedef struct {
|
34
|
120 ngx_array_t servers; /* ngx_http_core_srv_conf_t */
|
26
|
121
|
230
|
122 ngx_http_phase_engine_t phase_engine;
|
0
|
123
|
198
|
124 ngx_hash_t headers_in_hash;
|
160
|
125
|
|
126 ngx_hash_t variables_hash;
|
|
127
|
|
128 ngx_array_t variables; /* ngx_http_variable_t */
|
56
|
129
|
142
|
130 ngx_uint_t server_names_hash_max_size;
|
|
131 ngx_uint_t server_names_hash_bucket_size;
|
34
|
132
|
160
|
133 ngx_uint_t variables_hash_max_size;
|
|
134 ngx_uint_t variables_hash_bucket_size;
|
|
135
|
|
136 ngx_hash_keys_arrays_t *variables_keys;
|
230
|
137
|
538
|
138 ngx_array_t *ports;
|
|
139
|
430
|
140 ngx_uint_t try_files; /* unsigned try_files:1 */
|
|
141
|
230
|
142 ngx_http_phase_t phases[NGX_HTTP_LOG_PHASE + 1];
|
0
|
143 } ngx_http_core_main_conf_t;
|
|
144
|
|
145
|
|
146 typedef struct {
|
34
|
147 /* array of the ngx_http_server_name_t, "server_name" directive */
|
378
|
148 ngx_array_t server_names;
|
0
|
149
|
|
150 /* server ctx */
|
378
|
151 ngx_http_conf_ctx_t *ctx;
|
0
|
152
|
378
|
153 ngx_str_t server_name;
|
142
|
154
|
378
|
155 size_t connection_pool_size;
|
|
156 size_t request_pool_size;
|
|
157 size_t client_header_buffer_size;
|
0
|
158
|
378
|
159 ngx_bufs_t large_client_header_buffers;
|
0
|
160
|
378
|
161 ngx_msec_t client_header_timeout;
|
0
|
162
|
378
|
163 ngx_flag_t ignore_invalid_headers;
|
|
164 ngx_flag_t merge_slashes;
|
412
|
165 ngx_flag_t underscores_in_headers;
|
378
|
166
|
538
|
167 unsigned listen:1;
|
|
168 #if (NGX_PCRE)
|
|
169 unsigned captures:1;
|
|
170 #endif
|
|
171
|
378
|
172 ngx_http_core_loc_conf_t **named_locations;
|
0
|
173 } ngx_http_core_srv_conf_t;
|
|
174
|
|
175
|
|
176 /* list of structures to find core_srv_conf quickly at run time */
|
|
177
|
142
|
178
|
|
179 typedef struct {
|
|
180 /* the default server configuration for this address:port */
|
538
|
181 ngx_http_core_srv_conf_t *default_server;
|
326
|
182
|
478
|
183 ngx_http_virtual_names_t *virtual_names;
|
|
184
|
404
|
185 #if (NGX_HTTP_SSL)
|
|
186 ngx_uint_t ssl; /* unsigned ssl:1; */
|
|
187 #endif
|
448
|
188 } ngx_http_addr_conf_t;
|
|
189
|
|
190
|
|
191 typedef struct {
|
|
192 in_addr_t addr;
|
|
193 ngx_http_addr_conf_t conf;
|
142
|
194 } ngx_http_in_addr_t;
|
|
195
|
|
196
|
448
|
197 #if (NGX_HAVE_INET6)
|
|
198
|
|
199 typedef struct {
|
|
200 struct in6_addr addr6;
|
|
201 ngx_http_addr_conf_t conf;
|
|
202 } ngx_http_in6_addr_t;
|
|
203
|
|
204 #endif
|
|
205
|
|
206
|
0
|
207 typedef struct {
|
448
|
208 /* ngx_http_in_addr_t or ngx_http_in6_addr_t */
|
|
209 void *addrs;
|
142
|
210 ngx_uint_t naddrs;
|
448
|
211 } ngx_http_port_t;
|
0
|
212
|
|
213
|
142
|
214 typedef struct {
|
448
|
215 ngx_int_t family;
|
142
|
216 in_port_t port;
|
448
|
217 ngx_array_t addrs; /* array of ngx_http_conf_addr_t */
|
|
218 } ngx_http_conf_port_t;
|
142
|
219
|
|
220
|
|
221 typedef struct {
|
538
|
222 ngx_http_listen_opt_t opt;
|
26
|
223
|
142
|
224 ngx_hash_t hash;
|
312
|
225 ngx_hash_wildcard_t *wc_head;
|
|
226 ngx_hash_wildcard_t *wc_tail;
|
142
|
227
|
326
|
228 #if (NGX_PCRE)
|
|
229 ngx_uint_t nregex;
|
|
230 ngx_http_server_name_t *regex;
|
|
231 #endif
|
|
232
|
26
|
233 /* the default server configuration for this address:port */
|
538
|
234 ngx_http_core_srv_conf_t *default_server;
|
|
235 ngx_array_t servers; /* array of ngx_http_core_srv_conf_t */
|
448
|
236 } ngx_http_conf_addr_t;
|
0
|
237
|
|
238
|
326
|
239 struct ngx_http_server_name_s {
|
|
240 #if (NGX_PCRE)
|
|
241 ngx_regex_t *regex;
|
|
242 #endif
|
538
|
243 ngx_http_core_srv_conf_t *server; /* virtual name server conf */
|
0
|
244 ngx_str_t name;
|
326
|
245 };
|
0
|
246
|
|
247
|
|
248 typedef struct {
|
222
|
249 ngx_int_t status;
|
|
250 ngx_int_t overwrite;
|
464
|
251 ngx_http_complex_value_t value;
|
372
|
252 ngx_str_t args;
|
0
|
253 } ngx_http_err_page_t;
|
|
254
|
|
255
|
430
|
256 typedef struct {
|
|
257 ngx_array_t *lengths;
|
|
258 ngx_array_t *values;
|
|
259 ngx_str_t name;
|
478
|
260
|
|
261 unsigned code:10;
|
|
262 unsigned test_dir:1;
|
430
|
263 } ngx_http_try_file_t;
|
|
264
|
|
265
|
0
|
266 struct ngx_http_core_loc_conf_s {
|
|
267 ngx_str_t name; /* location name */
|
|
268
|
4
|
269 #if (NGX_PCRE)
|
0
|
270 ngx_regex_t *regex;
|
456
|
271
|
|
272 unsigned captures:1;
|
0
|
273 #endif
|
|
274
|
324
|
275 unsigned noname:1; /* "if () {}" block or limit_except */
|
|
276 unsigned named:1;
|
34
|
277
|
0
|
278 unsigned exact_match:1;
|
16
|
279 unsigned noregex:1;
|
|
280
|
0
|
281 unsigned auto_redirect:1;
|
|
282 unsigned alias:1;
|
400
|
283 #if (NGX_HTTP_GZIP)
|
|
284 unsigned gzip_disable_msie6:2;
|
|
285 #endif
|
0
|
286
|
378
|
287 ngx_http_location_tree_node_t *static_locations;
|
456
|
288 #if (NGX_PCRE)
|
378
|
289 ngx_http_core_loc_conf_t **regex_locations;
|
456
|
290 #endif
|
0
|
291
|
|
292 /* pointer to the modules' loc_conf */
|
378
|
293 void **loc_conf;
|
0
|
294
|
180
|
295 uint32_t limit_except;
|
378
|
296 void **limit_except_loc_conf;
|
180
|
297
|
0
|
298 ngx_http_handler_pt handler;
|
|
299
|
126
|
300 ngx_str_t root; /* root, alias */
|
|
301 ngx_str_t post_action;
|
|
302
|
144
|
303 ngx_array_t *root_lengths;
|
|
304 ngx_array_t *root_values;
|
|
305
|
138
|
306 ngx_array_t *types;
|
|
307 ngx_hash_t types_hash;
|
|
308 ngx_str_t default_type;
|
|
309
|
212
|
310 off_t client_max_body_size; /* client_max_body_size */
|
390
|
311 off_t directio; /* directio */
|
518
|
312 off_t directio_alignment; /* directio_alignment */
|
212
|
313
|
0
|
314 size_t client_body_buffer_size; /* client_body_buffer_size */
|
|
315 size_t send_lowat; /* send_lowat */
|
|
316 size_t postpone_output; /* postpone_output */
|
|
317 size_t limit_rate; /* limit_rate */
|
496
|
318 size_t limit_rate_after; /* limit_rate_after */
|
300
|
319 size_t sendfile_max_chunk; /* sendfile_max_chunk */
|
532
|
320 size_t read_ahead; /* read_ahead */
|
0
|
321
|
|
322 ngx_msec_t client_body_timeout; /* client_body_timeout */
|
|
323 ngx_msec_t send_timeout; /* send_timeout */
|
|
324 ngx_msec_t keepalive_timeout; /* keepalive_timeout */
|
|
325 ngx_msec_t lingering_time; /* lingering_time */
|
|
326 ngx_msec_t lingering_timeout; /* lingering_timeout */
|
348
|
327 ngx_msec_t resolver_timeout; /* resolver_timeout */
|
|
328
|
|
329 ngx_resolver_t *resolver; /* resolver */
|
0
|
330
|
|
331 time_t keepalive_header; /* keepalive_timeout */
|
|
332
|
496
|
333 ngx_uint_t keepalive_requests; /* keepalive_requests */
|
362
|
334 ngx_uint_t satisfy; /* satisfy */
|
424
|
335 ngx_uint_t if_modified_since; /* if_modified_since */
|
492
|
336 ngx_uint_t client_body_in_file_only; /* client_body_in_file_only */
|
362
|
337
|
492
|
338 ngx_flag_t client_body_in_single_buffer;
|
|
339 /* client_body_in_singe_buffer */
|
58
|
340 ngx_flag_t internal; /* internal */
|
0
|
341 ngx_flag_t sendfile; /* sendfile */
|
518
|
342 #if (NGX_HAVE_FILE_AIO)
|
|
343 ngx_flag_t aio; /* aio */
|
|
344 #endif
|
0
|
345 ngx_flag_t tcp_nopush; /* tcp_nopush */
|
2
|
346 ngx_flag_t tcp_nodelay; /* tcp_nodelay */
|
0
|
347 ngx_flag_t reset_timedout_connection; /* reset_timedout_connection */
|
362
|
348 ngx_flag_t server_name_in_redirect; /* server_name_in_redirect */
|
70
|
349 ngx_flag_t port_in_redirect; /* port_in_redirect */
|
0
|
350 ngx_flag_t msie_padding; /* msie_padding */
|
228
|
351 ngx_flag_t msie_refresh; /* msie_refresh */
|
76
|
352 ngx_flag_t log_not_found; /* log_not_found */
|
412
|
353 ngx_flag_t log_subrequest; /* log_subrequest */
|
228
|
354 ngx_flag_t recursive_error_pages; /* recursive_error_pages */
|
342
|
355 ngx_flag_t server_tokens; /* server_tokens */
|
0
|
356
|
358
|
357 #if (NGX_HTTP_GZIP)
|
|
358 ngx_flag_t gzip_vary; /* gzip_vary */
|
|
359
|
|
360 ngx_uint_t gzip_http_version; /* gzip_http_version */
|
|
361 ngx_uint_t gzip_proxied; /* gzip_proxied */
|
|
362
|
|
363 #if (NGX_PCRE)
|
|
364 ngx_array_t *gzip_disable; /* gzip_disable */
|
|
365 #endif
|
|
366 #endif
|
|
367
|
0
|
368 ngx_array_t *error_pages; /* error_page */
|
430
|
369 ngx_http_try_file_t *try_files; /* try_files */
|
0
|
370
|
28
|
371 ngx_path_t *client_body_temp_path; /* client_body_temp_path */
|
|
372
|
332
|
373 ngx_open_file_cache_t *open_file_cache;
|
358
|
374 time_t open_file_cache_valid;
|
|
375 ngx_uint_t open_file_cache_min_uses;
|
332
|
376 ngx_flag_t open_file_cache_errors;
|
|
377 ngx_flag_t open_file_cache_events;
|
0
|
378
|
484
|
379 ngx_log_t *error_log;
|
0
|
380
|
138
|
381 ngx_uint_t types_hash_max_size;
|
|
382 ngx_uint_t types_hash_bucket_size;
|
|
383
|
378
|
384 ngx_queue_t *locations;
|
|
385
|
34
|
386 #if 0
|
0
|
387 ngx_http_core_loc_conf_t *prev_location;
|
34
|
388 #endif
|
0
|
389 };
|
|
390
|
|
391
|
378
|
392 typedef struct {
|
|
393 ngx_queue_t queue;
|
|
394 ngx_http_core_loc_conf_t *exact;
|
|
395 ngx_http_core_loc_conf_t *inclusive;
|
|
396 ngx_str_t *name;
|
|
397 u_char *file_name;
|
|
398 ngx_uint_t line;
|
|
399 ngx_queue_t list;
|
|
400 } ngx_http_location_queue_t;
|
|
401
|
|
402
|
|
403 struct ngx_http_location_tree_node_s {
|
|
404 ngx_http_location_tree_node_t *left;
|
|
405 ngx_http_location_tree_node_t *right;
|
|
406 ngx_http_location_tree_node_t *tree;
|
|
407
|
|
408 ngx_http_core_loc_conf_t *exact;
|
|
409 ngx_http_core_loc_conf_t *inclusive;
|
|
410
|
|
411 u_char auto_redirect;
|
|
412 u_char len;
|
|
413 u_char name[1];
|
|
414 };
|
|
415
|
|
416
|
230
|
417 void ngx_http_core_run_phases(ngx_http_request_t *r);
|
|
418 ngx_int_t ngx_http_core_generic_phase(ngx_http_request_t *r,
|
|
419 ngx_http_phase_handler_t *ph);
|
|
420 ngx_int_t ngx_http_core_find_config_phase(ngx_http_request_t *r,
|
|
421 ngx_http_phase_handler_t *ph);
|
|
422 ngx_int_t ngx_http_core_post_rewrite_phase(ngx_http_request_t *r,
|
|
423 ngx_http_phase_handler_t *ph);
|
|
424 ngx_int_t ngx_http_core_access_phase(ngx_http_request_t *r,
|
|
425 ngx_http_phase_handler_t *ph);
|
|
426 ngx_int_t ngx_http_core_post_access_phase(ngx_http_request_t *r,
|
|
427 ngx_http_phase_handler_t *ph);
|
430
|
428 ngx_int_t ngx_http_core_try_files_phase(ngx_http_request_t *r,
|
|
429 ngx_http_phase_handler_t *ph);
|
230
|
430 ngx_int_t ngx_http_core_content_phase(ngx_http_request_t *r,
|
|
431 ngx_http_phase_handler_t *ph);
|
0
|
432
|
392
|
433
|
|
434 void *ngx_http_test_content_type(ngx_http_request_t *r, ngx_hash_t *types_hash);
|
0
|
435 ngx_int_t ngx_http_set_content_type(ngx_http_request_t *r);
|
508
|
436 void ngx_http_set_exten(ngx_http_request_t *r);
|
106
|
437 u_char *ngx_http_map_uri_to_path(ngx_http_request_t *r, ngx_str_t *name,
|
248
|
438 size_t *root_length, size_t reserved);
|
88
|
439 ngx_int_t ngx_http_auth_basic_user(ngx_http_request_t *r);
|
358
|
440 #if (NGX_HTTP_GZIP)
|
|
441 ngx_int_t ngx_http_gzip_ok(ngx_http_request_t *r);
|
|
442 #endif
|
|
443
|
0
|
444
|
58
|
445 ngx_int_t ngx_http_subrequest(ngx_http_request_t *r,
|
244
|
446 ngx_str_t *uri, ngx_str_t *args, ngx_http_request_t **sr,
|
248
|
447 ngx_http_post_subrequest_t *psr, ngx_uint_t flags);
|
0
|
448 ngx_int_t ngx_http_internal_redirect(ngx_http_request_t *r,
|
48
|
449 ngx_str_t *uri, ngx_str_t *args);
|
324
|
450 ngx_int_t ngx_http_named_location(ngx_http_request_t *r, ngx_str_t *name);
|
|
451
|
34
|
452
|
118
|
453 ngx_http_cleanup_t *ngx_http_cleanup_add(ngx_http_request_t *r, size_t size);
|
|
454
|
0
|
455
|
|
456 typedef ngx_int_t (*ngx_http_output_header_filter_pt)(ngx_http_request_t *r);
|
|
457 typedef ngx_int_t (*ngx_http_output_body_filter_pt)
|
48
|
458 (ngx_http_request_t *r, ngx_chain_t *chain);
|
0
|
459
|
|
460
|
|
461 ngx_int_t ngx_http_output_filter(ngx_http_request_t *r, ngx_chain_t *chain);
|
|
462 ngx_int_t ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *chain);
|
|
463
|
|
464
|
126
|
465 extern ngx_module_t ngx_http_core_module;
|
|
466
|
|
467 extern ngx_uint_t ngx_http_max_module;
|
|
468
|
480
|
469 extern ngx_str_t ngx_http_core_get_method;
|
|
470
|
126
|
471
|
|
472 #define ngx_http_clear_content_length(r) \
|
|
473 \
|
|
474 r->headers_out.content_length_n = -1; \
|
|
475 if (r->headers_out.content_length) { \
|
|
476 r->headers_out.content_length->hash = 0; \
|
|
477 r->headers_out.content_length = NULL; \
|
|
478 }
|
|
479 \
|
|
480 #define ngx_http_clear_accept_ranges(r) \
|
|
481 \
|
130
|
482 r->allow_ranges = 0; \
|
126
|
483 if (r->headers_out.accept_ranges) { \
|
378
|
484 r->headers_out.accept_ranges->hash = 0; \
|
126
|
485 r->headers_out.accept_ranges = NULL; \
|
|
486 }
|
|
487
|
|
488 #define ngx_http_clear_last_modified(r) \
|
|
489 \
|
|
490 r->headers_out.last_modified_time = -1; \
|
|
491 if (r->headers_out.last_modified) { \
|
|
492 r->headers_out.last_modified->hash = 0; \
|
|
493 r->headers_out.last_modified = NULL; \
|
|
494 }
|
|
495
|
|
496
|
0
|
497 #endif /* _NGX_HTTP_CORE_H_INCLUDED_ */
|