about summary refs log tree commit homepage
path: root/ext/unicorn_http
diff options
context:
space:
mode:
Diffstat (limited to 'ext/unicorn_http')
-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 | ";" | ":" | "&" | "=" | "+")+ "@")*;