[nginx] svn commit: r4970 - trunk/src/core

ru at nginx.com ru at nginx.com
Mon Dec 17 09:31:53 UTC 2012


Author: ru
Date: 2012-12-17 09:31:53 +0000 (Mon, 17 Dec 2012)
New Revision: 4970
URL: http://trac.nginx.org/nginx/changeset/4970/nginx

Log:
Simplified URL parsing code.

Except for the "listen" directive, "*" specified as a hostname is
no longer treated specially.


Modified:
   trunk/src/core/ngx_inet.c

Modified: trunk/src/core/ngx_inet.c
===================================================================
--- trunk/src/core/ngx_inet.c	2012-12-14 19:56:03 UTC (rev 4969)
+++ trunk/src/core/ngx_inet.c	2012-12-17 09:31:53 UTC (rev 4970)
@@ -705,6 +705,11 @@
         }
 
         u->no_port = 1;
+
+        if (!u->no_resolve) {
+            u->port = u->default_port;
+            sin->sin_port = htons(u->default_port);
+        }
     }
 
     len = last - host;
@@ -714,54 +719,45 @@
         return NGX_ERROR;
     }
 
-    if (len == 1 && *host == '*') {
-        len = 0;
-    }
-
     u->host.len = len;
     u->host.data = host;
 
+    if (u->listen && len == 1 && *host == '*') {
+        sin->sin_addr.s_addr = INADDR_ANY;
+        u->wildcard = 1;
+        return NGX_OK;
+    }
+
     if (u->no_resolve) {
         return NGX_OK;
     }
 
-    if (len) {
-        sin->sin_addr.s_addr = ngx_inet_addr(host, len);
+    sin->sin_addr.s_addr = ngx_inet_addr(host, len);
 
-        if (sin->sin_addr.s_addr == INADDR_NONE) {
-            p = ngx_alloc(++len, pool->log);
-            if (p == NULL) {
-                return NGX_ERROR;
-            }
+    if (sin->sin_addr.s_addr == INADDR_NONE) {
+        p = ngx_alloc(++len, pool->log);
+        if (p == NULL) {
+            return NGX_ERROR;
+        }
 
-            (void) ngx_cpystrn(p, host, len);
+        (void) ngx_cpystrn(p, host, len);
 
-            h = gethostbyname((const char *) p);
+        h = gethostbyname((const char *) p);
 
-            ngx_free(p);
+        ngx_free(p);
 
-            if (h == NULL || h->h_addr_list[0] == NULL) {
-                u->err = "host not found";
-                return NGX_ERROR;
-            }
-
-            sin->sin_addr.s_addr = *(in_addr_t *) (h->h_addr_list[0]);
+        if (h == NULL || h->h_addr_list[0] == NULL) {
+            u->err = "host not found";
+            return NGX_ERROR;
         }
 
-        if (sin->sin_addr.s_addr == INADDR_ANY) {
-            u->wildcard = 1;
-        }
+        sin->sin_addr.s_addr = *(in_addr_t *) (h->h_addr_list[0]);
+    }
 
-    } else {
-        sin->sin_addr.s_addr = INADDR_ANY;
+    if (sin->sin_addr.s_addr == INADDR_ANY) {
         u->wildcard = 1;
     }
 
-    if (u->no_port) {
-        u->port = u->default_port;
-        sin->sin_port = htons(u->default_port);
-    }
-
     if (u->listen) {
         return NGX_OK;
     }



More information about the nginx-devel mailing list