@@ -106,8 +106,11 @@ private async Task HandleClient(ExplicitProxyEndPoint endPoint, TcpClient tcpCli
106106 }
107107
108108 //write back successfull CONNECT response
109- connectArgs . WebSession . Response = ConnectResponse . CreateSuccessfullConnectResponse ( version ) ;
110- await clientStreamWriter . WriteResponseAsync ( connectArgs . WebSession . Response ) ;
109+ var response = ConnectResponse . CreateSuccessfullConnectResponse ( version ) ;
110+ response . Headers . FixProxyHeaders ( ) ;
111+ connectArgs . WebSession . Response = response ;
112+
113+ await clientStreamWriter . WriteResponseAsync ( response ) ;
111114
112115 var clientHelloInfo = await SslTools . PeekClientHello ( clientStream ) ;
113116 bool isClientHello = clientHelloInfo != null ;
@@ -401,14 +404,14 @@ private async Task HandleHttpSessionRequest(TcpClient client, CustomBufferedStre
401404 args . ProxyClient . ClientStreamWriter = clientStreamWriter ;
402405
403406 //proxy authorization check
404- if ( httpsConnectHostname == null && await CheckAuthorization ( clientStreamWriter , args ) == false )
407+ if ( ! args . IsTransparent && httpsConnectHostname == null && await CheckAuthorization ( clientStreamWriter , args ) == false )
405408 {
406409 break ;
407410 }
408411
409- PrepareRequestHeaders ( args . WebSession . Request . Headers ) ;
410412 if ( ! isTransparentEndPoint )
411413 {
414+ PrepareRequestHeaders ( args . WebSession . Request . Headers ) ;
412415 args . WebSession . Request . Host = args . WebSession . Request . RequestUri . Authority ;
413416 }
414417
@@ -426,10 +429,18 @@ private async Task HandleHttpSessionRequest(TcpClient client, CustomBufferedStre
426429 await BeforeRequest . InvokeAsync ( this , args , ExceptionFunc ) ;
427430 }
428431
432+ var response = args . WebSession . Response ;
433+
429434 if ( args . WebSession . Request . CancelRequest )
430435 {
431436 await HandleHttpSessionResponse ( args ) ;
432- break ;
437+
438+ if ( ! response . KeepAlive )
439+ {
440+ break ;
441+ }
442+
443+ continue ;
433444 }
434445
435446 //create a new connection if hostname/upstream end point changes
@@ -457,13 +468,16 @@ private async Task HandleHttpSessionRequest(TcpClient client, CustomBufferedStre
457468 string httpStatus = await connection . StreamReader . ReadLineAsync ( ) ;
458469
459470 Response . ParseResponseLine ( httpStatus , out var responseVersion , out int responseStatusCode , out string responseStatusDescription ) ;
460- args . WebSession . Response . HttpVersion = responseVersion ;
461- args . WebSession . Response . StatusCode = responseStatusCode ;
462- args . WebSession . Response . StatusDescription = responseStatusDescription ;
471+ response . HttpVersion = responseVersion ;
472+ response . StatusCode = responseStatusCode ;
473+ response . StatusDescription = responseStatusDescription ;
463474
464- await HeaderParser . ReadHeaders ( connection . StreamReader , args . WebSession . Response . Headers ) ;
475+ await HeaderParser . ReadHeaders ( connection . StreamReader , response . Headers ) ;
465476
466- await clientStreamWriter . WriteResponseAsync ( args . WebSession . Response ) ;
477+ if ( ! args . IsTransparent )
478+ {
479+ await clientStreamWriter . WriteResponseAsync ( response ) ;
480+ }
467481
468482 //If user requested call back then do it
469483 if ( BeforeResponse != null && ! args . WebSession . Response . ResponseLocked )
@@ -483,7 +497,7 @@ await TcpHelper.SendRaw(clientStream, connection.Stream, BufferSize,
483497 await HandleHttpSessionRequestInternal ( connection , args ) ;
484498
485499 //if connection is closing exit
486- if ( args . WebSession . Response . KeepAlive == false )
500+ if ( ! response . KeepAlive )
487501 {
488502 break ;
489503 }
@@ -522,7 +536,7 @@ private async Task HandleHttpSessionRequestInternal(TcpConnection connection, Se
522536 if ( request . ExpectContinue )
523537 {
524538 args . WebSession . SetConnection ( connection ) ;
525- await args . WebSession . SendRequest ( Enable100ContinueBehaviour ) ;
539+ await args . WebSession . SendRequest ( Enable100ContinueBehaviour , args . IsTransparent ) ;
526540 }
527541
528542 //If 100 continue was the response inform that to the client
@@ -546,7 +560,7 @@ private async Task HandleHttpSessionRequestInternal(TcpConnection connection, Se
546560 if ( ! request . ExpectContinue )
547561 {
548562 args . WebSession . SetConnection ( connection ) ;
549- await args . WebSession . SendRequest ( Enable100ContinueBehaviour ) ;
563+ await args . WebSession . SendRequest ( Enable100ContinueBehaviour , args . IsTransparent ) ;
550564 }
551565
552566 //check if content-length is > 0
0 commit comments