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"]); }
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"]); }
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()); }
public void ToStringShouldEndWithCarrageReturnNewLine() { var request = new WebSocketRequest("localhost:80", "path"); Assert.IsTrue(request.ToString().EndsWith("\r\n")); }
public void ShouldBeAGetRequest() { var request = new WebSocketRequest("localhost:80","path"); Assert.AreEqual("GET", request.Method); }
public void ToStringShouldStartWithGetPathAndHttpHeader() { var request = new WebSocketRequest("localhost:80", "path"); Assert.IsTrue(request.ToString().StartsWith("GET path HTTP/1.1\r\n")); }
public void ShouldContainWebSocketKeyHeader() { var request = new WebSocketRequest("localhost:80", "path"); Assert.IsTrue(request.Headers.ContainsKey("Sec-WebSocket-Key")); }
public void ShouldContainUpgradeHeader() { var request = new WebSocketRequest("localhost:80", "path"); Assert.IsTrue(request.Headers.ContainsKey("Upgrade")); }
public void ShouldContainHostHeader() { var request = new WebSocketRequest("localhost:80", "path"); Assert.AreEqual("localhost:81", request.Headers["Host"]); }
public void ShouldPassThroughtThePath() { var request = new WebSocketRequest("localhost:80", "path"); Assert.AreEqual("path", request.Path); }