Exemple #1
0
 public void IsRequestKeyValid()
 {
     foreach (var key in _requestKeys)
     {
         HandshakeHelpers.IsRequestKeyValid(key);
     }
 }
Exemple #2
0
        public static bool CheckSupportedWebSocketRequest(string method, IHeaderDictionary requestHeaders)
        {
            if (!HttpMethods.IsGet(method))
            {
                return(false);
            }

            if (!CheckWebSocketVersion(requestHeaders))
            {
                return(false);
            }

            var foundHeader = false;

            var values = requestHeaders.GetCommaSeparatedValues(HeaderNames.Upgrade);

            foreach (var value in values)
            {
                if (string.Equals(value, Constants.Headers.UpgradeWebSocket, StringComparison.OrdinalIgnoreCase))
                {
                    // WebSockets are long lived; so if the header values are valid we switch them out for the interned versions.
                    if (values.Length == 1)
                    {
                        requestHeaders.Upgrade = Constants.Headers.UpgradeWebSocket;
                    }
                    foundHeader = true;
                    break;
                }
            }
            if (!foundHeader)
            {
                return(false);
            }
            foundHeader = false;

            values = requestHeaders.GetCommaSeparatedValues(HeaderNames.Connection);
            foreach (var value in values)
            {
                if (string.Equals(value, HeaderNames.Upgrade, StringComparison.OrdinalIgnoreCase))
                {
                    // WebSockets are long lived; so if the header values are valid we switch them out for the interned versions.
                    if (values.Length == 1)
                    {
                        requestHeaders.Connection = HeaderNames.Upgrade;
                    }
                    foundHeader = true;
                    break;
                }
            }
            if (!foundHeader)
            {
                return(false);
            }

            return(HandshakeHelpers.IsRequestKeyValid(requestHeaders.SecWebSocketKey.ToString()));
        }
Exemple #3
0
 public void RejectsInvalidRequestKeys(string key)
 {
     Assert.False(HandshakeHelpers.IsRequestKeyValid(key));
 }
Exemple #4
0
 public void AcceptsValidRequestKeys(string key)
 {
     Assert.True(HandshakeHelpers.IsRequestKeyValid(key));
 }