From c6e3e12aaf581ab6e6bc5b73541d961992d8d613 Mon Sep 17 00:00:00 2001 From: David Burhans Date: Wed, 3 Jun 2015 11:15:02 -0600 Subject: [PATCH 1/3] Port 443 is also a default port and should be excluded from the Host header on websocket requests for compatibility reasons --- websocket-sharp/HttpRequest.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/websocket-sharp/HttpRequest.cs b/websocket-sharp/HttpRequest.cs index 41f700e2..d7c2c842 100644 --- a/websocket-sharp/HttpRequest.cs +++ b/websocket-sharp/HttpRequest.cs @@ -133,7 +133,8 @@ namespace WebSocketSharp var headers = req.Headers; headers["Upgrade"] = "websocket"; headers["Connection"] = "Upgrade"; - headers["Host"] = uri.Port == 80 ? uri.DnsSafeHost : uri.Authority; + bool isDefaultPort = (uri.Port == 80 && uri.Scheme == "ws") || (uri.Port == 443 && uri.Scheme == "wss"); + headers["Host"] = isDefaultPort ? uri.DnsSafeHost : uri.Authority; return req; } From ab3d3bd7b50d75cf1bd48a3106a460a63d9b2789 Mon Sep 17 00:00:00 2001 From: David Burhans Date: Tue, 9 Jun 2015 08:06:04 -0600 Subject: [PATCH 2/3] fix spacing. add intermediate variables --- websocket-sharp/HttpRequest.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/websocket-sharp/HttpRequest.cs b/websocket-sharp/HttpRequest.cs index d7c2c842..d6a11d67 100644 --- a/websocket-sharp/HttpRequest.cs +++ b/websocket-sharp/HttpRequest.cs @@ -133,8 +133,12 @@ namespace WebSocketSharp var headers = req.Headers; headers["Upgrade"] = "websocket"; headers["Connection"] = "Upgrade"; - bool isDefaultPort = (uri.Port == 80 && uri.Scheme == "ws") || (uri.Port == 443 && uri.Scheme == "wss"); - headers["Host"] = isDefaultPort ? uri.DnsSafeHost : uri.Authority; + var port = uri.Port; + var scheme = uri.Scheme + bool isDefaultPort = (port == 80 && scheme == "ws") || (port == 443 && scheme == "wss"); + // only include port in host header if it is non-default + // https://tools.ietf.org/html/rfc6455#page-17 + headers["Host"] = isDefaultPort ? uri.DnsSafeHost : uri.Authority; return req; } From 23a8c1f4b17330dd56a42890b0789dd458d30399 Mon Sep 17 00:00:00 2001 From: David Burhans Date: Tue, 9 Jun 2015 09:17:25 -0600 Subject: [PATCH 3/3] add missed semicolon --- websocket-sharp/HttpRequest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/websocket-sharp/HttpRequest.cs b/websocket-sharp/HttpRequest.cs index d6a11d67..cfced5c8 100644 --- a/websocket-sharp/HttpRequest.cs +++ b/websocket-sharp/HttpRequest.cs @@ -134,7 +134,7 @@ namespace WebSocketSharp headers["Upgrade"] = "websocket"; headers["Connection"] = "Upgrade"; var port = uri.Port; - var scheme = uri.Scheme + var scheme = uri.Scheme; bool isDefaultPort = (port == 80 && scheme == "ws") || (port == 443 && scheme == "wss"); // only include port in host header if it is non-default // https://tools.ietf.org/html/rfc6455#page-17