Unverified Commit 82ac9634 authored by honfika's avatar honfika Committed by GitHub

Merge pull request #727 from justcoding121/beta

stable
parents 3a62c35e fce77d70
...@@ -42,6 +42,11 @@ namespace Titanium.Web.Proxy.Examples.Basic ...@@ -42,6 +42,11 @@ namespace Titanium.Web.Proxy.Examples.Basic
await writeToConsole(exception.Message, ConsoleColor.Red); await writeToConsole(exception.Message, ConsoleColor.Red);
} }
}; };
proxyServer.TcpTimeWaitSeconds = 10;
proxyServer.ConnectionTimeOutSeconds = 15;
proxyServer.ReuseSocket = false;
proxyServer.EnableConnectionPool = false;
proxyServer.ForwardToUpstreamGateway = true; proxyServer.ForwardToUpstreamGateway = true;
proxyServer.CertificateManager.SaveFakeCertificates = true; proxyServer.CertificateManager.SaveFakeCertificates = true;
//proxyServer.ProxyBasicAuthenticateFunc = async (args, userName, password) => //proxyServer.ProxyBasicAuthenticateFunc = async (args, userName, password) =>
......
...@@ -39,7 +39,7 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -39,7 +39,7 @@ namespace Titanium.Web.Proxy.Helpers
{ {
// is this really possible? // is this really possible?
httpStatus = await ReadLineAsync(cancellationToken) ?? httpStatus = await ReadLineAsync(cancellationToken) ??
throw new ServerConnectionException("Server connection was closed."); throw new ServerConnectionException("Server connection was closed. Response status is empty.");
} }
Response.ParseResponseLine(httpStatus, out var version, out int statusCode, out string description); Response.ParseResponseLine(httpStatus, out var version, out int statusCode, out string description);
...@@ -47,7 +47,7 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -47,7 +47,7 @@ namespace Titanium.Web.Proxy.Helpers
} }
catch (Exception e) when (!(e is ServerConnectionException)) catch (Exception e) when (!(e is ServerConnectionException))
{ {
throw new ServerConnectionException("Server connection was closed."); throw new ServerConnectionException("Server connection was closed. Exception while reading the response status.", e);
} }
} }
} }
......
...@@ -1096,7 +1096,12 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -1096,7 +1096,12 @@ namespace Titanium.Web.Proxy.Helpers
{ {
while (true) while (true)
{ {
string chunkHead = (await ReadLineAsync(cancellationToken))!; string? chunkHead = await ReadLineAsync(cancellationToken);
if (chunkHead == null)
{
return;
}
int idx = chunkHead.IndexOf(";"); int idx = chunkHead.IndexOf(";");
if (idx >= 0) if (idx >= 0)
{ {
......
...@@ -302,6 +302,11 @@ namespace Titanium.Web.Proxy.Network.Tcp ...@@ -302,6 +302,11 @@ namespace Titanium.Web.Proxy.Network.Tcp
} }
} }
if (isHttps && sslProtocol == SslProtocols.None)
{
sslProtocol = proxyServer.SupportedSslProtocols;
}
bool useUpstreamProxy1 = false; bool useUpstreamProxy1 = false;
// check if external proxy is set for HTTP/HTTPS // check if external proxy is set for HTTP/HTTPS
......
...@@ -68,7 +68,10 @@ namespace Titanium.Web.Proxy ...@@ -68,7 +68,10 @@ namespace Titanium.Web.Proxy
UserData = connectArgs?.UserData UserData = connectArgs?.UserData
}; };
args.HttpClient.Request.IsHttps = isHttps; if (isHttps)
{
args.HttpClient.Request.IsHttps = true;
}
try try
{ {
...@@ -156,7 +159,19 @@ namespace Titanium.Web.Proxy ...@@ -156,7 +159,19 @@ namespace Titanium.Web.Proxy
} }
prefetchTask = null; prefetchTask = null;
}
if (connection != null)
{
var socket = connection.TcpSocket;
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;
}
} }
// create a new connection if cache key changes. // create a new connection if cache key changes.
...@@ -283,7 +298,11 @@ namespace Titanium.Web.Proxy ...@@ -283,7 +298,11 @@ namespace Titanium.Web.Proxy
if (args.HttpClient.Request.UpgradeToWebSocket) 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 // if upgrading to websocket then relay the request without reading the contents
await handleWebSocketUpgrade(args, args.ClientStream, connection, cancellationTokenSource, cancellationToken); await handleWebSocketUpgrade(args, args.ClientStream, connection, cancellationTokenSource, cancellationToken);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment