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

Commit fce77d7

Browse files
authored
Merge pull request #726 from justcoding121/master
beta
2 parents f3528b7 + 27791e0 commit fce77d7

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

examples/Titanium.Web.Proxy.Examples.Basic/ProxyTestController.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ public ProxyTestController()
4242
await writeToConsole(exception.Message, ConsoleColor.Red);
4343
}
4444
};
45+
46+
proxyServer.TcpTimeWaitSeconds = 10;
47+
proxyServer.ConnectionTimeOutSeconds = 15;
48+
proxyServer.ReuseSocket = false;
49+
proxyServer.EnableConnectionPool = false;
4550
proxyServer.ForwardToUpstreamGateway = true;
4651
proxyServer.CertificateManager.SaveFakeCertificates = true;
4752
//proxyServer.ProxyBasicAuthenticateFunc = async (args, userName, password) =>

src/Titanium.Web.Proxy/Helpers/HttpStream.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1096,7 +1096,12 @@ private async Task copyBodyChunkedAsync(IHttpStreamWriter writer, Action<byte[],
10961096
{
10971097
while (true)
10981098
{
1099-
string chunkHead = (await ReadLineAsync(cancellationToken))!;
1099+
string? chunkHead = await ReadLineAsync(cancellationToken);
1100+
if (chunkHead == null)
1101+
{
1102+
return;
1103+
}
1104+
11001105
int idx = chunkHead.IndexOf(";");
11011106
if (idx >= 0)
11021107
{

src/Titanium.Web.Proxy/RequestHandler.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ await HeaderParser.ReadHeaders(clientStream, args.HttpClient.Request.Headers,
169169
if (part1 & part2)
170170
{
171171
//connection is closed
172+
await tcpConnectionFactory.Release(connection, true);
172173
connection = null;
173174
}
174175
}
@@ -297,7 +298,11 @@ private async Task<RetryResult> handleHttpSessionRequest(SessionEventArgs args,
297298

298299
if (args.HttpClient.Request.UpgradeToWebSocket)
299300
{
300-
args.HttpClient.ConnectRequest!.TunnelType = TunnelType.Websocket;
301+
// connectRequest can be null for SOCKS connection
302+
if (args.HttpClient.ConnectRequest != null)
303+
{
304+
args.HttpClient.ConnectRequest!.TunnelType = TunnelType.Websocket;
305+
}
301306

302307
// if upgrading to websocket then relay the request without reading the contents
303308
await handleWebSocketUpgrade(args, args.ClientStream, connection, cancellationTokenSource, cancellationToken);

0 commit comments

Comments
 (0)