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

Commit 4456a22

Browse files
committed
connection timeout for web socket requests
1 parent 15fd894 commit 4456a22

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

Titanium.Web.Proxy/Helpers/Tcp.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ internal class TcpHelper
2828
/// <param name="isHttps"></param>
2929
/// <returns></returns>
3030
internal static async Task SendRaw(Stream clientStream, string httpCmd, Dictionary<string, HttpHeader> requestHeaders, string hostName,
31-
int tunnelPort, bool isHttps, SslProtocols supportedProtocols)
31+
int tunnelPort, bool isHttps, SslProtocols supportedProtocols, int connectionTimeOutSeconds)
3232
{
3333
//prepare the prefix content
3434
StringBuilder sb = null;
@@ -83,6 +83,12 @@ internal static async Task SendRaw(Stream clientStream, string httpCmd, Dictiona
8383
}
8484
}
8585

86+
tunnelClient.SendTimeout = connectionTimeOutSeconds * 1000;
87+
tunnelClient.ReceiveTimeout = connectionTimeOutSeconds * 1000;
88+
89+
tunnelStream.ReadTimeout = connectionTimeOutSeconds * 1000;
90+
tunnelStream.WriteTimeout = connectionTimeOutSeconds * 1000;
91+
8692
Task sendRelay;
8793

8894
//Now async relay all server=>client & client=>server data

Titanium.Web.Proxy/Network/TcpConnectionFactory.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ private async Task<TcpConnection> CreateClient(string hostname, int port, bool i
129129
client.ReceiveTimeout = connectionTimeOutSeconds * 1000;
130130
client.SendTimeout = connectionTimeOutSeconds * 1000;
131131

132+
stream.ReadTimeout = connectionTimeOutSeconds * 1000;
133+
stream.WriteTimeout = connectionTimeOutSeconds * 1000;
134+
132135
return new TcpConnection()
133136
{
134137
HostName = hostname,

Titanium.Web.Proxy/RequestHandler.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ await sslStream.AuthenticateAsServerAsync(certificate, false,
127127

128128
//Just relay the request/response without decrypting it
129129
await TcpHelper.SendRaw(clientStream, null, null, httpRemoteUri.Host, httpRemoteUri.Port,
130-
false, SupportedSslProtocols);
130+
false, SupportedSslProtocols, ConnectionTimeOutSeconds);
131131

132132
Dispose(client, clientStream, clientStreamReader, clientStreamWriter, null);
133133
return;
@@ -311,7 +311,8 @@ private async Task HandleHttpSessionRequest(TcpClient client, string httpCmd, St
311311
if (args.WebSession.Request.UpgradeToWebSocket)
312312
{
313313
await TcpHelper.SendRaw(clientStream, httpCmd, args.WebSession.Request.RequestHeaders,
314-
httpRemoteUri.Host, httpRemoteUri.Port, args.IsHttps, SupportedSslProtocols);
314+
httpRemoteUri.Host, httpRemoteUri.Port, args.IsHttps, SupportedSslProtocols, ConnectionTimeOutSeconds);
315+
315316
Dispose(client, clientStream, clientStreamReader, clientStreamWriter, args);
316317
break;
317318
}

0 commit comments

Comments
 (0)