Commit 4456a224 authored by justcoding121's avatar justcoding121

connection timeout for web socket requests

parent 15fd8948
...@@ -28,7 +28,7 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -28,7 +28,7 @@ namespace Titanium.Web.Proxy.Helpers
/// <param name="isHttps"></param> /// <param name="isHttps"></param>
/// <returns></returns> /// <returns></returns>
internal static async Task SendRaw(Stream clientStream, string httpCmd, Dictionary<string, HttpHeader> requestHeaders, string hostName, internal static async Task SendRaw(Stream clientStream, string httpCmd, Dictionary<string, HttpHeader> requestHeaders, string hostName,
int tunnelPort, bool isHttps, SslProtocols supportedProtocols) int tunnelPort, bool isHttps, SslProtocols supportedProtocols, int connectionTimeOutSeconds)
{ {
//prepare the prefix content //prepare the prefix content
StringBuilder sb = null; StringBuilder sb = null;
...@@ -83,6 +83,12 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -83,6 +83,12 @@ namespace Titanium.Web.Proxy.Helpers
} }
} }
tunnelClient.SendTimeout = connectionTimeOutSeconds * 1000;
tunnelClient.ReceiveTimeout = connectionTimeOutSeconds * 1000;
tunnelStream.ReadTimeout = connectionTimeOutSeconds * 1000;
tunnelStream.WriteTimeout = connectionTimeOutSeconds * 1000;
Task sendRelay; Task sendRelay;
//Now async relay all server=>client & client=>server data //Now async relay all server=>client & client=>server data
......
...@@ -129,6 +129,9 @@ namespace Titanium.Web.Proxy.Network ...@@ -129,6 +129,9 @@ namespace Titanium.Web.Proxy.Network
client.ReceiveTimeout = connectionTimeOutSeconds * 1000; client.ReceiveTimeout = connectionTimeOutSeconds * 1000;
client.SendTimeout = connectionTimeOutSeconds * 1000; client.SendTimeout = connectionTimeOutSeconds * 1000;
stream.ReadTimeout = connectionTimeOutSeconds * 1000;
stream.WriteTimeout = connectionTimeOutSeconds * 1000;
return new TcpConnection() return new TcpConnection()
{ {
HostName = hostname, HostName = hostname,
......
...@@ -127,7 +127,7 @@ namespace Titanium.Web.Proxy ...@@ -127,7 +127,7 @@ namespace Titanium.Web.Proxy
//Just relay the request/response without decrypting it //Just relay the request/response without decrypting it
await TcpHelper.SendRaw(clientStream, null, null, httpRemoteUri.Host, httpRemoteUri.Port, await TcpHelper.SendRaw(clientStream, null, null, httpRemoteUri.Host, httpRemoteUri.Port,
false, SupportedSslProtocols); false, SupportedSslProtocols, ConnectionTimeOutSeconds);
Dispose(client, clientStream, clientStreamReader, clientStreamWriter, null); Dispose(client, clientStream, clientStreamReader, clientStreamWriter, null);
return; return;
...@@ -311,7 +311,8 @@ namespace Titanium.Web.Proxy ...@@ -311,7 +311,8 @@ namespace Titanium.Web.Proxy
if (args.WebSession.Request.UpgradeToWebSocket) if (args.WebSession.Request.UpgradeToWebSocket)
{ {
await TcpHelper.SendRaw(clientStream, httpCmd, args.WebSession.Request.RequestHeaders, await TcpHelper.SendRaw(clientStream, httpCmd, args.WebSession.Request.RequestHeaders,
httpRemoteUri.Host, httpRemoteUri.Port, args.IsHttps, SupportedSslProtocols); httpRemoteUri.Host, httpRemoteUri.Port, args.IsHttps, SupportedSslProtocols, ConnectionTimeOutSeconds);
Dispose(client, clientStream, clientStreamReader, clientStreamWriter, args); Dispose(client, clientStream, clientStreamReader, clientStreamWriter, args);
break; break;
} }
......
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