private void HandleConnect(bool success, INetworkConnection server) { try { if (success) { ServiceLog.Logger.Info("Established HTTPS tunnel"); _server = server; _server.DataAvailable += new EventHandler<DataAvailableEventArgs>(_server_DataAvailable); _server.ConnectionClosed += new EventHandler(_client_ConnectionClosed); _server.Shutdown += new EventHandler(_client_ConnectionClosed); _server.Start(); _client.ConnectionClosed += new EventHandler(_client_ConnectionClosed); _client.Shutdown += new EventHandler(_client_ConnectionClosed); _client.DataAvailable += new EventHandler<DataAvailableEventArgs>(_client_DataAvailable ); _client.SendData( Encoding.UTF8.GetBytes( string.Format( "HTTP/{0} 200 Connection established\r\n" + "Proxy-agent: Gallatin-Proxy/1.1\r\n\r\n", _httpVersion ) ) ); } else { ServiceLog.Logger.Warning("Unable to establish HTTPS tunnel"); OnTunnelClosed(); } } catch ( Exception ex ) { ServiceLog.Logger.Exception("Unhandled exception while trying to connect to HTTPS host", ex); OnTunnelClosed(); } }
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(); } }
private void HandleConnect( bool success, INetworkConnection connection ) { Logger.Info( "Connected to remote host" ); try { if ( success ) { lock ( _serverConnections ) { if (_activeServer != null) { Logger.Verbose("Unwiring from previous server connection"); // Do NOT unsubscribe from the session closed event here. We need that to trigger the clean up. _activeServer.DataAvailable -= ActiveServerDataAvailable; //_activeServer.ReceivedCompleteHttpResponse -= new EventHandler(_activeServer_ReceivedCompleteHttpResponse); } connection.Logger = Logger; _activeServer = new HttpServer( connection, _responseFilter ); _serverConnections.Add( _activeServer ); _activeServer.SessionClosed += ServerConnectionClosed; _activeServer.DataAvailable += ActiveServerDataAvailable; //_activeServer.ReceivedCompleteHttpResponse += new EventHandler(_activeServer_ReceivedCompleteHttpResponse); connection.Start(); _connectCallback( true ); } } else { Logger.Error( "Unable to connect to remote host. Closing proxy session." ); _connectCallback( false ); } } catch ( Exception ex ) { Logger.Exception( "Unhandled exception handling connection to remote host", ex ); _connectCallback( false ); } finally { _connectingToRemoteHost.Release(); } }