Skip to content

Commit

Permalink
small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
honfika committed Dec 28, 2019
1 parent 66a45c0 commit f69fb3b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ public ProxyTestController()
await writeToConsole(exception.Message, ConsoleColor.Red);
}
};

proxyServer.TcpTimeWaitSeconds = 10;
proxyServer.ConnectionTimeOutSeconds = 15;
proxyServer.ReuseSocket = false;
proxyServer.EnableConnectionPool = false;
proxyServer.ForwardToUpstreamGateway = true;
proxyServer.CertificateManager.SaveFakeCertificates = true;
//proxyServer.ProxyBasicAuthenticateFunc = async (args, userName, password) =>
Expand Down
7 changes: 6 additions & 1 deletion src/Titanium.Web.Proxy/Helpers/HttpStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1096,7 +1096,12 @@ private async Task copyBodyChunkedAsync(IHttpStreamWriter writer, Action<byte[],
{
while (true)
{
string chunkHead = (await ReadLineAsync(cancellationToken))!;
string? chunkHead = await ReadLineAsync(cancellationToken);
if (chunkHead == null)
{
return;
}

int idx = chunkHead.IndexOf(";");
if (idx >= 0)
{
Expand Down
9 changes: 7 additions & 2 deletions src/Titanium.Web.Proxy/RequestHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,12 @@ await HeaderParser.ReadHeaders(clientStream, args.HttpClient.Request.Headers,
if (connection != null)
{
var socket = connection.TcpSocket;
bool part1 = socket.Poll(1000, SelectMode.SelectRead);
bool part1 = socket.Poll(1000, SelectMode.SelectRead);
bool part2 = socket.Available == 0;
if (part1 & part2)
{
//connection is closed
await tcpConnectionFactory.Release(connection, true);
connection = null;
}
}
Expand Down Expand Up @@ -297,7 +298,11 @@ private async Task<RetryResult> handleHttpSessionRequest(SessionEventArgs args,

if (args.HttpClient.Request.UpgradeToWebSocket)
{
args.HttpClient.ConnectRequest!.TunnelType = TunnelType.Websocket;
// connectRequest can be null for SOCKS connection
if (args.HttpClient.ConnectRequest != null)
{
args.HttpClient.ConnectRequest!.TunnelType = TunnelType.Websocket;
}

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

0 comments on commit f69fb3b

Please sign in to comment.