@@ -86,11 +86,12 @@ class Response:
86
86
87
87
encoding = None
88
88
89
- def __init__ (self , sock : SocketType , session : "Session" ) -> None :
89
+ def __init__ (self , sock : SocketType , session : "Session" , fast_close : bool = False ) -> None :
90
90
self .socket = sock
91
91
self .encoding = "utf-8"
92
92
self ._cached = None
93
93
self ._headers = {}
94
+ self ._fast_close = fast_close
94
95
95
96
# _start_index and _receive_buffer are used when parsing headers.
96
97
# _receive_buffer will grow by 32 bytes everytime it is too small.
@@ -226,12 +227,12 @@ def _throw_away(self, nbytes: int) -> None:
226
227
while to_read > 0 :
227
228
to_read -= self ._recv_into (buf , to_read )
228
229
229
- def close (self , fast : bool = False ) -> None :
230
+ def close (self ) -> None :
230
231
"""Drain the remaining ESP socket buffers. We assume we already got what we wanted."""
231
232
if not self .socket :
232
233
return
233
234
# 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 :
235
236
if self ._remaining and self ._remaining > 0 :
236
237
self ._throw_away (self ._remaining )
237
238
elif self ._chunked :
@@ -362,11 +363,13 @@ def __init__(
362
363
socket_pool : SocketpoolModuleType ,
363
364
ssl_context : Optional [SSLContextType ] = None ,
364
365
session_id : Optional [str ] = None ,
366
+ fast_close : Optional [Bool ] = False ,
365
367
) -> None :
366
368
self ._connection_manager = get_connection_manager (socket_pool )
367
369
self ._ssl_context = ssl_context
368
370
self ._session_id = session_id
369
371
self ._last_response = None
372
+ self ._fast_close = fast_close
370
373
371
374
@staticmethod
372
375
def _check_headers (headers : Dict [str , str ]):
@@ -561,7 +564,7 @@ def request(
561
564
if not socket :
562
565
raise OutOfRetries ("Repeated socket failures" ) from last_exc
563
566
564
- resp = Response (socket , self ) # our response
567
+ resp = Response (socket , self , fast_close = self . _fast_close ) # our response
565
568
if allow_redirects :
566
569
if "location" in resp .headers and 300 <= resp .status_code <= 399 :
567
570
# a naive handler for redirects
0 commit comments