Mercurial > hg > nginx-vendor-0-7
comparison src/http/ngx_http_core_module.c @ 58:b55cbf18157e NGINX_0_1_29
nginx 0.1.29
*) Feature: the ngx_http_ssi_module supports "include virtual" command.
*) Feature: the ngx_http_ssi_module supports the condition command like
'if expr="$NAME"' and "else" and "endif" commands. Only one nested
level is supported.
*) Feature: the ngx_http_ssi_module supports the DATE_LOCAL and
DATE_GMT variables and "config timefmt" command.
*) Feature: the "ssi_ignore_recycled_buffers" directive.
*) Bugfix: the "echo" command did not show the default value for the
empty QUERY_STRING variable.
*) Change: the ngx_http_proxy_module was rewritten.
*) Feature: the "proxy_redirect", "proxy_pass_request_headers",
"proxy_pass_request_body", and "proxy_method" directives.
*) Feature: the "proxy_set_header" directive. The "proxy_x_var" was
canceled and must be replaced with the proxy_set_header directive.
*) Change: the "proxy_preserve_host" is canceled and must be replaced
with the "proxy_set_header Host $host" and the "proxy_redirect off"
directives, the "proxy_set_header Host $host:$proxy_port" directive
and the appropriate proxy_redirect directives.
*) Change: the "proxy_set_x_real_ip" is canceled and must be replaced
with the "proxy_set_header X-Real-IP $remote_addr" directive.
*) Change: the "proxy_add_x_forwarded_for" is canceled and must be
replaced with
the "proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for"
directive.
*) Change: the "proxy_set_x_url" is canceled and must be replaced with
the "proxy_set_header X-URL http://$host:$server_port$request_uri"
directive.
*) Feature: the "fastcgi_param" directive.
*) Change: the "fastcgi_root", "fastcgi_set_var" and "fastcgi_params"
directive are canceled and must be replaced with the fastcgi_param
directives.
*) Feature: the "index" directive can use the variables.
*) Feature: the "index" directive can be used at http and server levels.
*) Change: the last index only in the "index" directive can be absolute.
*) Feature: the "rewrite" directive can use the variables.
*) Feature: the "internal" directive.
*) Feature: the CONTENT_LENGTH, CONTENT_TYPE, REMOTE_PORT, SERVER_ADDR,
SERVER_PORT, SERVER_PROTOCOL, DOCUMENT_ROOT, SERVER_NAME,
REQUEST_METHOD, REQUEST_URI, and REMOTE_USER variables.
*) Change: nginx now passes the invalid lines in a client request
headers or a backend response header.
*) Bugfix: if the backend did not transfer response for a long time and
the "send_timeout" was less than "proxy_read_timeout", then nginx
returned the 408 response.
*) Bugfix: the segmentation fault was occurred if the backend sent an
invalid line in response header; bug appeared in 0.1.26.
*) Bugfix: the segmentation fault may occurred in FastCGI fault
tolerance configuration.
*) Bugfix: the "expires" directive did not remove the previous
"Expires" and "Cache-Control" headers.
*) Bugfix: nginx did not take into account trailing dot in "Host"
header line.
*) Bugfix: the ngx_http_auth_module did not work under Linux.
*) Bugfix: the rewrite directive worked incorrectly, if the arguments
were in a request.
*) Bugfix: nginx could not be built on MacOS X.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Thu, 12 May 2005 00:00:00 +0400 |
parents | bcb5fce0b038 |
children | df7d3fff122b |
comparison
equal
deleted
inserted
replaced
57:5df375c55338 | 58:b55cbf18157e |
---|---|
15 #define NGX_HTTP_LOCATION_AUTO_REDIRECT 2 | 15 #define NGX_HTTP_LOCATION_AUTO_REDIRECT 2 |
16 #define NGX_HTTP_LOCATION_NOREGEX 3 | 16 #define NGX_HTTP_LOCATION_NOREGEX 3 |
17 #define NGX_HTTP_LOCATION_REGEX 4 | 17 #define NGX_HTTP_LOCATION_REGEX 4 |
18 | 18 |
19 | 19 |
20 static void ngx_http_core_phase_event_handler(ngx_event_t *rev); | |
21 static void ngx_http_core_run_phases(ngx_http_request_t *r); | 20 static void ngx_http_core_run_phases(ngx_http_request_t *r); |
22 static ngx_int_t ngx_http_core_find_location(ngx_http_request_t *r, | 21 static ngx_int_t ngx_http_core_find_location(ngx_http_request_t *r, |
23 ngx_array_t *locations, size_t len); | 22 ngx_array_t *locations, size_t len); |
24 | 23 |
24 static ngx_int_t ngx_http_core_preconfiguration(ngx_conf_t *cf); | |
25 static ngx_int_t ngx_http_core_postconfiguration(ngx_conf_t *cf); | |
25 static void *ngx_http_core_create_main_conf(ngx_conf_t *cf); | 26 static void *ngx_http_core_create_main_conf(ngx_conf_t *cf); |
26 static char *ngx_http_core_init_main_conf(ngx_conf_t *cf, void *conf); | 27 static char *ngx_http_core_init_main_conf(ngx_conf_t *cf, void *conf); |
27 static void *ngx_http_core_create_srv_conf(ngx_conf_t *cf); | 28 static void *ngx_http_core_create_srv_conf(ngx_conf_t *cf); |
28 static char *ngx_http_core_merge_srv_conf(ngx_conf_t *cf, | 29 static char *ngx_http_core_merge_srv_conf(ngx_conf_t *cf, |
29 void *parent, void *child); | 30 void *parent, void *child); |
52 void *conf); | 53 void *conf); |
53 static char *ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd, | 54 static char *ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd, |
54 void *conf); | 55 void *conf); |
55 static char *ngx_http_core_keepalive(ngx_conf_t *cf, ngx_command_t *cmd, | 56 static char *ngx_http_core_keepalive(ngx_conf_t *cf, ngx_command_t *cmd, |
56 void *conf); | 57 void *conf); |
58 static char *ngx_http_core_internal(ngx_conf_t *cf, ngx_command_t *cmd, | |
59 void *conf); | |
57 | 60 |
58 static char *ngx_http_core_lowat_check(ngx_conf_t *cf, void *post, void *data); | 61 static char *ngx_http_core_lowat_check(ngx_conf_t *cf, void *post, void *data); |
59 static ngx_int_t ngx_http_core_init(ngx_cycle_t *cycle); | |
60 | 62 |
61 static ngx_conf_post_t ngx_http_core_lowat_post = | 63 static ngx_conf_post_t ngx_http_core_lowat_post = |
62 { ngx_http_core_lowat_check }; | 64 { ngx_http_core_lowat_check }; |
63 | 65 |
64 | 66 |
181 NGX_HTTP_LOC_CONF_OFFSET, | 183 NGX_HTTP_LOC_CONF_OFFSET, |
182 offsetof(ngx_http_core_loc_conf_t, default_type), | 184 offsetof(ngx_http_core_loc_conf_t, default_type), |
183 NULL }, | 185 NULL }, |
184 | 186 |
185 { ngx_string("root"), | 187 { ngx_string("root"), |
186 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | 188 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF |
189 |NGX_CONF_TAKE1, | |
187 ngx_http_core_root, | 190 ngx_http_core_root, |
188 NGX_HTTP_LOC_CONF_OFFSET, | 191 NGX_HTTP_LOC_CONF_OFFSET, |
189 0, | 192 0, |
190 NULL }, | 193 NULL }, |
191 | 194 |
279 ngx_http_core_keepalive, | 282 ngx_http_core_keepalive, |
280 NGX_HTTP_LOC_CONF_OFFSET, | 283 NGX_HTTP_LOC_CONF_OFFSET, |
281 0, | 284 0, |
282 NULL }, | 285 NULL }, |
283 | 286 |
287 { ngx_string("internal"), | |
288 NGX_HTTP_LOC_CONF|NGX_CONF_NOARGS, | |
289 ngx_http_core_internal, | |
290 NGX_HTTP_LOC_CONF_OFFSET, | |
291 0, | |
292 NULL }, | |
293 | |
284 { ngx_string("lingering_time"), | 294 { ngx_string("lingering_time"), |
285 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | 295 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, |
286 ngx_conf_set_msec_slot, | 296 ngx_conf_set_msec_slot, |
287 NGX_HTTP_LOC_CONF_OFFSET, | 297 NGX_HTTP_LOC_CONF_OFFSET, |
288 offsetof(ngx_http_core_loc_conf_t, lingering_time), | 298 offsetof(ngx_http_core_loc_conf_t, lingering_time), |
308 NGX_HTTP_LOC_CONF_OFFSET, | 318 NGX_HTTP_LOC_CONF_OFFSET, |
309 offsetof(ngx_http_core_loc_conf_t, msie_padding), | 319 offsetof(ngx_http_core_loc_conf_t, msie_padding), |
310 NULL }, | 320 NULL }, |
311 | 321 |
312 { ngx_string("error_page"), | 322 { ngx_string("error_page"), |
313 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_2MORE, | 323 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF |
324 |NGX_CONF_2MORE, | |
314 ngx_http_core_error_page, | 325 ngx_http_core_error_page, |
315 NGX_HTTP_LOC_CONF_OFFSET, | 326 NGX_HTTP_LOC_CONF_OFFSET, |
316 0, | 327 0, |
317 NULL }, | 328 NULL }, |
318 | 329 |
337 ngx_null_command | 348 ngx_null_command |
338 }; | 349 }; |
339 | 350 |
340 | 351 |
341 ngx_http_module_t ngx_http_core_module_ctx = { | 352 ngx_http_module_t ngx_http_core_module_ctx = { |
342 NULL, /* pre conf */ | 353 ngx_http_core_preconfiguration, /* preconfiguration */ |
354 ngx_http_core_postconfiguration, /* postconfiguration */ | |
343 | 355 |
344 ngx_http_core_create_main_conf, /* create main configuration */ | 356 ngx_http_core_create_main_conf, /* create main configuration */ |
345 ngx_http_core_init_main_conf, /* init main configuration */ | 357 ngx_http_core_init_main_conf, /* init main configuration */ |
346 | 358 |
347 ngx_http_core_create_srv_conf, /* create server configuration */ | 359 ngx_http_core_create_srv_conf, /* create server configuration */ |
351 ngx_http_core_merge_loc_conf /* merge location configuration */ | 363 ngx_http_core_merge_loc_conf /* merge location configuration */ |
352 }; | 364 }; |
353 | 365 |
354 | 366 |
355 ngx_module_t ngx_http_core_module = { | 367 ngx_module_t ngx_http_core_module = { |
356 NGX_MODULE, | 368 NGX_MODULE_V1, |
357 &ngx_http_core_module_ctx, /* module context */ | 369 &ngx_http_core_module_ctx, /* module context */ |
358 ngx_http_core_commands, /* module directives */ | 370 ngx_http_core_commands, /* module directives */ |
359 NGX_HTTP_MODULE, /* module type */ | 371 NGX_HTTP_MODULE, /* module type */ |
360 ngx_http_core_init, /* init module */ | 372 NULL, /* init module */ |
361 NULL /* init process */ | 373 NULL /* init process */ |
362 }; | 374 }; |
363 | 375 |
364 | 376 |
365 void | 377 void |
411 | 423 |
412 #if 0 | 424 #if 0 |
413 /* TEST STUB */ r->lingering_close = 1; | 425 /* TEST STUB */ r->lingering_close = 1; |
414 #endif | 426 #endif |
415 | 427 |
416 r->connection->write->event_handler = ngx_http_core_phase_event_handler; | 428 r->write_event_handler = ngx_http_core_run_phases; |
417 | 429 |
418 r->valid_unparsed_uri = 1; | 430 r->valid_unparsed_uri = 1; |
431 r->valid_location = 1; | |
419 r->uri_changed = 1; | 432 r->uri_changed = 1; |
420 r->uri_changes = 11; | 433 r->uri_changes = NGX_HTTP_MAX_REWRITE_CYCLES + 1; |
421 | 434 |
422 r->phase = NGX_HTTP_REWRITE_PHASE; | 435 r->phase = NGX_HTTP_REWRITE_PHASE; |
423 r->phase_handler = 0; | 436 r->phase_handler = 0; |
424 | |
425 ngx_http_core_run_phases(r); | |
426 } | |
427 | |
428 | |
429 static void | |
430 ngx_http_core_phase_event_handler(ngx_event_t *ev) | |
431 { | |
432 ngx_connection_t *c; | |
433 ngx_http_request_t *r; | |
434 | |
435 c = ev->data; | |
436 r = c->data; | |
437 | |
438 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, ev->log, 0, "phase event handler"); | |
439 | 437 |
440 ngx_http_core_run_phases(r); | 438 ngx_http_core_run_phases(r); |
441 } | 439 } |
442 | 440 |
443 | 441 |
446 { | 444 { |
447 ngx_int_t rc; | 445 ngx_int_t rc; |
448 ngx_http_handler_pt *h; | 446 ngx_http_handler_pt *h; |
449 ngx_http_core_loc_conf_t *clcf; | 447 ngx_http_core_loc_conf_t *clcf; |
450 ngx_http_core_main_conf_t *cmcf; | 448 ngx_http_core_main_conf_t *cmcf; |
449 | |
450 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
451 "http phase handler"); | |
451 | 452 |
452 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module); | 453 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module); |
453 | 454 |
454 for (/* void */; r->phase < NGX_HTTP_LAST_PHASE; r->phase++) { | 455 for (/* void */; r->phase < NGX_HTTP_LAST_PHASE; r->phase++) { |
455 | 456 |
476 | 477 |
477 r->phase = NGX_HTTP_FIND_CONFIG_PHASE; | 478 r->phase = NGX_HTTP_FIND_CONFIG_PHASE; |
478 } | 479 } |
479 | 480 |
480 if (r->phase == NGX_HTTP_CONTENT_PHASE && r->content_handler) { | 481 if (r->phase == NGX_HTTP_CONTENT_PHASE && r->content_handler) { |
481 r->connection->write->event_handler = ngx_http_empty_handler; | 482 r->write_event_handler = ngx_http_request_empty_handler; |
482 ngx_http_finalize_request(r, r->content_handler(r)); | 483 ngx_http_finalize_request(r, r->content_handler(r)); |
483 return; | 484 return; |
484 } | 485 } |
485 | 486 |
486 h = cmcf->phases[r->phase].handlers.elts; | 487 h = cmcf->phases[r->phase].handlers.elts; |
561 if (rc == NGX_HTTP_INTERNAL_SERVER_ERROR) { | 562 if (rc == NGX_HTTP_INTERNAL_SERVER_ERROR) { |
562 return rc; | 563 return rc; |
563 } | 564 } |
564 | 565 |
565 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); | 566 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
567 | |
568 if (!r->internal && clcf->internal) { | |
569 return NGX_HTTP_NOT_FOUND; | |
570 } | |
566 | 571 |
567 r->connection->log->file = clcf->err_log->file; | 572 r->connection->log->file = clcf->err_log->file; |
568 if (!(r->connection->log->log_level & NGX_LOG_DEBUG_CONNECTION)) { | 573 if (!(r->connection->log->log_level & NGX_LOG_DEBUG_CONNECTION)) { |
569 r->connection->log->log_level = clcf->err_log->log_level; | 574 r->connection->log->log_level = clcf->err_log->log_level; |
570 } | 575 } |
606 r->headers_out.location = ngx_list_push(&r->headers_out.headers); | 611 r->headers_out.location = ngx_list_push(&r->headers_out.headers); |
607 if (r->headers_out.location == NULL) { | 612 if (r->headers_out.location == NULL) { |
608 return NGX_HTTP_INTERNAL_SERVER_ERROR; | 613 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
609 } | 614 } |
610 | 615 |
616 /* | |
617 * we do not need to set the r->headers_out.location->hash and | |
618 * r->headers_out.location->key fields | |
619 */ | |
620 | |
611 r->headers_out.location->value = clcf->name; | 621 r->headers_out.location->value = clcf->name; |
612 | 622 |
613 return NGX_HTTP_MOVED_PERMANENTLY; | 623 return NGX_HTTP_MOVED_PERMANENTLY; |
614 } | 624 } |
615 | 625 |
762 u_char c, *p, *exten; | 772 u_char c, *p, *exten; |
763 uint32_t key; | 773 uint32_t key; |
764 ngx_uint_t i; | 774 ngx_uint_t i; |
765 ngx_http_type_t *type; | 775 ngx_http_type_t *type; |
766 ngx_http_core_loc_conf_t *clcf; | 776 ngx_http_core_loc_conf_t *clcf; |
767 | |
768 r->headers_out.content_type = ngx_list_push(&r->headers_out.headers); | |
769 if (r->headers_out.content_type == NULL) { | |
770 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
771 } | |
772 | |
773 r->headers_out.content_type->key.len = 0; | |
774 r->headers_out.content_type->key.data = NULL; | |
775 r->headers_out.content_type->value.len = 0; | |
776 r->headers_out.content_type->value.data = NULL; | |
777 | 777 |
778 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); | 778 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
779 | 779 |
780 if (r->exten.len) { | 780 if (r->exten.len) { |
781 | 781 |
808 } | 808 } |
809 | 809 |
810 r->low_case_exten = 1; | 810 r->low_case_exten = 1; |
811 } | 811 } |
812 | 812 |
813 #if 0 | |
814 key = ngx_crc(r->exten.data, r->exten.key); | |
815 #endif | |
816 ngx_http_types_hash_key(key, r->exten); | 813 ngx_http_types_hash_key(key, r->exten); |
817 | 814 |
818 type = clcf->types[key].elts; | 815 type = clcf->types[key].elts; |
819 for (i = 0; i < clcf->types[key].nelts; i++) { | 816 for (i = 0; i < clcf->types[key].nelts; i++) { |
820 if (r->exten.len != type[i].exten.len) { | 817 if (r->exten.len != type[i].exten.len) { |
822 } | 819 } |
823 | 820 |
824 if (ngx_memcmp(r->exten.data, type[i].exten.data, r->exten.len) | 821 if (ngx_memcmp(r->exten.data, type[i].exten.data, r->exten.len) |
825 == 0) | 822 == 0) |
826 { | 823 { |
827 r->headers_out.content_type->value = type[i].type; | 824 r->headers_out.content_type = type[i].type; |
828 break; | 825 break; |
829 } | 826 } |
830 } | 827 } |
831 } | 828 } |
832 | 829 |
833 if (r->headers_out.content_type->value.len == 0) { | 830 if (r->headers_out.content_type.len == 0) { |
834 r->headers_out.content_type->value = clcf->default_type; | 831 r->headers_out.content_type= clcf->default_type; |
835 } | 832 } |
836 | 833 |
837 return NGX_OK; | 834 return NGX_OK; |
838 } | 835 } |
839 | 836 |
840 | 837 |
841 ngx_int_t | 838 ngx_int_t |
842 ngx_http_send_header(ngx_http_request_t *r) | 839 ngx_http_send_header(ngx_http_request_t *r) |
843 { | 840 { |
844 if (r->main) { | |
845 return NGX_OK; | |
846 } | |
847 | |
848 if (r->err_ctx) { | 841 if (r->err_ctx) { |
849 r->headers_out.status = r->err_status; | 842 r->headers_out.status = r->err_status; |
850 r->headers_out.status_line.len = 0; | 843 r->headers_out.status_line.len = 0; |
851 } | 844 } |
852 | 845 |
861 | 854 |
862 if (r->connection->write->error) { | 855 if (r->connection->write->error) { |
863 return NGX_ERROR; | 856 return NGX_ERROR; |
864 } | 857 } |
865 | 858 |
859 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
860 "http output filter \"%V\"", &r->uri); | |
861 | |
866 rc = ngx_http_top_body_filter(r, in); | 862 rc = ngx_http_top_body_filter(r, in); |
867 | 863 |
868 if (rc == NGX_ERROR) { | 864 if (rc == NGX_ERROR) { |
869 | |
870 /* NGX_ERROR may be returned by any filter */ | 865 /* NGX_ERROR may be returned by any filter */ |
871 | |
872 r->connection->write->error = 1; | 866 r->connection->write->error = 1; |
873 } | 867 } |
874 | 868 |
875 return rc; | 869 return rc; |
876 } | 870 } |
922 return NGX_OK; | 916 return NGX_OK; |
923 } | 917 } |
924 | 918 |
925 | 919 |
926 ngx_int_t | 920 ngx_int_t |
921 ngx_http_subrequest(ngx_http_request_t *r, | |
922 ngx_str_t *uri, ngx_str_t *args) | |
923 { | |
924 ngx_http_request_t *sr; | |
925 ngx_http_core_srv_conf_t *cscf; | |
926 ngx_http_postponed_request_t *pr, *p; | |
927 | |
928 sr = ngx_pcalloc(r->pool, sizeof(ngx_http_request_t)); | |
929 if (sr == NULL) { | |
930 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
931 } | |
932 | |
933 sr->signature = NGX_HTTP_MODULE; | |
934 sr->connection = r->connection; | |
935 | |
936 sr->ctx = ngx_pcalloc(r->pool, sizeof(void *) * ngx_http_max_module); | |
937 if (sr->ctx == NULL) { | |
938 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
939 } | |
940 | |
941 if (ngx_list_init(&sr->headers_out.headers, r->pool, 20, | |
942 sizeof(ngx_table_elt_t)) == NGX_ERROR) | |
943 { | |
944 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
945 } | |
946 | |
947 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); | |
948 sr->main_conf = cscf->ctx->main_conf; | |
949 sr->srv_conf = cscf->ctx->srv_conf; | |
950 sr->loc_conf = cscf->ctx->loc_conf; | |
951 | |
952 sr->pool = r->pool; | |
953 | |
954 sr->headers_in = r->headers_in; | |
955 | |
956 sr->start_time = ngx_time(); | |
957 sr->headers_out.content_length_n = -1; | |
958 sr->headers_out.last_modified_time = -1; | |
959 | |
960 sr->request_body = r->request_body; | |
961 | |
962 sr->method = NGX_HTTP_GET; | |
963 sr->http_version = r->http_version; | |
964 sr->http_major = r->http_minor; | |
965 | |
966 sr->request_line = r->request_line; | |
967 sr->uri = *uri; | |
968 if (args) { | |
969 sr->args = *args; | |
970 } | |
971 sr->unparsed_uri = r->unparsed_uri; | |
972 sr->method_name = r->method_name; | |
973 sr->http_protocol = r->http_protocol; | |
974 | |
975 if (ngx_http_set_exten(sr) != NGX_OK) { | |
976 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
977 } | |
978 | |
979 sr->main = r->main ? r->main : r; | |
980 sr->parent = r; | |
981 sr->read_event_handler = ngx_http_request_empty_handler; | |
982 sr->write_event_handler = ngx_http_request_empty_handler; | |
983 | |
984 if (r->connection->data == r) { | |
985 sr->connection->data = sr; | |
986 } | |
987 | |
988 sr->in_addr = r->in_addr; | |
989 sr->port = r->port; | |
990 sr->port_text = r->port_text; | |
991 sr->server_name = r->server_name; | |
992 | |
993 sr->variables = r->variables; | |
994 | |
995 sr->log_handler = r->log_handler; | |
996 | |
997 pr = ngx_palloc(r->pool, sizeof(ngx_http_postponed_request_t)); | |
998 if (pr == NULL) { | |
999 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
1000 } | |
1001 | |
1002 pr->request = sr; | |
1003 pr->out = NULL; | |
1004 pr->next = NULL; | |
1005 | |
1006 if (r->postponed) { | |
1007 for (p = r->postponed; p->next; p = p->next) { /* void */ } | |
1008 p->next = pr; | |
1009 | |
1010 } else { | |
1011 r->postponed = pr; | |
1012 } | |
1013 | |
1014 sr->internal = 1; | |
1015 | |
1016 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
1017 "http subrequest \"%V\"", uri); | |
1018 | |
1019 ngx_http_handler(sr); | |
1020 | |
1021 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
1022 "http subrequest \"%V\" done", uri); | |
1023 | |
1024 return NGX_OK; | |
1025 } | |
1026 | |
1027 | |
1028 ngx_int_t | |
927 ngx_http_internal_redirect(ngx_http_request_t *r, | 1029 ngx_http_internal_redirect(ngx_http_request_t *r, |
928 ngx_str_t *uri, ngx_str_t *args) | 1030 ngx_str_t *uri, ngx_str_t *args) |
929 { | 1031 { |
930 ngx_http_core_srv_conf_t *cscf; | 1032 ngx_http_core_srv_conf_t *cscf; |
931 | 1033 |
934 | 1036 |
935 r->uri = *uri; | 1037 r->uri = *uri; |
936 | 1038 |
937 if (args) { | 1039 if (args) { |
938 r->args = *args; | 1040 r->args = *args; |
1041 | |
1042 } else { | |
1043 r->args.len = 0; | |
1044 r->args.data = NULL; | |
939 } | 1045 } |
940 | 1046 |
941 if (ngx_http_set_exten(r) != NGX_OK) { | 1047 if (ngx_http_set_exten(r) != NGX_OK) { |
942 return NGX_HTTP_INTERNAL_SERVER_ERROR; | 1048 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
943 } | 1049 } |
958 ngx_memzero(r->ctx, sizeof(void *) * ngx_http_max_module); | 1064 ngx_memzero(r->ctx, sizeof(void *) * ngx_http_max_module); |
959 } | 1065 } |
960 | 1066 |
961 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); | 1067 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); |
962 r->loc_conf = cscf->ctx->loc_conf; | 1068 r->loc_conf = cscf->ctx->loc_conf; |
1069 | |
1070 r->internal = 1; | |
963 | 1071 |
964 ngx_http_handler(r); | 1072 ngx_http_handler(r); |
965 | 1073 |
966 return NGX_DONE; | 1074 return NGX_DONE; |
967 } | 1075 } |
1371 type->exten = value[i]; | 1479 type->exten = value[i]; |
1372 type->type = value[0]; | 1480 type->type = value[0]; |
1373 } | 1481 } |
1374 | 1482 |
1375 return NGX_CONF_OK; | 1483 return NGX_CONF_OK; |
1484 } | |
1485 | |
1486 | |
1487 static ngx_int_t | |
1488 ngx_http_core_preconfiguration(ngx_conf_t *cf) | |
1489 { | |
1490 return ngx_http_variables_add_core_vars(cf); | |
1491 } | |
1492 | |
1493 | |
1494 static ngx_int_t | |
1495 ngx_http_core_postconfiguration(ngx_conf_t *cf) | |
1496 { | |
1497 return ngx_http_variables_init_vars(cf); | |
1376 } | 1498 } |
1377 | 1499 |
1378 | 1500 |
1379 static void * | 1501 static void * |
1380 ngx_http_core_create_main_conf(ngx_conf_t *cf) | 1502 ngx_http_core_create_main_conf(ngx_conf_t *cf) |
1573 */ | 1695 */ |
1574 | 1696 |
1575 lcf->client_max_body_size = NGX_CONF_UNSET_SIZE; | 1697 lcf->client_max_body_size = NGX_CONF_UNSET_SIZE; |
1576 lcf->client_body_buffer_size = NGX_CONF_UNSET_SIZE; | 1698 lcf->client_body_buffer_size = NGX_CONF_UNSET_SIZE; |
1577 lcf->client_body_timeout = NGX_CONF_UNSET_MSEC; | 1699 lcf->client_body_timeout = NGX_CONF_UNSET_MSEC; |
1700 lcf->internal = NGX_CONF_UNSET; | |
1578 lcf->sendfile = NGX_CONF_UNSET; | 1701 lcf->sendfile = NGX_CONF_UNSET; |
1579 lcf->tcp_nopush = NGX_CONF_UNSET; | 1702 lcf->tcp_nopush = NGX_CONF_UNSET; |
1580 lcf->tcp_nodelay = NGX_CONF_UNSET; | 1703 lcf->tcp_nodelay = NGX_CONF_UNSET; |
1581 lcf->send_timeout = NGX_CONF_UNSET_MSEC; | 1704 lcf->send_timeout = NGX_CONF_UNSET_MSEC; |
1582 lcf->send_lowat = NGX_CONF_UNSET_SIZE; | 1705 lcf->send_lowat = NGX_CONF_UNSET_SIZE; |
1671 ngx_conf_merge_size_value(conf->client_body_buffer_size, | 1794 ngx_conf_merge_size_value(conf->client_body_buffer_size, |
1672 prev->client_body_buffer_size, | 1795 prev->client_body_buffer_size, |
1673 (size_t) 2 * ngx_pagesize); | 1796 (size_t) 2 * ngx_pagesize); |
1674 ngx_conf_merge_msec_value(conf->client_body_timeout, | 1797 ngx_conf_merge_msec_value(conf->client_body_timeout, |
1675 prev->client_body_timeout, 60000); | 1798 prev->client_body_timeout, 60000); |
1799 | |
1800 ngx_conf_merge_value(conf->internal, prev->internal, 0); | |
1676 ngx_conf_merge_value(conf->sendfile, prev->sendfile, 0); | 1801 ngx_conf_merge_value(conf->sendfile, prev->sendfile, 0); |
1677 ngx_conf_merge_value(conf->tcp_nopush, prev->tcp_nopush, 0); | 1802 ngx_conf_merge_value(conf->tcp_nopush, prev->tcp_nopush, 0); |
1678 ngx_conf_merge_value(conf->tcp_nodelay, prev->tcp_nodelay, 0); | 1803 ngx_conf_merge_value(conf->tcp_nodelay, prev->tcp_nodelay, 0); |
1804 | |
1679 ngx_conf_merge_msec_value(conf->send_timeout, prev->send_timeout, 60000); | 1805 ngx_conf_merge_msec_value(conf->send_timeout, prev->send_timeout, 60000); |
1680 ngx_conf_merge_size_value(conf->send_lowat, prev->send_lowat, 0); | 1806 ngx_conf_merge_size_value(conf->send_lowat, prev->send_lowat, 0); |
1681 ngx_conf_merge_size_value(conf->postpone_output, prev->postpone_output, | 1807 ngx_conf_merge_size_value(conf->postpone_output, prev->postpone_output, |
1682 1460); | 1808 1460); |
1683 ngx_conf_merge_size_value(conf->limit_rate, prev->limit_rate, 0); | 1809 ngx_conf_merge_size_value(conf->limit_rate, prev->limit_rate, 0); |
1961 return NGX_CONF_OK; | 2087 return NGX_CONF_OK; |
1962 } | 2088 } |
1963 | 2089 |
1964 | 2090 |
1965 static char * | 2091 static char * |
1966 ngx_http_core_keepalive(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
1967 { | |
1968 ngx_http_core_loc_conf_t *lcf = conf; | |
1969 | |
1970 ngx_str_t *value; | |
1971 | |
1972 if (lcf->keepalive_timeout != NGX_CONF_UNSET_MSEC) { | |
1973 return "is duplicate"; | |
1974 } | |
1975 | |
1976 value = cf->args->elts; | |
1977 | |
1978 lcf->keepalive_timeout = ngx_parse_time(&value[1], 0); | |
1979 | |
1980 if (lcf->keepalive_timeout == (ngx_msec_t) NGX_ERROR) { | |
1981 return "invalid value"; | |
1982 } | |
1983 | |
1984 if (lcf->keepalive_timeout == (ngx_msec_t) NGX_PARSE_LARGE_TIME) { | |
1985 return "value must be less than 597 hours"; | |
1986 } | |
1987 | |
1988 if (cf->args->nelts == 2) { | |
1989 return NGX_CONF_OK; | |
1990 } | |
1991 | |
1992 lcf->keepalive_header = ngx_parse_time(&value[2], 1); | |
1993 | |
1994 if (lcf->keepalive_header == NGX_ERROR) { | |
1995 return "invalid value"; | |
1996 } | |
1997 | |
1998 if (lcf->keepalive_header == NGX_PARSE_LARGE_TIME) { | |
1999 return "value must be less than 68 years"; | |
2000 } | |
2001 | |
2002 return NGX_CONF_OK; | |
2003 } | |
2004 | |
2005 | |
2006 static char * | |
2007 ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | 2092 ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
2008 { | 2093 { |
2009 ngx_http_core_loc_conf_t *lcf = conf; | 2094 ngx_http_core_loc_conf_t *lcf = conf; |
2010 | 2095 |
2011 lcf->err_log = ngx_log_create_errlog(cf->cycle, cf->args); | 2096 lcf->err_log = ngx_log_create_errlog(cf->cycle, cf->args); |
2012 if (lcf->err_log == NULL) { | 2097 if (lcf->err_log == NULL) { |
2013 return NGX_CONF_ERROR; | 2098 return NGX_CONF_ERROR; |
2014 } | 2099 } |
2015 | 2100 |
2016 return ngx_set_error_log_levels(cf, lcf->err_log); | 2101 return ngx_set_error_log_levels(cf, lcf->err_log); |
2102 } | |
2103 | |
2104 | |
2105 static char * | |
2106 ngx_http_core_keepalive(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
2107 { | |
2108 ngx_http_core_loc_conf_t *lcf = conf; | |
2109 | |
2110 ngx_str_t *value; | |
2111 | |
2112 if (lcf->keepalive_timeout != NGX_CONF_UNSET_MSEC) { | |
2113 return "is duplicate"; | |
2114 } | |
2115 | |
2116 value = cf->args->elts; | |
2117 | |
2118 lcf->keepalive_timeout = ngx_parse_time(&value[1], 0); | |
2119 | |
2120 if (lcf->keepalive_timeout == (ngx_msec_t) NGX_ERROR) { | |
2121 return "invalid value"; | |
2122 } | |
2123 | |
2124 if (lcf->keepalive_timeout == (ngx_msec_t) NGX_PARSE_LARGE_TIME) { | |
2125 return "value must be less than 597 hours"; | |
2126 } | |
2127 | |
2128 if (cf->args->nelts == 2) { | |
2129 return NGX_CONF_OK; | |
2130 } | |
2131 | |
2132 lcf->keepalive_header = ngx_parse_time(&value[2], 1); | |
2133 | |
2134 if (lcf->keepalive_header == NGX_ERROR) { | |
2135 return "invalid value"; | |
2136 } | |
2137 | |
2138 if (lcf->keepalive_header == NGX_PARSE_LARGE_TIME) { | |
2139 return "value must be less than 68 years"; | |
2140 } | |
2141 | |
2142 return NGX_CONF_OK; | |
2143 } | |
2144 | |
2145 | |
2146 static char * | |
2147 ngx_http_core_internal(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
2148 { | |
2149 ngx_http_core_loc_conf_t *lcf = conf; | |
2150 | |
2151 if (lcf->internal != NGX_CONF_UNSET) { | |
2152 return "is duplicate"; | |
2153 } | |
2154 | |
2155 lcf->internal = 1; | |
2156 | |
2157 return NGX_CONF_OK; | |
2017 } | 2158 } |
2018 | 2159 |
2019 | 2160 |
2020 static char * | 2161 static char * |
2021 ngx_http_core_lowat_check(ngx_conf_t *cf, void *post, void *data) | 2162 ngx_http_core_lowat_check(ngx_conf_t *cf, void *post, void *data) |
2042 | 2183 |
2043 #endif | 2184 #endif |
2044 | 2185 |
2045 return NGX_CONF_OK; | 2186 return NGX_CONF_OK; |
2046 } | 2187 } |
2047 | |
2048 | |
2049 static ngx_int_t | |
2050 ngx_http_core_init(ngx_cycle_t *cycle) | |
2051 { | |
2052 return ngx_http_variables_init(cycle); | |
2053 } |