Exemplo n.º 1
0
    internal static HttpResponse CreateWebSocketResponse ()
    {
      var res = new HttpResponse (HttpStatusCode.SwitchingProtocols);

      var headers = res.Headers;
      headers["Upgrade"] = "websocket";
      headers["Connection"] = "Upgrade";

      return res;
    }
Exemplo n.º 2
0
    internal static HttpResponse CreateUnauthorizedResponse (string challenge)
    {
      var res = new HttpResponse (HttpStatusCode.Unauthorized);
      res.Headers["WWW-Authenticate"] = challenge;

      return res;
    }
Exemplo n.º 3
0
    internal static HttpResponse CreateCloseResponse (HttpStatusCode code)
    {
      var res = new HttpResponse (code);
      res.Headers["Connection"] = "close";

      return res;
    }
Exemplo n.º 4
0
 // As client
 private string checkIfValidHandshakeResponse (HttpResponse response)
 {
   var headers = response.Headers;
   return response.IsRedirect
          ? "Indicates the redirection."
          : response.IsUnauthorized
            ? "Requires the authentication."
            : !response.IsWebSocketResponse
              ? "Not a WebSocket connection response."
              : !validateSecWebSocketAcceptHeader (headers["Sec-WebSocket-Accept"])
                ? "Includes an invalid Sec-WebSocket-Accept header."
                : !validateSecWebSocketProtocolHeader (headers["Sec-WebSocket-Protocol"])
                  ? "Includes an invalid Sec-WebSocket-Protocol header."
                  : !validateSecWebSocketExtensionsHeader (headers["Sec-WebSocket-Extensions"])
                    ? "Includes an invalid Sec-WebSocket-Extensions header."
                    : !validateSecWebSocketVersionServerHeader (headers["Sec-WebSocket-Version"])
                      ? "Includes an invalid Sec-WebSocket-Version header."
                      : null;
 }
Exemplo n.º 5
0
    // As server
    internal void Close (HttpResponse response)
    {
      _readyState = WebSocketState.Closing;

      sendHttpResponse (response);
      releaseServerResources ();

      _readyState = WebSocketState.Closed;
    }
Exemplo n.º 6
0
 // As server
 private bool sendHttpResponse (HttpResponse response)
 {
   _logger.Debug ("A response to this request:\n" + response.ToString ());
   return sendBytes (response.ToByteArray ());
 }