From c25bbb15a479e6ec160cd377fe537c9b5eab186e Mon Sep 17 00:00:00 2001 From: titanium007 Date: Tue, 22 Mar 2016 00:40:17 -0400 Subject: [PATCH] move header prepare method right after user callback --- Titanium.Web.Proxy/RequestHandler.cs | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/Titanium.Web.Proxy/RequestHandler.cs b/Titanium.Web.Proxy/RequestHandler.cs index c2bc58286..32dd82a1c 100644 --- a/Titanium.Web.Proxy/RequestHandler.cs +++ b/Titanium.Web.Proxy/RequestHandler.cs @@ -217,18 +217,12 @@ private static void HandleHttpSessionRequest(TcpClient client, string httpCmd, S args.ProxySession.Request.RequestHeaders.Add(new HttpHeader(header[0], header[1])); } - SetRequestHeaders(args.ProxySession.Request.RequestHeaders, args.ProxySession); + var httpRemoteUri = new Uri(!IsHttps ? httpCmdSplit[1] : (string.Concat("https://", args.ProxySession.Request.Host, httpCmdSplit[1]))); args.IsHttps = IsHttps; - if (args.ProxySession.Request.UpgradeToWebSocket) - { - TcpHelper.SendRaw(clientStream, httpCmd, args.ProxySession.Request.RequestHeaders, - httpRemoteUri.Host, httpRemoteUri.Port, args.IsHttps); - Dispose(client, clientStream, clientStreamReader, clientStreamWriter, args); - return; - } + args.ProxySession.Request.RequestUri = httpRemoteUri; @@ -252,7 +246,15 @@ private static void HandleHttpSessionRequest(TcpClient client, string httpCmd, S break; } + if (args.ProxySession.Request.UpgradeToWebSocket) + { + TcpHelper.SendRaw(clientStream, httpCmd, args.ProxySession.Request.RequestHeaders, + httpRemoteUri.Host, httpRemoteUri.Port, args.IsHttps); + Dispose(client, clientStream, clientStreamReader, clientStreamWriter, args); + return; + } + PrepareRequestHeaders(args.ProxySession.Request.RequestHeaders, args.ProxySession); //construct the web request that we are going to issue on behalf of the client. connection = connection == null ? TcpConnectionManager.GetClient(args.ProxySession.Request.RequestUri.Host, args.ProxySession.Request.RequestUri.Port, args.IsHttps) @@ -314,7 +316,7 @@ private static void WriteConnectResponse(StreamWriter clientStreamWriter, string clientStreamWriter.Flush(); } - private static void SetRequestHeaders(List requestHeaders, HttpWebSession webRequest) + private static void PrepareRequestHeaders(List requestHeaders, HttpWebSession webRequest) { for (var i = 0; i < requestHeaders.Count; i++) { @@ -322,12 +324,13 @@ private static void SetRequestHeaders(List requestHeaders, HttpWebSe { case "accept-encoding": requestHeaders[i].Value = "gzip,deflate,zlib"; - break; - + break; + default: break; } } + FixRequestProxyHeaders(requestHeaders); webRequest.Request.RequestHeaders = requestHeaders; }