コード例 #1
0
        public void ExtensionsShouldBeSeparatedByColons()
        {
            var extensions = new[] { "first", "second" };

            var request = new WebSocketRequest("localhost:80", "path", extensions: extensions);

            Assert.IsTrue(request.Headers.ContainsKey("Sec-WebSocket-Extensions"));
            Assert.AreEqual("first;second", request.Headers["Sec-WebSocket-Extensions"]);
        }
コード例 #2
0
        public void ProtocolsShouldBeSeparatedByColons()
        {
            var protocols = new[] {"first", "second"};

            var request = new WebSocketRequest("localhost:80", "path", protocols);

            Assert.IsTrue(request.Headers.ContainsKey("Sec-WebSocket-Protocol"));
            Assert.AreEqual("first;second", request.Headers["Sec-WebSocket-Protocol"]);
        }
コード例 #3
0
        public void Connect()
        {
            _logger.Debug("Starting connect.");
            var handshake = _tcpClient.ReceiveAsync()
                                      .ContinueWith(bytes =>
                                      {
                                          var responseBytes = bytes.Result;
                                       
                                          var responseString = Encoding.UTF8.GetString(responseBytes);
                                       
                                          var response = _responseParser.Parse(responseString);
                                       
                                          _logger.Debug("Received response from handshake: {0}", response.StatusCode);
                                          if (response.StatusCode != HttpStatusCode.SwitchingProtocols)
                                              OnError(new WebSocketException(WebSocketStatusCode.TLSHandshake));
                                      });
            handshake.ContinueWith(t => OnError(t.Exception), TaskContinuationOptions.OnlyOnFaulted)
                     .ContinueWith(_ => OnClose(), TaskContinuationOptions.OnlyOnRanToCompletion)
                     .ContinueWith(_ => Dispose(), TaskContinuationOptions.OnlyOnRanToCompletion);

            handshake.ContinueWith(_ => Receive(), TaskContinuationOptions.OnlyOnRanToCompletion)
                     .ContinueWith(_ => OnOpen(), TaskContinuationOptions.OnlyOnRanToCompletion)
                     .ContinueWith(_ => _handshakeFinished.Set(), TaskContinuationOptions.OnlyOnRanToCompletion);

            _logger.Debug("Initiating handshake.");
            var request = new WebSocketRequest(_location.DnsSafeHost, _location.PathAndQuery);
            _tcpClient.SendAsync(request.ToBytes());
        }
コード例 #4
0
        public void ToStringShouldEndWithCarrageReturnNewLine()
        {
            var request = new WebSocketRequest("localhost:80", "path");

            Assert.IsTrue(request.ToString().EndsWith("\r\n"));
        }
コード例 #5
0
        public void ShouldBeAGetRequest()
        {
            var request = new WebSocketRequest("localhost:80","path");

            Assert.AreEqual("GET", request.Method);
        }
コード例 #6
0
        public void ToStringShouldStartWithGetPathAndHttpHeader()
        {
            var request = new WebSocketRequest("localhost:80", "path");

            Assert.IsTrue(request.ToString().StartsWith("GET path HTTP/1.1\r\n"));
        }
コード例 #7
0
        public void ShouldContainWebSocketKeyHeader()
        {
            var request = new WebSocketRequest("localhost:80", "path");

            Assert.IsTrue(request.Headers.ContainsKey("Sec-WebSocket-Key"));
        }
コード例 #8
0
        public void ShouldContainUpgradeHeader()
        {
            var request = new WebSocketRequest("localhost:80", "path");

            Assert.IsTrue(request.Headers.ContainsKey("Upgrade"));
        }
コード例 #9
0
        public void ShouldContainHostHeader()
        {
            var request = new WebSocketRequest("localhost:80", "path");

            Assert.AreEqual("localhost:81", request.Headers["Host"]);
        }
コード例 #10
0
        public void ShouldPassThroughtThePath()
        {
            var request = new WebSocketRequest("localhost:80", "path");

            Assert.AreEqual("path", request.Path);
        }