Exemple #1
0
        public HttpServer( INetworkConnection connection, IHttpResponseFilter responseFilter )
        {
            Contract.Requires( connection != null );

            _responseFilter = responseFilter;
            _connection = connection;

            connection.ConnectionClosed += ConnectionConnectionClosed;
            connection.Shutdown += ConnectionConnectionClosed;
            connection.DataAvailable += ConnectionDataAvailable;

            _parser = new HttpStreamParser();
            _parser.ReadResponseHeaderComplete += ParserReadResponseHeaderComplete;
        }
        private void ResetParser()
        {
            ServiceLog.Logger.Verbose( "{0} Resetting HTTP stream parser", Id );

            if ( _parser != null )
            {
                _parser.AdditionalDataRequested -= HandleParserAdditionalDataRequested;
                _parser.ReadRequestHeaderComplete -= HandleParserReadRequestHeaderComplete;
                _parser.PartialDataAvailable -= HandleParserPartialDataAvailable;
                _parser = null;
            }
        }
        public void Start( INetworkFacade connection )
        {
            Contract.Ensures( _clientConnection != null );
            Contract.Ensures( _parser != null );

            ServiceLog.Logger.Info( "{0} Starting new proxy client session with client ID {1}", Id, connection.Id );

            _parser = new HttpStreamParser();
            _parser.AdditionalDataRequested += HandleParserAdditionalDataRequested;
            _parser.ReadRequestHeaderComplete += HandleParserReadRequestHeaderComplete;
            _parser.PartialDataAvailable += HandleParserPartialDataAvailable;

            _clientConnection = connection;
            _clientConnection.ConnectionClosed += HandleClientConnectionClosed;

            _clientConnection.BeginReceive( ReceiveDataFromClient );

            _hasClientStoppedSendingData = false;
        }
        private void SetupClientConnection( INetworkFacade clientConnection )
        {
            ServiceLog.Logger.Info( "{0} SessionContext::SetupClientConnection", Id );

            try
            {
                lock ( _changeClientConnectionMutex )
                {
                    if (ClientParser != null)
                    {
                        ClientParser.AdditionalDataRequested -= HandleClientParserAdditionalDataRequested;
                        ClientParser.PartialDataAvailable -= HandleClientParserPartialDataAvailable;
                        ClientParser.ReadRequestHeaderComplete -= HandleClientParserReadRequestHeaderComplete;
                        ClientParser = null;
                    }

                    if (ClientConnection != null)
                    {
                        ClientConnection.ConnectionClosed -= HandleClientConnectionClosed;
                        ClientConnection.BeginClose(
                            ( s, f ) => ServiceLog.Logger.Info( "{0} Client connection closed", Id ) );
                    }

                    ClientConnection = clientConnection;

                    if ( ClientConnection != null )
                    {
                        ClientParser = new HttpStreamParser();
                        ClientParser.AdditionalDataRequested += HandleClientParserAdditionalDataRequested;
                        ClientParser.PartialDataAvailable += HandleClientParserPartialDataAvailable;
                        ClientParser.ReadRequestHeaderComplete += HandleClientParserReadRequestHeaderComplete;
                        ClientConnection.ConnectionClosed += HandleClientConnectionClosed;

                        HasClientBegunShutdown = false;

                        ClientConnection.BeginReceive( HandleClientReceive );
                    }
                }
            }
            catch ( Exception ex )
            {
                ServiceLog.Logger.Exception(
                    string.Format( "{0} Unhandled exception setting up client connection", Id ), ex );
                ChangeState( SessionStateType.Error );
            }
        }
Exemple #5
0
        public void Start( INetworkConnection connection )
        {
            _logger.Info( "Starting new proxy client session" );

            lock ( _mutex )
            {
                _parser = new HttpStreamParser();
                _parser.ReadRequestHeaderComplete += ParserReadRequestHeaderComplete;
                _parser.PartialDataAvailable += ParserPartialDataAvailable;

                _connection = connection;
                _connection.Logger = _logger;
                _connection.ConnectionClosed += ConnectionConnectionClosed;
                _connection.DataAvailable += ConnectionDataAvailable;
                _connection.Shutdown += ConnectionReceiveShutdown;
                _connection.Start();
            }
        }
Exemple #6
0
        public void Reset()
        {
            lock ( _mutex )
            {
                if ( _connection != null )
                {
                    _logger.Info( "Resetting proxy client connection" );

                    _connection.ConnectionClosed -= ConnectionConnectionClosed;
                    _connection.DataAvailable -= ConnectionDataAvailable;
                    _connection.Shutdown -= ConnectionReceiveShutdown;
                    _connection.Close();
                    _connection = null;

                    _parser.ReadRequestHeaderComplete -= ParserReadRequestHeaderComplete;
                    _parser.PartialDataAvailable -= ParserPartialDataAvailable;
                    _parser = null;

                    _serverDispatcher.Reset();

                    EventHandler sessionEndedEvent = SessionEnded;
                    if ( sessionEndedEvent != null )
                    {
                        sessionEndedEvent( this, new EventArgs() );
                    }

                    _tunnel = null;
                }
            }
        }