Mercurial > hg > nginx
comparison src/http/modules/proxy/ngx_http_proxy_handler.c @ 290:87e73f067470
nginx-0.0.2-2004-03-16-10:10:12 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Tue, 16 Mar 2004 07:10:12 +0000 |
parents | f81d075ad172 |
children | 117ccc7c4055 |
comparison
equal
deleted
inserted
replaced
289:0750faf8d7e3 | 290:87e73f067470 |
---|---|
5 #include <ngx_http_proxy_handler.h> | 5 #include <ngx_http_proxy_handler.h> |
6 | 6 |
7 | 7 |
8 static int ngx_http_proxy_handler(ngx_http_request_t *r); | 8 static int ngx_http_proxy_handler(ngx_http_request_t *r); |
9 | 9 |
10 static char *ngx_http_proxy_log_proxy_state(ngx_http_request_t *r, char *buf, | 10 static u_char *ngx_http_proxy_log_proxy_state(ngx_http_request_t *r, |
11 uintptr_t data); | 11 u_char *buf, uintptr_t data); |
12 static char *ngx_http_proxy_log_cache_state(ngx_http_request_t *r, char *buf, | 12 static u_char *ngx_http_proxy_log_cache_state(ngx_http_request_t *r, |
13 uintptr_t data); | 13 u_char *buf, uintptr_t data); |
14 static char *ngx_http_proxy_log_reason(ngx_http_request_t *r, char *buf, | 14 static u_char *ngx_http_proxy_log_reason(ngx_http_request_t *r, u_char *buf, |
15 uintptr_t data); | 15 uintptr_t data); |
16 | 16 |
17 static int ngx_http_proxy_pre_conf(ngx_conf_t *cf); | 17 static int ngx_http_proxy_pre_conf(ngx_conf_t *cf); |
18 static void *ngx_http_proxy_create_loc_conf(ngx_conf_t *cf); | 18 static void *ngx_http_proxy_create_loc_conf(ngx_conf_t *cf); |
19 static char *ngx_http_proxy_merge_loc_conf(ngx_conf_t *cf, | 19 static char *ngx_http_proxy_merge_loc_conf(ngx_conf_t *cf, |
20 void *parent, void *child); | 20 void *parent, void *child); |
144 { ngx_string("proxy_temp_path"), | 144 { ngx_string("proxy_temp_path"), |
145 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1234, | 145 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1234, |
146 ngx_conf_set_path_slot, | 146 ngx_conf_set_path_slot, |
147 NGX_HTTP_LOC_CONF_OFFSET, | 147 NGX_HTTP_LOC_CONF_OFFSET, |
148 offsetof(ngx_http_proxy_loc_conf_t, temp_path), | 148 offsetof(ngx_http_proxy_loc_conf_t, temp_path), |
149 ngx_garbage_collector_temp_handler }, | 149 (void *) ngx_garbage_collector_temp_handler }, |
150 | 150 |
151 { ngx_string("proxy_temp_file_write_size"), | 151 { ngx_string("proxy_temp_file_write_size"), |
152 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | 152 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, |
153 ngx_conf_set_size_slot, | 153 ngx_conf_set_size_slot, |
154 NGX_HTTP_LOC_CONF_OFFSET, | 154 NGX_HTTP_LOC_CONF_OFFSET, |
589 if (ngx_close_socket(c->fd) == -1) { | 589 if (ngx_close_socket(c->fd) == -1) { |
590 ngx_log_error(NGX_LOG_ALERT, c->log, ngx_socket_errno, | 590 ngx_log_error(NGX_LOG_ALERT, c->log, ngx_socket_errno, |
591 ngx_close_socket_n " failed"); | 591 ngx_close_socket_n " failed"); |
592 } | 592 } |
593 | 593 |
594 c->fd = -1; | 594 c->fd = (ngx_socket_t) -1; |
595 } | 595 } |
596 | 596 |
597 | 597 |
598 size_t ngx_http_proxy_log_error(void *data, char *buf, size_t len) | 598 size_t ngx_http_proxy_log_error(void *data, char *buf, size_t len) |
599 { | 599 { |
612 r->unparsed_uri.data, | 612 r->unparsed_uri.data, |
613 peer->peers->peers[peer->cur_peer].addr_port_text.data, | 613 peer->peers->peers[peer->cur_peer].addr_port_text.data, |
614 ctx->proxy->lcf->upstream->uri.data, | 614 ctx->proxy->lcf->upstream->uri.data, |
615 r->uri.data + ctx->proxy->lcf->upstream->location->len, | 615 r->uri.data + ctx->proxy->lcf->upstream->location->len, |
616 r->args.len ? "?" : "", | 616 r->args.len ? "?" : "", |
617 r->args.len ? r->args.data : ""); | 617 r->args.len ? r->args.data : (u_char *) ""); |
618 } | 618 } |
619 | 619 |
620 | 620 |
621 static char *ngx_http_proxy_log_proxy_state(ngx_http_request_t *r, char *buf, | 621 static u_char *ngx_http_proxy_log_proxy_state(ngx_http_request_t *r, |
622 uintptr_t data) | 622 u_char *buf, uintptr_t data) |
623 { | 623 { |
624 ngx_http_proxy_ctx_t *p; | 624 ngx_http_proxy_ctx_t *p; |
625 | 625 |
626 p = ngx_http_get_module_err_ctx(r, ngx_http_proxy_module); | 626 p = ngx_http_get_module_err_ctx(r, ngx_http_proxy_module); |
627 | 627 |
642 | 642 |
643 if (p->state->expired == 0) { | 643 if (p->state->expired == 0) { |
644 *buf++ = '-'; | 644 *buf++ = '-'; |
645 | 645 |
646 } else { | 646 } else { |
647 buf += ngx_snprintf(buf, NGX_TIME_T_LEN, TIME_T_FMT, p->state->expired); | 647 buf += ngx_snprintf((char *) buf, NGX_TIME_T_LEN, |
648 TIME_T_FMT, p->state->expired); | |
648 } | 649 } |
649 | 650 |
650 *buf++ = '/'; | 651 *buf++ = '/'; |
651 | 652 |
652 if (p->state->bl_time == 0) { | 653 if (p->state->bl_time == 0) { |
653 *buf++ = '-'; | 654 *buf++ = '-'; |
654 | 655 |
655 } else { | 656 } else { |
656 buf += ngx_snprintf(buf, NGX_TIME_T_LEN, TIME_T_FMT, p->state->bl_time); | 657 buf += ngx_snprintf((char *) buf, NGX_TIME_T_LEN, |
658 TIME_T_FMT, p->state->bl_time); | |
657 } | 659 } |
658 | 660 |
659 *buf++ = '/'; | 661 *buf++ = '/'; |
660 | 662 |
661 *buf++ = '*'; | 663 *buf++ = '*'; |
664 | 666 |
665 if (p->state->status == 0) { | 667 if (p->state->status == 0) { |
666 *buf++ = '-'; | 668 *buf++ = '-'; |
667 | 669 |
668 } else { | 670 } else { |
669 buf += ngx_snprintf(buf, 4, "%d", p->state->status); | 671 buf += ngx_snprintf((char *) buf, 4, "%d", p->state->status); |
670 } | 672 } |
671 | 673 |
672 *buf++ = '/'; | 674 *buf++ = '/'; |
673 | 675 |
674 if (p->state->reason == 0) { | 676 if (p->state->reason == 0) { |
683 | 685 |
684 if (p->state->reason < NGX_HTTP_PROXY_CACHE_XAE) { | 686 if (p->state->reason < NGX_HTTP_PROXY_CACHE_XAE) { |
685 *buf++ = '-'; | 687 *buf++ = '-'; |
686 | 688 |
687 } else { | 689 } else { |
688 buf += ngx_snprintf(buf, NGX_TIME_T_LEN, TIME_T_FMT, p->state->expires); | 690 buf += ngx_snprintf((char *) buf, NGX_TIME_T_LEN, |
691 TIME_T_FMT, p->state->expires); | |
689 } | 692 } |
690 | 693 |
691 *buf++ = ' '; | 694 *buf++ = ' '; |
692 *buf++ = '*'; | 695 *buf++ = '*'; |
693 | 696 |
694 return buf; | 697 return buf; |
695 } | 698 } |
696 | 699 |
697 | 700 |
698 static char *ngx_http_proxy_log_cache_state(ngx_http_request_t *r, char *buf, | 701 static u_char *ngx_http_proxy_log_cache_state(ngx_http_request_t *r, |
699 uintptr_t data) | 702 u_char *buf, uintptr_t data) |
700 { | 703 { |
701 ngx_http_proxy_ctx_t *p; | 704 ngx_http_proxy_ctx_t *p; |
702 | 705 |
703 p = ngx_http_get_module_err_ctx(r, ngx_http_proxy_module); | 706 p = ngx_http_get_module_err_ctx(r, ngx_http_proxy_module); |
704 | 707 |
710 return ngx_cpymem(buf, cache_states[p->state->cache_state - 1].data, | 713 return ngx_cpymem(buf, cache_states[p->state->cache_state - 1].data, |
711 cache_states[p->state->cache_state - 1].len); | 714 cache_states[p->state->cache_state - 1].len); |
712 } | 715 } |
713 | 716 |
714 | 717 |
715 static char *ngx_http_proxy_log_reason(ngx_http_request_t *r, char *buf, | 718 static u_char *ngx_http_proxy_log_reason(ngx_http_request_t *r, u_char *buf, |
716 uintptr_t data) | 719 uintptr_t data) |
717 { | 720 { |
718 ngx_http_proxy_ctx_t *p; | 721 ngx_http_proxy_ctx_t *p; |
719 | 722 |
720 p = ngx_http_get_module_err_ctx(r, ngx_http_proxy_module); | 723 p = ngx_http_get_module_err_ctx(r, ngx_http_proxy_module); |
721 | 724 |
775 | 778 |
776 conf->busy_lock = NULL; | 779 conf->busy_lock = NULL; |
777 | 780 |
778 */ | 781 */ |
779 | 782 |
780 conf->request_buffer_size = NGX_CONF_UNSET; | 783 conf->request_buffer_size = NGX_CONF_UNSET_SIZE; |
781 conf->connect_timeout = NGX_CONF_UNSET; | 784 conf->connect_timeout = NGX_CONF_UNSET_MSEC; |
782 conf->send_timeout = NGX_CONF_UNSET; | 785 conf->send_timeout = NGX_CONF_UNSET_MSEC; |
783 | 786 |
784 conf->preserve_host = NGX_CONF_UNSET; | 787 conf->preserve_host = NGX_CONF_UNSET; |
785 conf->set_x_real_ip = NGX_CONF_UNSET; | 788 conf->set_x_real_ip = NGX_CONF_UNSET; |
786 conf->add_x_forwarded_for = NGX_CONF_UNSET; | 789 conf->add_x_forwarded_for = NGX_CONF_UNSET; |
787 | 790 |
788 conf->header_buffer_size = NGX_CONF_UNSET; | 791 conf->header_buffer_size = NGX_CONF_UNSET_SIZE; |
789 conf->read_timeout = NGX_CONF_UNSET; | 792 conf->read_timeout = NGX_CONF_UNSET_MSEC; |
790 conf->busy_buffers_size = NGX_CONF_UNSET; | 793 conf->busy_buffers_size = NGX_CONF_UNSET_SIZE; |
791 | 794 |
792 /* | 795 /* |
793 * "proxy_max_temp_file_size" is hardcoded to 1G for reverse proxy, | 796 * "proxy_max_temp_file_size" is hardcoded to 1G for reverse proxy, |
794 * it should be configurable in the generic proxy | 797 * it should be configurable in the generic proxy |
795 */ | 798 */ |
796 conf->max_temp_file_size = 1024 * 1024 * 1024; | 799 conf->max_temp_file_size = 1024 * 1024 * 1024; |
797 | 800 |
798 conf->temp_file_write_size = NGX_CONF_UNSET; | 801 conf->temp_file_write_size = NGX_CONF_UNSET_SIZE; |
799 | 802 |
800 /* "proxy_cyclic_temp_file" is disabled */ | 803 /* "proxy_cyclic_temp_file" is disabled */ |
801 conf->cyclic_temp_file = 0; | 804 conf->cyclic_temp_file = 0; |
802 | 805 |
803 conf->cache = NGX_CONF_UNSET; | 806 conf->cache = NGX_CONF_UNSET; |
904 static char *ngx_http_proxy_set_pass(ngx_conf_t *cf, ngx_command_t *cmd, | 907 static char *ngx_http_proxy_set_pass(ngx_conf_t *cf, ngx_command_t *cmd, |
905 void *conf) | 908 void *conf) |
906 { | 909 { |
907 ngx_http_proxy_loc_conf_t *lcf = conf; | 910 ngx_http_proxy_loc_conf_t *lcf = conf; |
908 | 911 |
909 int i, len; | 912 ngx_uint_t i, len; |
910 char *err, *host; | 913 char *err; |
914 u_char *host; | |
911 in_addr_t addr; | 915 in_addr_t addr; |
912 ngx_str_t *value; | 916 ngx_str_t *value; |
913 struct hostent *h; | 917 struct hostent *h; |
914 ngx_http_conf_ctx_t *ctx; | 918 ngx_http_conf_ctx_t *ctx; |
915 ngx_http_core_loc_conf_t *clcf; | 919 ngx_http_core_loc_conf_t *clcf; |
944 NGX_CONF_ERROR); | 948 NGX_CONF_ERROR); |
945 ngx_cpystrn(host, lcf->upstream->host.data, lcf->upstream->host.len + 1); | 949 ngx_cpystrn(host, lcf->upstream->host.data, lcf->upstream->host.len + 1); |
946 | 950 |
947 /* AF_INET only */ | 951 /* AF_INET only */ |
948 | 952 |
949 addr = inet_addr(host); | 953 addr = inet_addr((char *) host); |
950 | 954 |
951 if (addr == INADDR_NONE) { | 955 if (addr == INADDR_NONE) { |
952 h = gethostbyname(host); | 956 h = gethostbyname((char *) host); |
953 | 957 |
954 if (h == NULL || h->h_addr_list[0] == NULL) { | 958 if (h == NULL || h->h_addr_list[0] == NULL) { |
955 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "host %s not found", host); | 959 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "host %s not found", host); |
956 return NGX_CONF_ERROR; | 960 return NGX_CONF_ERROR; |
957 } | 961 } |
978 ngx_test_null(lcf->peers->peers[i].addr_port_text.data, | 982 ngx_test_null(lcf->peers->peers[i].addr_port_text.data, |
979 ngx_palloc(cf->pool, len), | 983 ngx_palloc(cf->pool, len), |
980 NGX_CONF_ERROR); | 984 NGX_CONF_ERROR); |
981 | 985 |
982 len = ngx_inet_ntop(AF_INET, | 986 len = ngx_inet_ntop(AF_INET, |
983 (char *) &lcf->peers->peers[i].addr, | 987 (u_char *) &lcf->peers->peers[i].addr, |
984 lcf->peers->peers[i].addr_port_text.data, | 988 lcf->peers->peers[i].addr_port_text.data, |
985 len); | 989 len); |
986 | 990 |
987 lcf->peers->peers[i].addr_port_text.data[len++] = ':'; | 991 lcf->peers->peers[i].addr_port_text.data[len++] = ':'; |
988 | 992 |