Refactored a few for HttpRequest.cs
This commit is contained in:
parent
a4cb03f8da
commit
df9c8b1e74
@ -26,6 +26,13 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
#region Contributors
|
||||
/*
|
||||
* Contributors:
|
||||
* - David Burhans
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Specialized;
|
||||
using System.IO;
|
||||
@ -41,7 +48,7 @@ namespace WebSocketSharp
|
||||
private string _method;
|
||||
private string _uri;
|
||||
private bool _websocketRequest;
|
||||
private bool _websocketRequestWasSet;
|
||||
private bool _websocketRequestSet;
|
||||
|
||||
#endregion
|
||||
|
||||
@ -91,14 +98,14 @@ namespace WebSocketSharp
|
||||
|
||||
public bool IsWebSocketRequest {
|
||||
get {
|
||||
if (!_websocketRequestWasSet) {
|
||||
if (!_websocketRequestSet) {
|
||||
var headers = Headers;
|
||||
_websocketRequest = _method == "GET" &&
|
||||
ProtocolVersion > HttpVersion.Version10 &&
|
||||
headers.Contains ("Upgrade", "websocket") &&
|
||||
headers.Contains ("Connection", "Upgrade");
|
||||
|
||||
_websocketRequestWasSet = true;
|
||||
_websocketRequestSet = true;
|
||||
}
|
||||
|
||||
return _websocketRequest;
|
||||
@ -129,16 +136,18 @@ namespace WebSocketSharp
|
||||
internal static HttpRequest CreateWebSocketRequest (Uri uri)
|
||||
{
|
||||
var req = new HttpRequest ("GET", uri.PathAndQuery);
|
||||
|
||||
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["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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user