private void Verify(WebSocketContext Context, Action <EngineIOException> Callback)
        {
            EngineIOException Return = null;
            bool AllowWebSocket      = false;

            try
            {
                if ((Return = Verify(Context.QueryString, Context.Headers, EngineIOTransportType.websocket)) == null)
                {
                    string SID      = EngineIOHttpManager.GetSID(Context.QueryString);
                    bool   Contains = _Clients.ContainsKey(SID);

                    if (!string.IsNullOrEmpty(SID))
                    {
                        if (Contains && _Clients.TryGetValue(SID, out EngineIOSocket Socket))
                        {
                            if (Socket.Transport is EngineIOPolling && Option.AllowUpgrade && Option.WebSocket && !(Socket.Upgrading || Socket.Upgraded))
                            {
                                if (!(Socket.Upgrading || Socket.Upgraded))
                                {
                                    Socket.UpgradeTransport(new EngineIOWebSocket(Context));
                                    AllowWebSocket = true;
                                }
                                else
                                {
                                    Return = Exceptions.BAD_REQUEST;
                                }
                            }
                            else
                            {
                                Return = Exceptions.BAD_REQUEST;
                            }
                        }
                        else
                        {
                            Return = Exceptions.UNKNOWN_SID;
                        }
                    }
                    else
                    {
                        if (Option.AllowWebSocket != null)
                        {
                            AllowWebSocket = true;
                            Option.AllowWebSocket(Context, Callback);
                        }
                    }
                }
            }
            catch (Exception Exception)
            {
                EngineIOLogger.Error(this, Return = new EngineIOException("Unknown exception", Exception));
            }
            finally
            {
                if (!AllowWebSocket)
                {
                    Callback(Return);
                }
            }
        }
Example #2
0
        private void Verify(HttpListenerRequest Request, Action <EngineIOException> Callback)
        {
            EngineIOException Return = null;
            bool AllowHttpRequest    = false;

            try
            {
                if ((Return = Verify(Request.QueryString, Request.Headers, EngineIOTransportType.polling)) == null)
                {
                    string SID      = EngineIOHttpManager.GetSID(Request.QueryString);
                    bool   Contains = _Clients.ContainsKey(SID);

                    if (string.IsNullOrEmpty(SID) || Contains)
                    {
                        if (Contains && !(_Clients[SID].Transport is EngineIOPolling))
                        {
                            Return = Exceptions.BAD_REQUEST;
                        }
                        else if (EngineIOHttpManager.ParseMethod(Request.HttpMethod) == EngineIOHttpMethod.GET)
                        {
                            if (Option.AllowHttpRequest != null)
                            {
                                AllowHttpRequest = true;
                                Option.AllowHttpRequest(Request, Callback);
                            }
                        }
                        else if (string.IsNullOrEmpty(SID))
                        {
                            Return = Exceptions.BAD_HANDSHAKE_METHOD;
                        }
                    }
                    else
                    {
                        Return = Exceptions.UNKNOWN_SID;
                    }
                }
            }
            catch (Exception Exception)
            {
                EngineIOLogger.Error(this, Return = new EngineIOException("Unknown exception", Exception));
            }
            finally
            {
                if (!AllowHttpRequest)
                {
                    Callback(Return);
                }
            }
        }
Example #3
0
        private void OnHttpRequest(object sender, HttpRequestEventArgs e)
        {
            Verify(e.Request, (Exception) =>
            {
                if (Exception == null)
                {
                    string SID = EngineIOHttpManager.GetSID(e.Request.QueryString);

                    if (_Clients.TryGetValue(SID, out EngineIOSocket Client))
                    {
                        Client.Transport.OnRequest(e.Request, e.Response);
                    }
                    else
                    {
                        Handshake(EngineIOHttpManager.GetTransport(e.Request.QueryString), e.Request, e.Response);
                    }
                }
                else
                {
                    EngineIOHttpManager.SendErrorMessage(e.Request, e.Response, Exception);
                }
            });
        }