Пример #1
0
        public override async Task HandleTcpConnection(InConnectionTcp connection)
        {
            var stream = await connection.HandleAndGetStream(this);

            HttpConnection httpConnection = CreateHttpConnectionFromMyStream(stream, HttpSvr);
            await httpConnection.Process();
        }
Пример #2
0
        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);
                }
            }
        }
Пример #3
0
        public async Task HandleTcpConnection(InConnectionTcp connection)
        {
            var stream = await connection.HandleAndGetStream(this);

            var httpConn = WebBaseAdapter.CreateHttpConnectionFromMyStream(stream, httpServer);
            await httpConn.Process();
        }
Пример #4
0
 public override async Task HandleTcpConnection(InConnectionTcp connection)
 {
     await connection.HandleAndGetStream(GetConnectResult());
 }
Пример #5
0
        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();
        }