From d10404041cf227ac9540c16733bb3e21f7cbb77b Mon Sep 17 00:00:00 2001 From: Gunnar Hinriksson Date: Thu, 8 Nov 2012 11:36:38 +0100 Subject: [PATCH 1/2] Fix: How apache mod gets port number from request. Uses System.Uri for getting the port number from the http request, makes ipv6 work. Might not be the best way since it could have performance penalties. --- src/Mono.WebServer.Apache/ModMonoWorker.cs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/Mono.WebServer.Apache/ModMonoWorker.cs b/src/Mono.WebServer.Apache/ModMonoWorker.cs index 8b9a85a9..5d210bba 100644 --- a/src/Mono.WebServer.Apache/ModMonoWorker.cs +++ b/src/Mono.WebServer.Apache/ModMonoWorker.cs @@ -192,14 +192,11 @@ void InnerRun (object state) string vhost = rr.Request.GetRequestHeader ("Host"); int port = -1; if (vhost != null) { - int colon = vhost.IndexOf (':'); - if (colon != -1) { - port = Int32.Parse (vhost.Substring (colon + 1)); - vhost = vhost.Substring (0, colon); - } else { - port = 80; - } - } + Uri u = new Uri("http://" + vhost); + port = u.Port; + } else { + port = 80; + } string vServerName = rr.Request.GetVirtualServerName (); if (vServerName == null) From 905ae013cfb340c79565cb07a0763bafb056a048 Mon Sep 17 00:00:00 2001 From: Gunnar Hinriksson Date: Thu, 8 Nov 2012 13:30:18 +0100 Subject: [PATCH 2/2] Fix: How apache mod gets port number from request. Removed last commit's modification. Detects whether the host is an ipv6 address and gets the port number accordingly. --- src/Mono.WebServer.Apache/ModMonoWorker.cs | 25 +++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/Mono.WebServer.Apache/ModMonoWorker.cs b/src/Mono.WebServer.Apache/ModMonoWorker.cs index 5d210bba..74be2579 100644 --- a/src/Mono.WebServer.Apache/ModMonoWorker.cs +++ b/src/Mono.WebServer.Apache/ModMonoWorker.cs @@ -191,11 +191,26 @@ void InnerRun (object state) string vhost = rr.Request.GetRequestHeader ("Host"); int port = -1; - if (vhost != null) { - Uri u = new Uri("http://" + vhost); - port = u.Port; - } else { - port = 80; + if (vhost != null) { + if (vhost.Contains("[") && vhost.Contains("]")) { + //ipv6 + int colon = vhost.IndexOf ("]:"); + if (colon != -1) { + port = Int32.Parse (vhost.Substring (colon +1)); + vhost = vhost.Substring( vhost.IndexOf('['), vhost.IndexOf(']') ); + } else { + port = 80; + } + } else { + //ipv4 or hostname + int colon = vhost.IndexOf (':'); + if (colon != -1) { + port = Int32.Parse (vhost.Substring (colon + 1)); + vhost = vhost.Substring (0, colon); + } else { + port = 80; + } + } } string vServerName = rr.Request.GetVirtualServerName ();