about summary refs log tree commit homepage
path: root/ext
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2011-02-02 14:45:57 -0800
committerEric Wong <normalperson@yhbt.net>2011-02-02 14:45:57 -0800
commitd140e7b1ff44b06bc54c2b790d06e9c7325503fe (patch)
tree0985a4e7195bb8973a6d098cef3831ea63801db4 /ext
parent24f8ef5f385e38954a5582fb2e8cd9d12fbf7d20 (diff)
downloadunicorn-d140e7b1ff44b06bc54c2b790d06e9c7325503fe.tar.gz
Just in case we have people that don't use DNS, we can support
folks who enter ugly IPv6 addresses...

IPv6 uses brackets around the address to avoid confusing
the colons used in the address with the colon used to denote
the TCP port number in URIs.
Diffstat (limited to 'ext')
-rw-r--r--ext/unicorn_http/unicorn_http.rl13
-rw-r--r--ext/unicorn_http/unicorn_http_common.rl2
2 files changed, 13 insertions, 2 deletions
diff --git a/ext/unicorn_http/unicorn_http.rl b/ext/unicorn_http/unicorn_http.rl
index 292601c..971cdc1 100644
--- a/ext/unicorn_http/unicorn_http.rl
+++ b/ext/unicorn_http/unicorn_http.rl
@@ -505,7 +505,18 @@ static void set_server_vars(VALUE env, VALUE *server_port)
   if (!NIL_P(host)) {
     char *host_ptr = RSTRING_PTR(host);
     long host_len = RSTRING_LEN(host);
-    char *colon = memchr(host_ptr, ':', host_len);
+    char *colon;
+
+    if (*host_ptr == '[') { /* ipv6 address format */
+      char *rbracket = memchr(host_ptr + 1, ']', host_len - 1);
+
+      if (rbracket)
+        colon = (rbracket[1] == ':') ? rbracket + 1 : NULL;
+      else
+        colon = memchr(host_ptr + 1, ':', host_len - 1);
+    } else {
+      colon = memchr(host_ptr, ':', host_len);
+    }
 
     if (colon) {
       long port_start = colon - host_ptr + 1;
diff --git a/ext/unicorn_http/unicorn_http_common.rl b/ext/unicorn_http/unicorn_http_common.rl
index f165e3f..cf93fec 100644
--- a/ext/unicorn_http/unicorn_http_common.rl
+++ b/ext/unicorn_http/unicorn_http_common.rl
@@ -26,7 +26,7 @@
 
 # URI schemes and absolute paths
   scheme = ( "http"i ("s"i)? ) $downcase_char >mark %scheme;
-  hostname = (alnum | "-" | "." | "_")+;
+  hostname = ((alnum | "-" | "." | "_")+ | ("[" (":" | xdigit)+ "]"));
   host_with_port = (hostname (":" digit*)?) >mark %host;
   userinfo = ((unreserved | escape | ";" | ":" | "&" | "=" | "+")+ "@")*;