diff 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
line wrap: on
line diff
--- a/src/http/ngx_http_variables.c
+++ b/src/http/ngx_http_variables.c
@@ -47,6 +47,8 @@ static ngx_int_t ngx_http_variable_docum
     ngx_http_variable_value_t *v, uintptr_t data);
 static ngx_int_t ngx_http_variable_request_filename(ngx_http_request_t *r,
     ngx_http_variable_value_t *v, uintptr_t data);
+static ngx_int_t ngx_http_variable_server_name(ngx_http_request_t *r,
+    ngx_http_variable_value_t *v, uintptr_t data);
 static ngx_int_t ngx_http_variable_request_method(ngx_http_request_t *r,
     ngx_http_variable_value_t *v, uintptr_t data);
 static ngx_int_t ngx_http_variable_remote_user(ngx_http_request_t *r,
@@ -172,8 +174,7 @@ static ngx_http_variable_t  ngx_http_cor
       ngx_http_variable_request_filename, 0,
       NGX_HTTP_VAR_NOCACHEABLE, 0 },
 
-    { ngx_string("server_name"), NULL, ngx_http_variable_request,
-      offsetof(ngx_http_request_t, server_name), 0, 0 },
+    { ngx_string("server_name"), NULL, ngx_http_variable_server_name, 0, 0, 0 },
 
     { ngx_string("request_method"), NULL,
       ngx_http_variable_request_method, 0, 0, 0 },
@@ -709,6 +710,8 @@ static ngx_int_t
 ngx_http_variable_host(ngx_http_request_t *r, ngx_http_variable_value_t *v,
     uintptr_t data)
 {
+    ngx_http_core_srv_conf_t  *cscf;
+
     if (r->host_start == NULL) {
 
         if (r->headers_in.host) {
@@ -716,8 +719,10 @@ ngx_http_variable_host(ngx_http_request_
             v->data = r->headers_in.host->value.data;
 
         } else {
-            v->len = r->server_name.len;
-            v->data = r->server_name.data;
+            cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
+
+            v->len = cscf->server_name.len;
+            v->data = cscf->server_name.data;
         }
 
     } else if (r->host_end) {
@@ -808,32 +813,22 @@ static ngx_int_t
 ngx_http_variable_server_addr(ngx_http_request_t *r,
     ngx_http_variable_value_t *v, uintptr_t data)
 {
-    socklen_t            len;
-    ngx_connection_t    *c;
-    struct sockaddr_in   sin;
+    ngx_str_t  s;
 
-    v->data = ngx_palloc(r->pool, INET_ADDRSTRLEN);
-    if (v->data == NULL) {
+    s.data = ngx_palloc(r->pool, INET_ADDRSTRLEN);
+    if (s.data == NULL) {
         return NGX_ERROR;
     }
 
-    c = r->connection;
-
-    if (r->in_addr == 0) {
-        len = sizeof(struct sockaddr_in);
-        if (getsockname(c->fd, (struct sockaddr *) &sin, &len) == -1) {
-            ngx_connection_error(c, ngx_socket_errno, "getsockname() failed");
-            return NGX_ERROR;
-        }
-
-        r->in_addr = sin.sin_addr.s_addr;
+    if (ngx_http_server_addr(r, &s) != NGX_OK) {
+        return NGX_ERROR;
     }
 
-    v->len = ngx_inet_ntop(c->listening->family, &r->in_addr,
-                           v->data, INET_ADDRSTRLEN);
+    v->len = s.len;
     v->valid = 1;
     v->no_cacheable = 0;
     v->not_found = 0;
+    v->data = s.data;
 
     return NGX_OK;
 }
@@ -967,6 +962,24 @@ ngx_http_variable_request_filename(ngx_h
 
 
 static ngx_int_t
+ngx_http_variable_server_name(ngx_http_request_t *r,
+    ngx_http_variable_value_t *v, uintptr_t data)
+{
+    ngx_http_core_srv_conf_t  *cscf;
+
+    cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
+
+    v->len = cscf->server_name.len;
+    v->valid = 1;
+    v->no_cacheable = 0;
+    v->not_found = 0;
+    v->data = cscf->server_name.data;
+
+    return NGX_OK;
+}
+
+
+static ngx_int_t
 ngx_http_variable_request_method(ngx_http_request_t *r,
     ngx_http_variable_value_t *v, uintptr_t data)
 {