@@ -35,8 +35,8 @@ private async Task handleClient(ExplicitProxyEndPoint endPoint, TcpClientConnect
3535 var cancellationTokenSource = new CancellationTokenSource ( ) ;
3636 var cancellationToken = cancellationTokenSource . Token ;
3737
38- var clientStream = new CustomBufferedStream ( clientConnection . GetStream ( ) , BufferPool , BufferSize ) ;
39- var clientStreamWriter = new HttpResponseWriter ( clientStream , BufferPool , BufferSize ) ;
38+ var clientStream = new CustomBufferedStream ( clientConnection . GetStream ( ) , BufferPool ) ;
39+ var clientStreamWriter = new HttpResponseWriter ( clientStream , BufferPool ) ;
4040
4141 Task < TcpServerConnection > prefetchConnectionTask = null ;
4242 bool closeServerConnection = false ;
@@ -50,7 +50,7 @@ private async Task handleClient(ExplicitProxyEndPoint endPoint, TcpClientConnect
5050 TunnelConnectSessionEventArgs connectArgs = null ;
5151
5252 // Client wants to create a secure tcp tunnel (probably its a HTTPS or Websocket request)
53- if ( await HttpHelper . IsConnectMethod ( clientStream , BufferPool , BufferSize , cancellationToken ) == 1 )
53+ if ( await HttpHelper . IsConnectMethod ( clientStream , BufferPool , cancellationToken ) == 1 )
5454 {
5555 // read the first line HTTP command
5656 string httpCmd = await clientStream . ReadLineAsync ( cancellationToken ) ;
@@ -75,6 +75,8 @@ private async Task handleClient(ExplicitProxyEndPoint endPoint, TcpClientConnect
7575
7676 connectArgs = new TunnelConnectSessionEventArgs ( this , endPoint , connectRequest ,
7777 cancellationTokenSource ) ;
78+ clientStream . DataRead += ( o , args ) => connectArgs . OnDataSent ( args . Buffer , args . Offset , args . Count ) ;
79+ clientStream . DataWrite += ( o , args ) => connectArgs . OnDataReceived ( args . Buffer , args . Offset , args . Count ) ;
7880 connectArgs . ProxyClient . Connection = clientConnection ;
7981 connectArgs . ProxyClient . ClientStream = clientStream ;
8082
@@ -213,8 +215,8 @@ await clientStreamWriter.WriteResponseAsync(connectArgs.HttpClient.Response,
213215#endif
214216
215217 // HTTPS server created - we can now decrypt the client's traffic
216- clientStream = new CustomBufferedStream ( sslStream , BufferPool , BufferSize ) ;
217- clientStreamWriter = new HttpResponseWriter ( clientStream , BufferPool , BufferSize ) ;
218+ clientStream = new CustomBufferedStream ( sslStream , BufferPool ) ;
219+ clientStreamWriter = new HttpResponseWriter ( clientStream , BufferPool ) ;
218220 }
219221 catch ( Exception e )
220222 {
@@ -223,7 +225,7 @@ await clientStreamWriter.WriteResponseAsync(connectArgs.HttpClient.Response,
223225 $ "Couldn't authenticate host '{ connectHostname } ' with certificate '{ certName } '.", e , connectArgs ) ;
224226 }
225227
226- if ( await HttpHelper . IsConnectMethod ( clientStream , BufferPool , BufferSize , cancellationToken ) == - 1 )
228+ if ( await HttpHelper . IsConnectMethod ( clientStream , BufferPool , cancellationToken ) == - 1 )
227229 {
228230 decryptSsl = false ;
229231 }
@@ -263,7 +265,7 @@ await clientStreamWriter.WriteResponseAsync(connectArgs.HttpClient.Response,
263265 if ( available > 0 )
264266 {
265267 // send the buffered data
266- var data = BufferPool . GetBuffer ( BufferSize ) ;
268+ var data = BufferPool . GetBuffer ( ) ;
267269
268270 try
269271 {
@@ -283,10 +285,8 @@ await clientStreamWriter.WriteResponseAsync(connectArgs.HttpClient.Response,
283285
284286 if ( ! clientStream . IsClosed && ! connection . Stream . IsClosed )
285287 {
286- await TcpHelper . SendRaw ( clientStream , connection . Stream , BufferPool , BufferSize ,
287- ( buffer , offset , count ) => { connectArgs . OnDataSent ( buffer , offset , count ) ; } ,
288- ( buffer , offset , count ) => { connectArgs . OnDataReceived ( buffer , offset , count ) ; } ,
289- connectArgs . CancellationTokenSource , ExceptionFunc ) ;
288+ await TcpHelper . SendRaw ( clientStream , connection . Stream , BufferPool ,
289+ null , null , connectArgs . CancellationTokenSource , ExceptionFunc ) ;
290290 }
291291 }
292292 finally
@@ -298,7 +298,7 @@ await TcpHelper.SendRaw(clientStream, connection.Stream, BufferPool, BufferSize,
298298 }
299299 }
300300
301- if ( connectArgs != null && await HttpHelper . IsPriMethod ( clientStream , BufferPool , BufferSize , cancellationToken ) == 1 )
301+ if ( connectArgs != null && await HttpHelper . IsPriMethod ( clientStream , BufferPool , cancellationToken ) == 1 )
302302 {
303303 // todo
304304 string httpCmd = await clientStream . ReadLineAsync ( cancellationToken ) ;
@@ -335,7 +335,7 @@ await TcpHelper.SendRaw(clientStream, connection.Stream, BufferPool, BufferSize,
335335 await connection . StreamWriter . WriteLineAsync ( "SM" , cancellationToken ) ;
336336 await connection . StreamWriter . WriteLineAsync ( cancellationToken ) ;
337337#if NETCOREAPP2_1
338- await Http2Helper . SendHttp2 ( clientStream , connection . Stream , BufferSize ,
338+ await Http2Helper . SendHttp2 ( clientStream , connection . Stream , BufferPool . BufferSize ,
339339 ( buffer , offset , count ) => { connectArgs . OnDataSent ( buffer , offset , count ) ; } ,
340340 ( buffer , offset , count ) => { connectArgs . OnDataReceived ( buffer , offset , count ) ; } ,
341341 ( ) => new SessionEventArgs ( this , endPoint , cancellationTokenSource )
@@ -357,6 +357,7 @@ await Http2Helper.SendHttp2(clientStream, connection.Stream, BufferSize,
357357 }
358358
359359 calledRequestHandler = true ;
360+
360361 // Now create the request
361362 await handleHttpSessionRequest ( endPoint , clientConnection , clientStream , clientStreamWriter ,
362363 cancellationTokenSource , connectHostname , connectArgs , prefetchConnectionTask ) ;
0 commit comments