about summary refs log tree commit homepage
path: root/ext/unicorn_http/unicorn_http.rl
diff options
context:
space:
mode:
Diffstat (limited to 'ext/unicorn_http/unicorn_http.rl')
-rw-r--r--ext/unicorn_http/unicorn_http.rl13
1 files changed, 12 insertions, 1 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;