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

Commit c25bbb1

Browse files
committed
move header prepare method right after user callback
1 parent ab92537 commit c25bbb1

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

Titanium.Web.Proxy/RequestHandler.cs

+14-11
Original file line numberDiff line numberDiff line change
@@ -217,18 +217,12 @@ private static void HandleHttpSessionRequest(TcpClient client, string httpCmd, S
217217
args.ProxySession.Request.RequestHeaders.Add(new HttpHeader(header[0], header[1]));
218218
}
219219

220-
SetRequestHeaders(args.ProxySession.Request.RequestHeaders, args.ProxySession);
220+
221221

222222
var httpRemoteUri = new Uri(!IsHttps ? httpCmdSplit[1] : (string.Concat("https://", args.ProxySession.Request.Host, httpCmdSplit[1])));
223223
args.IsHttps = IsHttps;
224224

225-
if (args.ProxySession.Request.UpgradeToWebSocket)
226-
{
227-
TcpHelper.SendRaw(clientStream, httpCmd, args.ProxySession.Request.RequestHeaders,
228-
httpRemoteUri.Host, httpRemoteUri.Port, args.IsHttps);
229-
Dispose(client, clientStream, clientStreamReader, clientStreamWriter, args);
230-
return;
231-
}
225+
232226

233227
args.ProxySession.Request.RequestUri = httpRemoteUri;
234228

@@ -252,7 +246,15 @@ private static void HandleHttpSessionRequest(TcpClient client, string httpCmd, S
252246
break;
253247
}
254248

249+
if (args.ProxySession.Request.UpgradeToWebSocket)
250+
{
251+
TcpHelper.SendRaw(clientStream, httpCmd, args.ProxySession.Request.RequestHeaders,
252+
httpRemoteUri.Host, httpRemoteUri.Port, args.IsHttps);
253+
Dispose(client, clientStream, clientStreamReader, clientStreamWriter, args);
254+
return;
255+
}
255256

257+
PrepareRequestHeaders(args.ProxySession.Request.RequestHeaders, args.ProxySession);
256258
//construct the web request that we are going to issue on behalf of the client.
257259
connection = connection == null ?
258260
TcpConnectionManager.GetClient(args.ProxySession.Request.RequestUri.Host, args.ProxySession.Request.RequestUri.Port, args.IsHttps)
@@ -314,20 +316,21 @@ private static void WriteConnectResponse(StreamWriter clientStreamWriter, string
314316
clientStreamWriter.Flush();
315317
}
316318

317-
private static void SetRequestHeaders(List<HttpHeader> requestHeaders, HttpWebSession webRequest)
319+
private static void PrepareRequestHeaders(List<HttpHeader> requestHeaders, HttpWebSession webRequest)
318320
{
319321
for (var i = 0; i < requestHeaders.Count; i++)
320322
{
321323
switch (requestHeaders[i].Name.ToLower())
322324
{
323325
case "accept-encoding":
324326
requestHeaders[i].Value = "gzip,deflate,zlib";
325-
break;
326-
327+
break;
328+
327329
default:
328330
break;
329331
}
330332
}
333+
331334
FixRequestProxyHeaders(requestHeaders);
332335
webRequest.Request.RequestHeaders = requestHeaders;
333336
}

0 commit comments

Comments
 (0)