示例#1
0
文件: Http.cs 项目: orf53975/PeaRoxy
        public static void DirectHandle(
            ProxyClient client,
            string clientConnectionAddress,
            ushort clientConnectionPort,
            byte[] firstResponse)
        {
            if (client.Controller.SmartPear.ForwarderHttpEnable && client.IsSmartForwarderEnable)
            {
                ServerType ac = new NoServer();
                if (client.Controller.SmartPear.DetectorHttpCheckEnable)
                {
                    ac.NoDataTimeout = client.Controller.ActiveServer.NoDataTimeout;
                    if (client.Controller.SmartPear.DetectorTimeoutEnable)
                    {
                        // If we have Timeout Detector then let change timeout
                        ac.NoDataTimeout = client.Controller.SmartPear.DetectorTimeout;
                    }

                    client.SmartDataSentCallbackForHttpConnections(firstResponse);
                    ac.Establish(
                        clientConnectionAddress,
                        clientConnectionPort,
                        client,
                        firstResponse,
                        delegate(ref byte[] data, ServerType thisactiveServer, ProxyClient thisclient)
                    {
                        if (IsHttp(data, true))
                        {
                            thisclient.SmartCleanTheForwarder();
                            Handle(data, thisclient, true);
                            return(false);
                        }

                        return(thisclient.SmartDataSentCallbackForHttpConnections(data));
                    },
                        (ref byte[] data, ServerType thisactiveServer, ProxyClient thisclient) =>
                        thisclient.SmartDataReceivedCallbackForHttpConnections(ref data, thisactiveServer),
                        (success, thisactiveServer, thisclient) =>
                        thisclient.SmartStatusCallbackForHttpConnections(thisactiveServer, success));
                }
                else
                {
                    ac.NoDataTimeout = client.Controller.ActiveServer.NoDataTimeout;
                    if (client.Controller.SmartPear.DetectorTimeoutEnable)
                    {
                        // If we have Timeout Detector then let change timeout
                        ac.NoDataTimeout = client.Controller.SmartPear.DetectorTimeout;
                    }

                    client.SmartDataSentCallbackForHttpConnections(firstResponse);
                    ac.Establish(
                        clientConnectionAddress,
                        clientConnectionPort,
                        client,
                        firstResponse,
                        delegate(ref byte[] data, ServerType thisactiveServer, ProxyClient thisclient)
                    {
                        if (IsHttp(data, true))
                        {
                            Handle(data, thisclient, true);
                            return(false);
                        }

                        return(thisclient.SmartDataSentCallbackForHttpConnections(data));
                    },
                        (ref byte[] data, ServerType thisactiveServer, ProxyClient thisclient) =>
                        thisclient.SmartDataReceivedCallbackForHttpConnections(ref data, thisactiveServer),
                        (success, thisactiveServer, thisclient) =>
                        thisclient.SmartStatusCallbackForHttpConnections(thisactiveServer, success));
                }
            }
            else
            {
                ServerType ac = client.Controller.ActiveServer.Clone();
                if (!client.IsSmartForwarderEnable && client.Controller.SmartPear.ForwarderHttpEnable &&
                    (client.Controller.SmartPear.DetectorHttpCheckEnable ||
                     client.Controller.SmartPear.DetectorDnsPoisoningEnable))
                {
                    ac.Establish(
                        clientConnectionAddress,
                        clientConnectionPort,
                        client,
                        firstResponse,
                        delegate(ref byte[] data, ServerType thisactiveServer, ProxyClient thisclient)
                    {
                        if (IsHttp(data, true))
                        {
                            if (client.Controller.SmartPear.ForwarderHttpEnable &&
                                !client.IsSmartForwarderEnable)
                            {
                                thisclient.SmartCleanTheForwarder();
                            }

                            Handle(data, thisclient, true);
                            return(false);
                        }

                        return(true);
                    },
                        (ref byte[] data, ServerType thisactiveServer, ProxyClient thisclient) =>
                        thisclient.SmartDataReceivedCallbackForHttpConnections(ref data, thisactiveServer));
                }
                else
                {
                    ac.Establish(
                        clientConnectionAddress,
                        clientConnectionPort,
                        client,
                        firstResponse,
                        delegate(ref byte[] data, ServerType thisactiveServer, ProxyClient thisclient)
                    {
                        if (IsHttp(data, true))
                        {
                            if (client.Controller.SmartPear.ForwarderHttpEnable &&
                                !client.IsSmartForwarderEnable)
                            {
                                thisclient.SmartCleanTheForwarder();
                            }

                            Handle(data, thisclient, true);
                            return(false);
                        }

                        return(true);
                    });
                }
            }
        }