Get the value once for IsWebSocketRequest property

This commit is contained in:
sta 2014-06-02 15:33:25 +09:00
parent 94bb58f4fc
commit fa01992fa1
2 changed files with 25 additions and 9 deletions

View File

@ -39,6 +39,8 @@ namespace WebSocketSharp
private string _method;
private string _uri;
private bool _websocketRequest;
private bool _websocketRequestWasSet;
#endregion
@ -94,11 +96,17 @@ namespace WebSocketSharp
public bool IsWebSocketRequest {
get {
if (!_websocketRequestWasSet) {
var headers = Headers;
return _method == "GET" &&
_websocketRequest = _method == "GET" &&
ProtocolVersion > HttpVersion.Version10 &&
headers.Contains ("Upgrade", "websocket") &&
headers.Contains ("Connection", "Upgrade");
_websocketRequestWasSet = true;
}
return _websocketRequest;
}
}

View File

@ -83,6 +83,8 @@ namespace WebSocketSharp.Net
private Uri _url;
private string [] _userLanguages;
private Version _version;
private bool _websocketRequest;
private bool _websocketRequestWasSet;
#endregion
@ -273,10 +275,16 @@ namespace WebSocketSharp.Net
/// </value>
public bool IsWebSocketRequest {
get {
return _method == "GET" &&
if (!_websocketRequestWasSet) {
_websocketRequest = _method == "GET" &&
_version > HttpVersion.Version10 &&
_headers.Contains ("Upgrade", "websocket") &&
_headers.Contains ("Connection", "Upgrade");
_websocketRequestWasSet = true;
}
return _websocketRequest;
}
}