@@ -33,7 +33,8 @@ private static void HandleClient(TcpClient client)
3333
3434 if ( string . IsNullOrEmpty ( httpCmd ) )
3535 {
36- throw new EndOfStreamException ( ) ;
36+ Dispose ( client , clientStream , clientStreamReader , clientStreamWriter , null ) ;
37+ return ;
3738 }
3839
3940 //break up the line into three components (method, remote URL & Http Version)
@@ -80,11 +81,13 @@ private static void HandleClient(TcpClient client)
8081 if ( sslStream != null )
8182 sslStream . Dispose ( ) ;
8283
83- throw ;
84+ Dispose ( client , clientStream , clientStreamReader , clientStreamWriter , null ) ;
85+ return ;
8486 }
8587
8688
8789 httpCmd = clientStreamReader . ReadLine ( ) ;
90+
8891 }
8992 else if ( httpVerb . ToUpper ( ) == "CONNECT" )
9093 {
@@ -121,7 +124,6 @@ private static void HandleHttpSessionRequest(TcpClient client, string httpCmd, S
121124 var args = new SessionEventArgs ( BUFFER_SIZE ) ;
122125 args . Client = client ;
123126
124-
125127 try
126128 {
127129 //break up the line into three components (method, remote URL & Http Version)
@@ -227,26 +229,21 @@ private static void HandleHttpSessionRequest(TcpClient client, string httpCmd, S
227229
228230 HandleHttpSessionResponse ( args ) ;
229231
232+ //if connection is closing exit
230233 if ( args . ResponseHeaders . Any ( x => x . Name . ToLower ( ) == "connection" && x . Value . ToLower ( ) == "close" ) )
231234 {
232235 Dispose ( client , clientStream , clientStreamReader , clientStreamWriter , args ) ;
233236 return ;
234237 }
235- //Now read the next request (if keep-Alive is enabled, otherwise exit this thread)
236- //If client is pipeling the request, this will be immediately hit before response for previous request was made
237- httpCmd = clientStreamReader . ReadLine ( ) ;
238- //Http request body sent, now wait for next request
239238
240- client = args . Client ;
241- clientStream = args . ClientStream ;
242- clientStreamReader = args . ClientStreamReader ;
243- args . ClientStreamWriter = clientStreamWriter ;
239+ // read the next request
240+ httpCmd = clientStreamReader . ReadLine ( ) ;
244241
245242 }
246243 catch
247244 {
248245 Dispose ( client , clientStream , clientStreamReader , clientStreamWriter , args ) ;
249- throw ;
246+ return ;
250247 }
251248 }
252249 }
0 commit comments