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

Commit ce0bba9

Browse files
committed
allow to terminate server connection
1 parent bb2d9b0 commit ce0bba9

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

Titanium.Web.Proxy/RequestHandler.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ private async Task HandleClient(ExplicitProxyEndPoint endPoint, TcpClient tcpCli
4646
try
4747
{
4848
string connectHostname = null;
49-
5049
ConnectRequest connectRequest = null;
5150

5251
//Client wants to create a secure tcp tunnel (probably its a HTTPS or Websocket request)
@@ -297,7 +296,7 @@ private async Task HandleHttpSessionRequest(TcpClient client, CustomBufferedStre
297296
string httpCmd = await clientStreamReader.ReadLineAsync();
298297
if (string.IsNullOrEmpty(httpCmd))
299298
{
300-
break;
299+
return;
301300
}
302301

303302
var args = new SessionEventArgs(BufferSize, endPoint, ExceptionFunc)
@@ -364,7 +363,7 @@ private async Task HandleHttpSessionRequest(TcpClient client, CustomBufferedStre
364363

365364
//send the response
366365
await clientStreamWriter.WriteResponseAsync(args.WebSession.Response);
367-
break;
366+
return;
368367
}
369368

370369
if (!isTransparentEndPoint)
@@ -397,7 +396,7 @@ private async Task HandleHttpSessionRequest(TcpClient client, CustomBufferedStre
397396

398397
if (!response.KeepAlive)
399398
{
400-
break;
399+
return;
401400
}
402401

403402
continue;
@@ -450,16 +449,22 @@ await TcpHelper.SendRaw(clientStream, connection.Stream, BufferSize,
450449
(buffer, offset, count) => { args.OnDataReceived(buffer, offset, count); },
451450
ExceptionFunc);
452451

453-
break;
452+
return;
454453
}
455454

456455
//construct the web request that we are going to issue on behalf of the client.
457456
await HandleHttpSessionRequestInternal(connection, args);
458457

458+
if (args.WebSession.ServerConnection == null)
459+
{
460+
//server connection was closed
461+
return;
462+
}
463+
459464
//if connection is closing exit
460465
if (!response.KeepAlive)
461466
{
462-
break;
467+
return;
463468
}
464469
}
465470
catch (Exception e) when (!(e is ProxyHttpException))

Titanium.Web.Proxy/ResponseHandler.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ private async Task HandleHttpSessionResponse(SessionEventArgs args)
5757
//syphon out the response body from server before setting the new body
5858
await args.SyphonOutBodyAsync(false);
5959
}
60+
else
61+
{
62+
args.WebSession.ServerConnection.Dispose();
63+
args.WebSession.ServerConnection = null;
64+
}
6065

6166
return;
6267
}

0 commit comments

Comments
 (0)