Skip to content

Commit 1f73638

Browse files
committed
fix: add compatibility for curl_cffi >= 0.14.0 and urllib3 >= 2.6.0
- Handle renamed method: clean_after_perform() -> clean_handles_and_buffers() - Add max_length parameter support to _decode() for urllib3 > 2.6.x Both changes are backward compatible with older versions.
1 parent de15bb8 commit 1f73638

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

curl_adapter/curl_cffi.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,5 +191,10 @@ def set_curl_options(self, curl, request, url, timeout, proxies):
191191
)
192192

193193
def reset_curl(self):
194-
self.curl.clean_after_perform()
194+
if hasattr(self.curl, 'clean_handles_and_buffers'):
195+
# curl_cffi >= 0.14.0: clean_after_perform() was renamed to clean_handles_and_buffers()
196+
self.curl.clean_handles_and_buffers()
197+
elif hasattr(self.curl, 'clean_after_perform'):
198+
# curl_cffi < 0.14.0
199+
self.curl.clean_after_perform()
195200
return super().reset_curl()

curl_adapter/stream/response.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,13 +203,16 @@ def _error_catcher(self):
203203
#self.close()
204204
pass
205205

206-
def _decode(self, data, decode_content, flush_decoder):
206+
def _decode(self, data, decode_content, flush_decoder, max_length=None):
207207
"""
208208
Curl automatically decodes content if the "Accept" header is present.
209209
"""
210210
if not self._handle_content_decoding:
211211
return data
212212

213+
# urllib3 >= 2.6.0 passes max_length parameter
214+
if max_length is not None:
215+
return super()._decode(data, decode_content, flush_decoder, max_length)
213216
return super()._decode(data, decode_content, flush_decoder)
214217

215218

@@ -241,4 +244,4 @@ def connection(self):
241244

242245
@classmethod
243246
def from_httplib(self, *args, **kwargs):
244-
raise NotImplementedError()
247+
raise NotImplementedError()

0 commit comments

Comments
 (0)