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

Commit 912fedd

Browse files
authored
Merge pull request #619 from justcoding121/master
Merge to beta
2 parents c2e5c44 + 1bce248 commit 912fedd

File tree

5 files changed

+15
-17
lines changed

5 files changed

+15
-17
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public void Stop()
119119
private async Task onBeforeTunnelConnectRequest(object sender, TunnelConnectSessionEventArgs e)
120120
{
121121
string hostname = e.HttpClient.Request.RequestUri.Host;
122-
//await writeToConsole("Tunnel to: " + hostname);
122+
await writeToConsole("Tunnel to: " + hostname);
123123

124124
if (hostname.Contains("dropbox.com"))
125125
{
@@ -138,8 +138,8 @@ private Task onBeforeTunnelConnectResponse(object sender, TunnelConnectSessionEv
138138
// intecept & cancel redirect or update requests
139139
private async Task onRequest(object sender, SessionEventArgs e)
140140
{
141-
//await writeToConsole("Active Client Connections:" + ((ProxyServer)sender).ClientConnectionCount);
142-
//await writeToConsole(e.HttpClient.Request.Url);
141+
await writeToConsole("Active Client Connections:" + ((ProxyServer)sender).ClientConnectionCount);
142+
await writeToConsole(e.HttpClient.Request.Url);
143143

144144
// store it in the UserData property
145145
// It can be a simple integer, Guid, or any type
@@ -189,7 +189,7 @@ private async Task multipartRequestPartSent(object sender, MultipartRequestPartS
189189

190190
private async Task onResponse(object sender, SessionEventArgs e)
191191
{
192-
//await writeToConsole("Active Server Connections:" + ((ProxyServer)sender).ServerConnectionCount);
192+
await writeToConsole("Active Server Connections:" + ((ProxyServer)sender).ServerConnectionCount);
193193

194194
string ext = System.IO.Path.GetExtension(e.HttpClient.Request.RequestUri.AbsolutePath);
195195

src/Titanium.Web.Proxy/Network/Certificate/WinCertificateMaker.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ private X509Certificate2 makeCertificate(string sSubjectCN, bool isRoot,
105105
// KeyLength
106106
const int keyLength = 2048;
107107

108-
var graceTime = DateTime.Now.AddDays(graceDays);
109108
var now = DateTime.Now;
109+
var graceTime = now.AddDays(graceDays);
110110
var certificate = makeCertificate(isRoot, sSubjectCN, fullSubject, keyLength, hashAlgo, graceTime,
111111
now.AddDays(validDays), isRoot ? null : signingCert);
112112
return certificate;

src/Titanium.Web.Proxy/Network/CertificateManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ internal async void ClearIdleCertificates()
483483
var cancellationToken = clearCertificatesTokenSource.Token;
484484
while (!cancellationToken.IsCancellationRequested)
485485
{
486-
var cutOff = DateTime.Now.AddMinutes(-1 * CertificateCacheTimeOutMinutes);
486+
var cutOff = DateTime.Now.AddMinutes(-CertificateCacheTimeOutMinutes);
487487

488488
var outdated = cachedCertificates.Where(x => x.Value.LastAccess < cutOff).ToList();
489489

src/Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,12 @@ internal async Task<TcpServerConnection> GetServerConnection(string remoteHostNa
184184
{
185185
if (cache.TryGetValue(cacheKey, out var existingConnections))
186186
{
187+
// +3 seconds for potential delay after getting connection
188+
var cutOff = DateTime.Now.AddSeconds(-proxyServer.ConnectionTimeOutSeconds + 3);
187189
while (existingConnections.Count > 0)
188190
{
189191
if (existingConnections.TryDequeue(out var recentConnection))
190192
{
191-
//+3 seconds for potential delay after getting connection
192-
var cutOff = DateTime.Now.AddSeconds(-1 * proxyServer.ConnectionTimeOutSeconds + 3);
193-
194193
if (recentConnection.LastAccess > cutOff
195194
&& recentConnection.TcpClient.IsGoodConnection())
196195
{
@@ -481,7 +480,7 @@ private async Task clearOutdatedConnections()
481480
{
482481
try
483482
{
484-
var cutOff = DateTime.Now.AddSeconds(-1 * Server.ConnectionTimeOutSeconds);
483+
var cutOff = DateTime.Now.AddSeconds(-Server.ConnectionTimeOutSeconds);
485484
foreach (var item in cache)
486485
{
487486
var queue = item.Value;
@@ -490,8 +489,7 @@ private async Task clearOutdatedConnections()
490489
{
491490
if (queue.TryDequeue(out var connection))
492491
{
493-
if (!Server.EnableConnectionPool
494-
|| connection.LastAccess < cutOff)
492+
if (!Server.EnableConnectionPool || connection.LastAccess < cutOff)
495493
{
496494
disposalBag.Add(connection);
497495
}
@@ -508,8 +506,8 @@ private async Task clearOutdatedConnections()
508506
{
509507
await @lock.WaitAsync();
510508

511-
//clear empty queues
512-
var emptyKeys = cache.Where(x => x.Value.Count == 0).Select(x => x.Key).ToList();
509+
// clear empty queues
510+
var emptyKeys = cache.ToArray().Where(x => x.Value.Count == 0).Select(x => x.Key);
513511
foreach (string key in emptyKeys)
514512
{
515513
cache.TryRemove(key, out _);

src/Titanium.Web.Proxy/StreamExtended/Network/CustomBufferedStream.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ static CustomBufferedStream()
5151
try
5252
{
5353
var method = typeof(NetworkStream).GetMethod(nameof(Stream.ReadAsync),
54-
new Type[] { typeof(byte[]), typeof(int), typeof(int), typeof(CancellationToken) });
54+
new[] { typeof(byte[]), typeof(int), typeof(int), typeof(CancellationToken) });
5555
if (method != null && method.DeclaringType != typeof(Stream))
5656
{
5757
networkStreamHack = false;
@@ -684,8 +684,7 @@ public override int EndRead(IAsyncResult asyncResult)
684684

685685
return ((TaskResult<int>)asyncResult).Result;
686686
}
687-
688-
687+
689688
/// <summary>
690689
/// Fix the .net bug with SslStream slow WriteAsync
691690
/// https://github.com/justcoding121/Titanium-Web-Proxy/issues/495
@@ -709,6 +708,7 @@ public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, As
709708

710709
return vAsyncResult;
711710
}
711+
712712
public override void EndWrite(IAsyncResult asyncResult)
713713
{
714714
if (!networkStreamHack)

0 commit comments

Comments
 (0)