From 91d12041a8bd8c89dbc20d1c964e50aa8798ee56 Mon Sep 17 00:00:00 2001 From: sta Date: Mon, 30 May 2016 15:02:46 +0900 Subject: [PATCH] [Fix] Use Host if IPv6 address hostname Fix for a part of pull request #264. --- websocket-sharp/Server/HttpServer.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/websocket-sharp/Server/HttpServer.cs b/websocket-sharp/Server/HttpServer.cs index 29d174de..5498fb49 100644 --- a/websocket-sharp/Server/HttpServer.cs +++ b/websocket-sharp/Server/HttpServer.cs @@ -157,7 +157,7 @@ namespace WebSocketSharp.Server if (!tryCreateUri (url, out uri, out msg)) throw new ArgumentException (msg, "url"); - var host = uri.DnsSafeHost; + var host = getHost (uri); var addr = host.ToIPAddress (); if (!addr.IsLocal ()) throw new ArgumentException ("The host part isn't a local host name: " + url, "url"); @@ -638,6 +638,11 @@ namespace WebSocketSharp.Server : str; } + private static string getHost (Uri uri) + { + return uri.HostNameType == UriHostNameType.IPv6 ? uri.Host : uri.DnsSafeHost; + } + private void init (string hostname, System.Net.IPAddress address, int port, bool secure) { _hostname = hostname ?? convertToString (address);