public override async Task HandleTcpConnection(InConnectionTcp connection) { var stream = await connection.HandleAndGetStream(this); HttpConnection httpConnection = CreateHttpConnectionFromMyStream(stream, HttpSvr); await httpConnection.Process(); }
public override async Task HandleTcpConnection(InConnectionTcp connection) { Exception e = null; ConnectResult connectResult = null; try { connectResult = await Connect(connection); } catch (Exception ex) when(if_failed != null) { Logging.exception(ex, Logging.Level.Error, $"{this}: {connection} failed ({connectResult.FailedReason}), redirecting to {if_failed}."); connection.RedirectTo(if_failed); return; } if (!connectResult.Ok && if_failed != null) { Logging.warning($": {connection} failed ({connectResult.FailedReason}), redirecting to {if_failed}."); connection.RedirectTo(if_failed); return; } try { if (connectResult.Ok) { await connection.HandleAndPutStream(this, connectResult.Stream, connectResult.WhenCanRead); } else { await connection.HandleAndGetStream(connectResult); } } finally { if (connectResult.Ok) { MyStream.CloseWithTimeout(connectResult.Stream); } } }
public async Task HandleTcpConnection(InConnectionTcp connection) { var stream = await connection.HandleAndGetStream(this); var httpConn = WebBaseAdapter.CreateHttpConnectionFromMyStream(stream, httpServer); await httpConn.Process(); }
public override async Task HandleTcpConnection(InConnectionTcp connection) { await connection.HandleAndGetStream(GetConnectResult()); }
public override async Task HandleTcpConnection(InConnectionTcp connection) { var host = connection.Dest.Host; var name = TryGetName(host); if (name != null) { if (name.Length == 0 || name == list_name) { if (connection.Dest.Port == 80) { goto LIST; } } else { var cli = FindClientByName(name); if (cli != null) { await cli.HandleConnection(connection); } else if (if_notfound == null) { await connection.HandleAndGetStream(new ConnectResult(this, ConnectResultEnum.Failed) { FailedReason = "no such client" }); } else { connection.RedirectTo(if_notfound); } } } else { if (enable_ip && AddrPort.TryParseIpv4(host, out var ip)) { if (ipmap.TryGetValue(ip, out var cli)) { await cli.HandleConnection(connection); return; } else if (ip == listIp) { goto LIST; } } if (if_notmatch != null) { connection.RedirectTo(if_notmatch); } } return; LIST: var stream = await connection.HandleAndGetStream(this); var httpConnection = CreateHttpConnectionFromMyStream(stream, HttpSvr); httpConnection.SetTag("connection", connection); await httpConnection.Process(); }