mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2026-08-18 18:16:18 +03:00
[rh:curl_cffi] Support curl_cffi 0.16.x (#17439)
Closes #17341 Authored by: bashonly, coletdjnz Co-authored-by: coletdjnz <coletdjnz@protonmail.com>
This commit is contained in:
+22
-2
@@ -83,6 +83,12 @@ class HTTPProxyHandler(BaseHTTPRequestHandler, HTTPProxyAuthMixin):
|
||||
|
||||
self.server.close_request(self.request)
|
||||
|
||||
def finish(self):
|
||||
try:
|
||||
super().finish()
|
||||
finally:
|
||||
self.server.close_request(self.request)
|
||||
|
||||
|
||||
if urllib3:
|
||||
import urllib3.util.ssltransport
|
||||
@@ -132,7 +138,11 @@ class HTTPSProxyHandler(HTTPProxyHandler):
|
||||
request = SSLTransport(request, ssl_context=sslctx, server_side=True)
|
||||
else:
|
||||
request = sslctx.wrap_socket(request, server_side=True)
|
||||
super().__init__(request, *args, **kwargs)
|
||||
try:
|
||||
super().__init__(request, *args, **kwargs)
|
||||
except Exception:
|
||||
request.close()
|
||||
raise
|
||||
|
||||
|
||||
class HTTPConnectProxyHandler(BaseHTTPRequestHandler, HTTPProxyAuthMixin):
|
||||
@@ -163,6 +173,12 @@ class HTTPConnectProxyHandler(BaseHTTPRequestHandler, HTTPProxyAuthMixin):
|
||||
self.request_handler(self.request, self.client_address, self.server, proxy_info=proxy_info)
|
||||
self.server.close_request(self.request)
|
||||
|
||||
def finish(self):
|
||||
try:
|
||||
super().finish()
|
||||
finally:
|
||||
self.server.close_request(self.request)
|
||||
|
||||
|
||||
class HTTPSConnectProxyHandler(HTTPConnectProxyHandler):
|
||||
def __init__(self, request, *args, **kwargs):
|
||||
@@ -171,7 +187,11 @@ class HTTPSConnectProxyHandler(HTTPConnectProxyHandler):
|
||||
sslctx.load_cert_chain(certfn, None)
|
||||
request = sslctx.wrap_socket(request, server_side=True)
|
||||
self._original_request = request
|
||||
super().__init__(request, *args, **kwargs)
|
||||
try:
|
||||
super().__init__(request, *args, **kwargs)
|
||||
except Exception:
|
||||
request.close()
|
||||
raise
|
||||
|
||||
def do_CONNECT(self):
|
||||
super().do_CONNECT()
|
||||
|
||||
+12
-2
@@ -388,13 +388,23 @@ class TestHTTPRequestHandler(TestRequestHandlerBase):
|
||||
assert res.status == 200
|
||||
res.close()
|
||||
|
||||
def test_percent_encode(self, handler):
|
||||
def test_percent_encode_unicode(self, handler):
|
||||
# RFC 3986 §6.2.2.1 defines that percent-encoding SHOULD be normalized to uppercase.
|
||||
with handler() as rh:
|
||||
# Unicode characters should be encoded with uppercase percent-encoding
|
||||
res = validate_and_send(rh, Request(f'http://127.0.0.1:{self.http_port}/中文.html'))
|
||||
assert res.status == 200
|
||||
res.close()
|
||||
# don't normalize existing percent encodings
|
||||
|
||||
@pytest.mark.skip_handler('CurlCFFI', 'not supported by curl-cffi (non-standard)')
|
||||
def test_percent_encode_keep_existing(self, handler):
|
||||
# NOTE: RFC 3986 §6.2.2.1 defines that percent-encoding SHOULD be normalized to uppercase.
|
||||
# For compatibility with legacy sites (e.g., redirects using lowercase encodings and only accept that),
|
||||
# our default handlers (urllib/requests) preserve existing percent-encoding instead of normalizing it.
|
||||
#
|
||||
# CurlCFFI is excluded because it forces uppercase encodings and is hard to change. This is acceptable
|
||||
# since CurlCFFI is used only for impersonation. https://github.com/curl/curl/pull/21592
|
||||
with handler() as rh:
|
||||
res = validate_and_send(rh, Request(f'http://127.0.0.1:{self.http_port}/%c7%9f'))
|
||||
assert res.status == 200
|
||||
res.close()
|
||||
|
||||
Reference in New Issue
Block a user