Mercurial > hg > nginx
comparison src/http/ngx_http_core_module.c @ 210:00cafae0bdf1
nginx-0.0.1-2003-12-14-23:10:27 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Sun, 14 Dec 2003 20:10:27 +0000 |
parents | 0b67be7d4489 |
children | fd9fecc4193f |
comparison
equal
deleted
inserted
replaced
209:e1c815be05ae | 210:00cafae0bdf1 |
---|---|
405 exact = 0; | 405 exact = 0; |
406 | 406 |
407 clcfp = cscf->locations.elts; | 407 clcfp = cscf->locations.elts; |
408 for (i = 0; i < cscf->locations.nelts; i++) { | 408 for (i = 0; i < cscf->locations.nelts; i++) { |
409 | 409 |
410 #if 1 | 410 #if (HAVE_PCRE) |
411 ngx_log_debug(r->connection->log, "trans: %s: %d" _ | |
412 clcfp[i]->name.data _ clcfp[i]->exact_match); | |
413 #endif | |
414 | 411 |
415 if (clcfp[i]->regex) { | 412 if (clcfp[i]->regex) { |
416 break; | 413 break; |
417 } | 414 } |
415 #endif | |
416 | |
417 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
418 "find location: %s\"%s\"", | |
419 clcfp[i]->exact_match ? "= " : "", | |
420 clcfp[i]->name.data); | |
418 | 421 |
419 if (clcfp[i]->auto_redirect | 422 if (clcfp[i]->auto_redirect |
420 && r->uri.len == clcfp[i]->name.len - 1 | 423 && r->uri.len == clcfp[i]->name.len - 1 |
421 && ngx_strncmp(r->uri.data, clcfp[i]->name.data, | 424 && ngx_strncmp(r->uri.data, clcfp[i]->name.data, |
422 clcfp[i]->name.len - 1) == 0) | 425 clcfp[i]->name.len - 1) == 0) |
447 break; | 450 break; |
448 } | 451 } |
449 } | 452 } |
450 } | 453 } |
451 | 454 |
455 #if (HAVE_PCRE) | |
456 | |
452 if (!exact && !auto_redirect) { | 457 if (!exact && !auto_redirect) { |
453 /* regex matches */ | 458 /* regex matches */ |
454 | 459 |
455 for (/* void */; i < cscf->locations.nelts; i++) { | 460 for (/* void */; i < cscf->locations.nelts; i++) { |
456 | 461 |
457 #if 1 | |
458 ngx_log_debug(r->connection->log, "trans: %s: %d" _ | |
459 clcfp[i]->name.data _ clcfp[i]->exact_match); | |
460 #endif | |
461 | |
462 if (!clcfp[i]->regex) { | 462 if (!clcfp[i]->regex) { |
463 continue; | 463 continue; |
464 } | 464 } |
465 | |
466 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
467 "find location: %s\"%s\"", | |
468 clcfp[i]->exact_match ? "= " : | |
469 clcfp[i]->regex ? "~ " : "", | |
470 clcfp[i]->name.data); | |
465 | 471 |
466 rc = ngx_regex_exec(clcfp[i]->regex, &r->uri); | 472 rc = ngx_regex_exec(clcfp[i]->regex, &r->uri); |
467 | 473 |
468 if (rc == NGX_DECLINED) { | 474 if (rc == NGX_DECLINED) { |
469 continue; | 475 continue; |
486 | 492 |
487 break; | 493 break; |
488 } | 494 } |
489 } | 495 } |
490 | 496 |
497 #endif /* HAVE_PCRE */ | |
498 | |
491 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); | 499 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
492 | 500 |
493 if (!(ngx_io.flags & NGX_IO_SENDFILE) || !clcf->sendfile) { | 501 if (!(ngx_io.flags & NGX_IO_SENDFILE) || !clcf->sendfile) { |
494 r->sendfile = 0; | 502 r->sendfile = 0; |
495 | 503 |
502 ngx_http_add_header(&r->headers_out, ngx_http_headers_out))) | 510 ngx_http_add_header(&r->headers_out, ngx_http_headers_out))) |
503 { | 511 { |
504 return NGX_HTTP_INTERNAL_SERVER_ERROR; | 512 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
505 } | 513 } |
506 | 514 |
507 #if 0 | |
508 r->headers_out.location->key.len = 8; | |
509 r->headers_out.location->key.data = "Location"; | |
510 #endif | |
511 r->headers_out.location->value = *auto_redirect; | 515 r->headers_out.location->value = *auto_redirect; |
512 | 516 |
513 return NGX_HTTP_MOVED_PERMANENTLY; | 517 return NGX_HTTP_MOVED_PERMANENTLY; |
514 } | 518 } |
515 | 519 |
612 int ngx_http_internal_redirect(ngx_http_request_t *r, | 616 int ngx_http_internal_redirect(ngx_http_request_t *r, |
613 ngx_str_t *uri, ngx_str_t *args) | 617 ngx_str_t *uri, ngx_str_t *args) |
614 { | 618 { |
615 int i; | 619 int i; |
616 | 620 |
617 ngx_log_debug(r->connection->log, "internal redirect: '%s'" _ uri->data); | 621 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
622 "internal redirect: \"%s\"", uri->data); | |
618 | 623 |
619 r->uri.len = uri->len; | 624 r->uri.len = uri->len; |
620 r->uri.data = uri->data; | 625 r->uri.data = uri->data; |
621 | 626 |
622 if (args) { | 627 if (args) { |
796 ngx_http_core_loc_conf_t *first = *(ngx_http_core_loc_conf_t **) one; | 801 ngx_http_core_loc_conf_t *first = *(ngx_http_core_loc_conf_t **) one; |
797 ngx_http_core_loc_conf_t *second = *(ngx_http_core_loc_conf_t **) two; | 802 ngx_http_core_loc_conf_t *second = *(ngx_http_core_loc_conf_t **) two; |
798 | 803 |
799 ngx_int_t rc; | 804 ngx_int_t rc; |
800 | 805 |
806 #if (HAVE_PCRE) | |
807 | |
801 if (first->regex && !second->regex) { | 808 if (first->regex && !second->regex) { |
802 /* shift regex matches to the end */ | 809 /* shift regex matches to the end */ |
803 return 1; | 810 return 1; |
804 } | 811 } |
805 | 812 |
806 if (first->regex || second->regex) { | 813 if (first->regex || second->regex) { |
807 /* do not sort regex matches */ | 814 /* do not sort regex matches */ |
808 return 0; | 815 return 0; |
809 } | 816 } |
817 | |
818 #endif | |
810 | 819 |
811 rc = ngx_strcmp(first->name.data, second->name.data); | 820 rc = ngx_strcmp(first->name.data, second->name.data); |
812 | 821 |
813 if (rc == 0 && second->exact_match) { | 822 if (rc == 0 && second->exact_match) { |
814 /* an exact match must be before the same inclusive one */ | 823 /* an exact match must be before the same inclusive one */ |
874 } else if ((value[1].len == 1 && value[1].data[0] == '~') | 883 } else if ((value[1].len == 1 && value[1].data[0] == '~') |
875 || (value[1].len == 2 | 884 || (value[1].len == 2 |
876 && value[1].data[0] == '~' | 885 && value[1].data[0] == '~' |
877 && value[1].data[1] == '*')) | 886 && value[1].data[1] == '*')) |
878 { | 887 { |
888 #if (HAVE_PCRE) | |
879 err.len = NGX_MAX_CONF_ERRSTR; | 889 err.len = NGX_MAX_CONF_ERRSTR; |
880 err.data = errstr; | 890 err.data = errstr; |
881 | 891 |
882 clcf->regex = ngx_regex_compile(&value[2], | 892 clcf->regex = ngx_regex_compile(&value[2], |
883 value[1].len == 2 ? NGX_REGEX_CASELESS: 0, | 893 value[1].len == 2 ? NGX_REGEX_CASELESS: 0, |
888 return NGX_CONF_ERROR; | 898 return NGX_CONF_ERROR; |
889 } | 899 } |
890 | 900 |
891 clcf->name.len = value[2].len; | 901 clcf->name.len = value[2].len; |
892 clcf->name.data = value[2].data; | 902 clcf->name.data = value[2].data; |
903 #else | |
904 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
905 "the using of the regex \"%s\" " | |
906 "requires PCRE library", | |
907 value[2].data); | |
908 return NGX_CONF_ERROR; | |
909 #endif | |
893 | 910 |
894 } else { | 911 } else { |
895 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 912 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
896 "invalid location modifier \"%s\"", | 913 "invalid location modifier \"%s\"", |
897 value[1].data); | 914 value[1].data); |