Пример #1
0
    internal static HttpResponse CreateWebSocketResponse ()
    {
      var res = new HttpResponse (HttpStatusCode.SwitchingProtocols);

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

      return res;
    }
Пример #2
0
    internal static HttpResponse CreateUnauthorizedResponse (string challenge)
    {
      var res = new HttpResponse (HttpStatusCode.Unauthorized);
      res.Headers["WWW-Authenticate"] = challenge;

      return res;
    }
Пример #3
0
    internal static HttpResponse CreateCloseResponse (HttpStatusCode code)
    {
      var res = new HttpResponse (code);
      res.Headers["Connection"] = "close";

      return res;
    }
Пример #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;
 }
Пример #5
0
    // As server
    internal void Close (HttpResponse response)
    {
      _readyState = WebSocketState.Closing;

      sendHttpResponse (response);
      releaseServerResources ();

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