Ejemplo n.º 1
0
        public override void Handle(ProxyRequest req)
        {
            using (var proxyStreamSsl = new SslStream(this.ProxyStream, true))
            {
                if (req.KeepAlive)
                {
                    this.ProxyStream.Write(ConnectionEstablishedKA, 0, ConnectionEstablishedKA.Length);
                }
                else
                {
                    this.ProxyStream.Write(ConnectionEstablished, 0, ConnectionEstablished.Length);
                }

                proxyStreamSsl.AuthenticateAsServer(this.m_certificate, false, this.m_sslProtocols, false);

                req.Dispose();

                while (ProxyRequest.TryParse(proxyStreamSsl, true, out req))
                {
                    using (req)
                        using (var resp = new ProxyResponse(proxyStreamSsl))
                        {
                            try
                            {
                                this.m_handler(new ProxyContext(req, resp));
                            }
                            catch
                            {
                                if (!resp.HeaderSent)
                                {
                                    resp.Headers.Clear();
                                    resp.StatusCode = HttpStatusCode.InternalServerError;
                                }

                                throw;
                            }
                        }

                    if (!req.KeepAlive)
                    {
                        break;
                    }
                }
            }
        }