|
|
|
@ -26,6 +26,13 @@
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region Contributors
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
* Contributors:
|
|
|
|
|
|
|
|
* - David Burhans
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System;
|
|
|
|
using System.Collections.Specialized;
|
|
|
|
using System.Collections.Specialized;
|
|
|
|
using System.IO;
|
|
|
|
using System.IO;
|
|
|
|
@ -41,7 +48,7 @@ namespace WebSocketSharp
|
|
|
|
private string _method;
|
|
|
|
private string _method;
|
|
|
|
private string _uri;
|
|
|
|
private string _uri;
|
|
|
|
private bool _websocketRequest;
|
|
|
|
private bool _websocketRequest;
|
|
|
|
private bool _websocketRequestWasSet;
|
|
|
|
private bool _websocketRequestSet;
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
@ -91,14 +98,14 @@ namespace WebSocketSharp
|
|
|
|
|
|
|
|
|
|
|
|
public bool IsWebSocketRequest {
|
|
|
|
public bool IsWebSocketRequest {
|
|
|
|
get {
|
|
|
|
get {
|
|
|
|
if (!_websocketRequestWasSet) {
|
|
|
|
if (!_websocketRequestSet) {
|
|
|
|
var headers = Headers;
|
|
|
|
var headers = Headers;
|
|
|
|
_websocketRequest = _method == "GET" &&
|
|
|
|
_websocketRequest = _method == "GET" &&
|
|
|
|
ProtocolVersion > HttpVersion.Version10 &&
|
|
|
|
ProtocolVersion > HttpVersion.Version10 &&
|
|
|
|
headers.Contains ("Upgrade", "websocket") &&
|
|
|
|
headers.Contains ("Upgrade", "websocket") &&
|
|
|
|
headers.Contains ("Connection", "Upgrade");
|
|
|
|
headers.Contains ("Connection", "Upgrade");
|
|
|
|
|
|
|
|
|
|
|
|
_websocketRequestWasSet = true;
|
|
|
|
_websocketRequestSet = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return _websocketRequest;
|
|
|
|
return _websocketRequest;
|
|
|
|
@ -129,16 +136,18 @@ namespace WebSocketSharp
|
|
|
|
internal static HttpRequest CreateWebSocketRequest (Uri uri)
|
|
|
|
internal static HttpRequest CreateWebSocketRequest (Uri uri)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var req = new HttpRequest ("GET", uri.PathAndQuery);
|
|
|
|
var req = new HttpRequest ("GET", uri.PathAndQuery);
|
|
|
|
|
|
|
|
|
|
|
|
var headers = req.Headers;
|
|
|
|
var headers = req.Headers;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Only includes a port number in the Host header value if it's non-default.
|
|
|
|
|
|
|
|
// See: https://tools.ietf.org/html/rfc6455#page-17
|
|
|
|
|
|
|
|
var port = uri.Port;
|
|
|
|
|
|
|
|
var schm = uri.Scheme;
|
|
|
|
|
|
|
|
headers["Host"] = (port == 80 && schm == "ws") || (port == 443 && schm == "wss")
|
|
|
|
|
|
|
|
? uri.DnsSafeHost
|
|
|
|
|
|
|
|
: uri.Authority;
|
|
|
|
|
|
|
|
|
|
|
|
headers["Upgrade"] = "websocket";
|
|
|
|
headers["Upgrade"] = "websocket";
|
|
|
|
headers["Connection"] = "Upgrade";
|
|
|
|
headers["Connection"] = "Upgrade";
|
|
|
|
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;
|
|
|
|
return req;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|