@@ -86,11 +86,12 @@ class Response:
8686
8787 encoding = None
8888
89- def __init__ (self , sock : SocketType , session : "Session" ) -> None :
89+ def __init__ (self , sock : SocketType , session : "Session" , fast_close : bool = False ) -> None :
9090 self .socket = sock
9191 self .encoding = "utf-8"
9292 self ._cached = None
9393 self ._headers = {}
94+ self ._fast_close = fast_close
9495
9596 # _start_index and _receive_buffer are used when parsing headers.
9697 # _receive_buffer will grow by 32 bytes everytime it is too small.
@@ -226,12 +227,12 @@ def _throw_away(self, nbytes: int) -> None:
226227 while to_read > 0 :
227228 to_read -= self ._recv_into (buf , to_read )
228229
229- def close (self , fast : bool = False ) -> None :
230+ def close (self ) -> None :
230231 """Drain the remaining ESP socket buffers. We assume we already got what we wanted."""
231232 if not self .socket :
232233 return
233234 # Make sure we've read all of our response.
234- if self ._cached is None and not fast :
235+ if self ._cached is None and not self . _fast_close :
235236 if self ._remaining and self ._remaining > 0 :
236237 self ._throw_away (self ._remaining )
237238 elif self ._chunked :
@@ -362,11 +363,13 @@ def __init__(
362363 socket_pool : SocketpoolModuleType ,
363364 ssl_context : Optional [SSLContextType ] = None ,
364365 session_id : Optional [str ] = None ,
366+ fast_close : Optional [Bool ] = False ,
365367 ) -> None :
366368 self ._connection_manager = get_connection_manager (socket_pool )
367369 self ._ssl_context = ssl_context
368370 self ._session_id = session_id
369371 self ._last_response = None
372+ self ._fast_close = fast_close
370373
371374 @staticmethod
372375 def _check_headers (headers : Dict [str , str ]):
@@ -561,7 +564,7 @@ def request(
561564 if not socket :
562565 raise OutOfRetries ("Repeated socket failures" ) from last_exc
563566
564- resp = Response (socket , self ) # our response
567+ resp = Response (socket , self , fast_close = self . _fast_close ) # our response
565568 if allow_redirects :
566569 if "location" in resp .headers and 300 <= resp .status_code <= 399 :
567570 # a naive handler for redirects
0 commit comments