Inheritance: HandshakeBase
        public static HandshakeResponse CreateCloseResponse(HttpStatusCode code)
        {
            HandshakeResponse handshakeResponse = new HandshakeResponse(code);

            handshakeResponse.Headers["Connection"] = "close";
            return(handshakeResponse);
        }
        internal static HandshakeResponse CreateCloseResponse(HttpStatusCode code)
        {
            var res = new HandshakeResponse(code);

            res.Headers["Connection"] = "close";

            return(res);
        }
Beispiel #3
0
        public static HandshakeResponse CreateCloseResponse(HttpStatusCode code)
        {
            var res = new HandshakeResponse(code);

            res.AddHeader("Connection", "close");

            return(res);
        }
        internal static HandshakeResponse Parse(string[] headerParts)
        {
            var statusLine = headerParts[0].Split(new[] { ' ' }, 3);

            if (statusLine.Length != 3)
            {
                throw new ArgumentException("Invalid status line: " + headerParts[0]);
            }

            var headers = new WebHeaderCollection();

            for (int i = 1; i < headerParts.Length; i++)
            {
                headers.SetInternally(headerParts[i], true);
            }

            var res = new HandshakeResponse(new Version(statusLine[0].Substring(5)), headers);

            res._code   = statusLine[1];
            res._reason = statusLine[2];

            return(res);
        }
Beispiel #5
0
 // As client
 private bool validateConnectionResponse(HandshakeResponse response)
 {
     string accept, version;
       return response.IsWebSocketResponse &&
      ((accept = response.Headers ["Sec-WebSocket-Accept"]) != null && accept == createResponseKey ()) &&
      ((version = response.Headers ["Sec-WebSocket-Version"]) == null || version == _version);
 }
Beispiel #6
0
 // As server
 private bool send(HandshakeResponse response)
 {
     _logger.Debug ("A response to a WebSocket connection request:\n" + response.ToString ());
       return _stream.WriteHandshake (response);
 }
Beispiel #7
0
        // As server
        private HandshakeResponse createHandshakeResponse()
        {
            var res = new HandshakeResponse ();
              res.AddHeader ("Sec-WebSocket-Accept", createResponseKey ());

              if (_protocol.Length > 0)
            res.AddHeader ("Sec-WebSocket-Protocol", _protocol);

              if (_extensions.Length > 0)
            res.AddHeader ("Sec-WebSocket-Extensions", _extensions);

              if (_cookies.Count > 0)
            res.SetCookies (_cookies);

              return res;
        }
Beispiel #8
0
        // As server
        private HandshakeResponse createHandshakeResponse()
        {
            var res = new HandshakeResponse (HttpStatusCode.SwitchingProtocols);
              var headers = res.Headers;

              headers ["Sec-WebSocket-Accept"] = CreateResponseKey (_base64Key);

              if (_protocol != null)
            headers ["Sec-WebSocket-Protocol"] = _protocol;

              if (_extensions != null)
            headers ["Sec-WebSocket-Extensions"] = _extensions;

              if (_cookies.Count > 0)
            res.SetCookies (_cookies);

              return res;
        }
Beispiel #9
0
 // As client
 private string checkIfValidHandshakeResponse(HandshakeResponse response)
 {
     var headers = response.Headers;
       return response.IsUnauthorized
      ? String.Format ("HTTP {0} authorization is required.", response.AuthChallenge.Scheme)
      : !response.IsWebSocketResponse
        ? "Not WebSocket connection response."
        : !validateSecWebSocketAcceptHeader (headers ["Sec-WebSocket-Accept"])
          ? "Invalid Sec-WebSocket-Accept header."
          : !validateSecWebSocketProtocolHeader (headers ["Sec-WebSocket-Protocol"])
            ? "Invalid Sec-WebSocket-Protocol header."
            : !validateSecWebSocketExtensionsHeader (headers ["Sec-WebSocket-Extensions"])
              ? "Invalid Sec-WebSocket-Extensions header."
              : !validateSecWebSocketVersionServerHeader (headers ["Sec-WebSocket-Version"])
                ? "Invalid Sec-WebSocket-Version header."
                : null;
 }
Beispiel #10
0
        // As server
        internal void Close(HandshakeResponse response)
        {
            _readyState = WebSocketState.Closing;

              send (response);
              closeServerResources ();

              _readyState = WebSocketState.Closed;
        }
    public static HandshakeResponse CreateCloseResponse (HttpStatusCode code)
    {
      var res = new HandshakeResponse (code);
      res.Headers ["Connection"] = "close";

      return res;
    }
    internal static HandshakeResponse Parse (string[] headerParts)
    {
      var statusLine = headerParts[0].Split (new[] { ' ' }, 3);
      if (statusLine.Length != 3)
        throw new ArgumentException ("Invalid status line: " + headerParts[0]);

      var headers = new WebHeaderCollection ();
      for (int i = 1; i < headerParts.Length; i++)
        headers.SetInternally (headerParts[i], true);

      var res = new HandshakeResponse (new Version (statusLine[0].Substring (5)), headers);
      res._code = statusLine[1];
      res._reason = statusLine[2];

      return res;
    }
Beispiel #13
0
    // As client
    private string checkIfValidHandshakeResponse (HandshakeResponse response)
    {
      var headers = response.Headers;

      string accept, version;
      return response.IsUnauthorized
             ? String.Format (
                 "An HTTP {0} authorization is required.",
                 response.AuthChallenge.Scheme)
             : !response.IsWebSocketResponse
               ? "Not WebSocket connection response to the connection request."
               : (accept = headers ["Sec-WebSocket-Accept"]) == null ||
                 accept != CreateResponseKey (_base64Key)
                 ? "Invalid Sec-WebSocket-Accept header."
                 : (version = headers ["Sec-WebSocket-Version"]) != null &&
                   version != _version
                   ? "Invalid Sec-WebSocket-Version header."
                   : null;
    }