Skip to content
This repository has been archived by the owner on Jul 9, 2023. It is now read-only.

Commit

Permalink
Merge pull request #57 from justcoding121/release
Browse files Browse the repository at this point in the history
move header prepare method right after user callback
  • Loading branch information
justcoding121 committed Mar 22, 2016
2 parents 9e3ec34 + c25bbb1 commit a4d42ab
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions Titanium.Web.Proxy/RequestHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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)
Expand Down Expand Up @@ -314,20 +316,21 @@ private static void WriteConnectResponse(StreamWriter clientStreamWriter, string
clientStreamWriter.Flush();
}

private static void SetRequestHeaders(List<HttpHeader> requestHeaders, HttpWebSession webRequest)
private static void PrepareRequestHeaders(List<HttpHeader> requestHeaders, HttpWebSession webRequest)
{
for (var i = 0; i < requestHeaders.Count; i++)
{
switch (requestHeaders[i].Name.ToLower())
{
case "accept-encoding":
requestHeaders[i].Value = "gzip,deflate,zlib";
break;
break;

default:
break;
}
}

FixRequestProxyHeaders(requestHeaders);
webRequest.Request.RequestHeaders = requestHeaders;
}
Expand Down

0 comments on commit a4d42ab

Please sign in to comment.