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

Commit 80de6ea

Browse files
committed
handling keepalive properly when user respond in the BeforeRequest handler
1 parent 989b6ca commit 80de6ea

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

Titanium.Web.Proxy/RequestHandler.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -429,10 +429,18 @@ private async Task HandleHttpSessionRequest(TcpClient client, CustomBufferedStre
429429
await BeforeRequest.InvokeAsync(this, args, ExceptionFunc);
430430
}
431431

432+
var response = args.WebSession.Response;
433+
432434
if (args.WebSession.Request.CancelRequest)
433435
{
434436
await HandleHttpSessionResponse(args);
435-
break;
437+
438+
if (!response.KeepAlive)
439+
{
440+
break;
441+
}
442+
443+
continue;
436444
}
437445

438446
//create a new connection if hostname/upstream end point changes
@@ -450,8 +458,6 @@ private async Task HandleHttpSessionRequest(TcpClient client, CustomBufferedStre
450458
connection = await GetServerConnection(args, false);
451459
}
452460

453-
var response = args.WebSession.Response;
454-
455461
//if upgrading to websocket then relay the requet without reading the contents
456462
if (args.WebSession.Request.UpgradeToWebSocket)
457463
{
@@ -491,7 +497,7 @@ await TcpHelper.SendRaw(clientStream, connection.Stream, BufferSize,
491497
await HandleHttpSessionRequestInternal(connection, args);
492498

493499
//if connection is closing exit
494-
if (response.KeepAlive == false)
500+
if (!response.KeepAlive)
495501
{
496502
break;
497503
}

0 commit comments

Comments
 (0)