comparison src/http/ngx_http_variables.c @ 362:54fad6c4b555 NGINX_0_6_25

nginx 0.6.25 *) Change: now the "server_name_in_redirect" directive is used instead of the "server_name" directive's special "*" parameter. *) Change: now wildcard and regex names can be used as main name in a "server_name" directive. *) Change: the "satisfy_any" directive was replaced by the "satisfy" directive. *) Workaround: old worker processes might hog CPU after reconfiguration if they was run under Linux OpenVZ. *) Feature: the "min_delete_depth" directive. *) Bugfix: the COPY and MOVE methods did not work with single files. *) Bugfix: the ngx_http_gzip_static_module did not allow the ngx_http_dav_module to work; bug appeared in 0.6.23. *) Bugfix: socket leak in HTTPS mode if deferred accept was used. Thanks to Ben Maurer. *) Bugfix: nginx could not be built without PCRE library; bug appeared in 0.6.23.
author Igor Sysoev <http://sysoev.ru>
date Tue, 08 Jan 2008 00:00:00 +0300
parents 10cc350ed8a1
children edf1cb6c328e
comparison
equal deleted inserted replaced
361:160660bad929 362:54fad6c4b555
44 static ngx_int_t ngx_http_variable_is_args(ngx_http_request_t *r, 44 static ngx_int_t ngx_http_variable_is_args(ngx_http_request_t *r,
45 ngx_http_variable_value_t *v, uintptr_t data); 45 ngx_http_variable_value_t *v, uintptr_t data);
46 static ngx_int_t ngx_http_variable_document_root(ngx_http_request_t *r, 46 static ngx_int_t ngx_http_variable_document_root(ngx_http_request_t *r,
47 ngx_http_variable_value_t *v, uintptr_t data); 47 ngx_http_variable_value_t *v, uintptr_t data);
48 static ngx_int_t ngx_http_variable_request_filename(ngx_http_request_t *r, 48 static ngx_int_t ngx_http_variable_request_filename(ngx_http_request_t *r,
49 ngx_http_variable_value_t *v, uintptr_t data);
50 static ngx_int_t ngx_http_variable_server_name(ngx_http_request_t *r,
49 ngx_http_variable_value_t *v, uintptr_t data); 51 ngx_http_variable_value_t *v, uintptr_t data);
50 static ngx_int_t ngx_http_variable_request_method(ngx_http_request_t *r, 52 static ngx_int_t ngx_http_variable_request_method(ngx_http_request_t *r,
51 ngx_http_variable_value_t *v, uintptr_t data); 53 ngx_http_variable_value_t *v, uintptr_t data);
52 static ngx_int_t ngx_http_variable_remote_user(ngx_http_request_t *r, 54 static ngx_int_t ngx_http_variable_remote_user(ngx_http_request_t *r,
53 ngx_http_variable_value_t *v, uintptr_t data); 55 ngx_http_variable_value_t *v, uintptr_t data);
170 172
171 { ngx_string("request_filename"), NULL, 173 { ngx_string("request_filename"), NULL,
172 ngx_http_variable_request_filename, 0, 174 ngx_http_variable_request_filename, 0,
173 NGX_HTTP_VAR_NOCACHEABLE, 0 }, 175 NGX_HTTP_VAR_NOCACHEABLE, 0 },
174 176
175 { ngx_string("server_name"), NULL, ngx_http_variable_request, 177 { ngx_string("server_name"), NULL, ngx_http_variable_server_name, 0, 0, 0 },
176 offsetof(ngx_http_request_t, server_name), 0, 0 },
177 178
178 { ngx_string("request_method"), NULL, 179 { ngx_string("request_method"), NULL,
179 ngx_http_variable_request_method, 0, 0, 0 }, 180 ngx_http_variable_request_method, 0, 0, 0 },
180 181
181 { ngx_string("remote_user"), NULL, ngx_http_variable_remote_user, 0, 0, 0 }, 182 { ngx_string("remote_user"), NULL, ngx_http_variable_remote_user, 0, 0, 0 },
707 708
708 static ngx_int_t 709 static ngx_int_t
709 ngx_http_variable_host(ngx_http_request_t *r, ngx_http_variable_value_t *v, 710 ngx_http_variable_host(ngx_http_request_t *r, ngx_http_variable_value_t *v,
710 uintptr_t data) 711 uintptr_t data)
711 { 712 {
713 ngx_http_core_srv_conf_t *cscf;
714
712 if (r->host_start == NULL) { 715 if (r->host_start == NULL) {
713 716
714 if (r->headers_in.host) { 717 if (r->headers_in.host) {
715 v->len = r->headers_in.host_name_len; 718 v->len = r->headers_in.host_name_len;
716 v->data = r->headers_in.host->value.data; 719 v->data = r->headers_in.host->value.data;
717 720
718 } else { 721 } else {
719 v->len = r->server_name.len; 722 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
720 v->data = r->server_name.data; 723
724 v->len = cscf->server_name.len;
725 v->data = cscf->server_name.data;
721 } 726 }
722 727
723 } else if (r->host_end) { 728 } else if (r->host_end) {
724 v->len = r->host_end - r->host_start; 729 v->len = r->host_end - r->host_start;
725 v->data = r->host_start; 730 v->data = r->host_start;
806 811
807 static ngx_int_t 812 static ngx_int_t
808 ngx_http_variable_server_addr(ngx_http_request_t *r, 813 ngx_http_variable_server_addr(ngx_http_request_t *r,
809 ngx_http_variable_value_t *v, uintptr_t data) 814 ngx_http_variable_value_t *v, uintptr_t data)
810 { 815 {
811 socklen_t len; 816 ngx_str_t s;
812 ngx_connection_t *c; 817
813 struct sockaddr_in sin; 818 s.data = ngx_palloc(r->pool, INET_ADDRSTRLEN);
814 819 if (s.data == NULL) {
815 v->data = ngx_palloc(r->pool, INET_ADDRSTRLEN);
816 if (v->data == NULL) {
817 return NGX_ERROR; 820 return NGX_ERROR;
818 } 821 }
819 822
820 c = r->connection; 823 if (ngx_http_server_addr(r, &s) != NGX_OK) {
821 824 return NGX_ERROR;
822 if (r->in_addr == 0) { 825 }
823 len = sizeof(struct sockaddr_in); 826
824 if (getsockname(c->fd, (struct sockaddr *) &sin, &len) == -1) { 827 v->len = s.len;
825 ngx_connection_error(c, ngx_socket_errno, "getsockname() failed"); 828 v->valid = 1;
826 return NGX_ERROR; 829 v->no_cacheable = 0;
827 } 830 v->not_found = 0;
828 831 v->data = s.data;
829 r->in_addr = sin.sin_addr.s_addr;
830 }
831
832 v->len = ngx_inet_ntop(c->listening->family, &r->in_addr,
833 v->data, INET_ADDRSTRLEN);
834 v->valid = 1;
835 v->no_cacheable = 0;
836 v->not_found = 0;
837 832
838 return NGX_OK; 833 return NGX_OK;
839 } 834 }
840 835
841 836
959 v->len = path.len - 1; 954 v->len = path.len - 1;
960 v->valid = 1; 955 v->valid = 1;
961 v->no_cacheable = 0; 956 v->no_cacheable = 0;
962 v->not_found = 0; 957 v->not_found = 0;
963 v->data = path.data; 958 v->data = path.data;
959
960 return NGX_OK;
961 }
962
963
964 static ngx_int_t
965 ngx_http_variable_server_name(ngx_http_request_t *r,
966 ngx_http_variable_value_t *v, uintptr_t data)
967 {
968 ngx_http_core_srv_conf_t *cscf;
969
970 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
971
972 v->len = cscf->server_name.len;
973 v->valid = 1;
974 v->no_cacheable = 0;
975 v->not_found = 0;
976 v->data = cscf->server_name.data;
964 977
965 return NGX_OK; 978 return NGX_OK;
966 } 979 }
967 980
968 981