From d1a64ff02d584dadbd32a636b26e482985f67420 Mon Sep 17 00:00:00 2001 From: Yifei Kong Date: Tue, 25 Jun 2024 15:24:43 +0800 Subject: [PATCH] Use plain http proxy for http request, not tunneling --- curl_cffi/requests/session.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/curl_cffi/requests/session.py b/curl_cffi/requests/session.py index 62ae263..1efe5d5 100644 --- a/curl_cffi/requests/session.py +++ b/curl_cffi/requests/session.py @@ -458,18 +458,21 @@ def _set_curl_options( ) if proxy is not None: - if parts.scheme == "https" and proxy.startswith("https://"): - warnings.warn( - "You may be using http proxy WRONG, the prefix should be 'http://' not 'https://'," - "see: https://github.com/yifeikong/curl_cffi/issues/6", - RuntimeWarning, - stacklevel=2, - ) c.setopt(CurlOpt.PROXY, proxy) - # for http proxy, need to tell curl to enable tunneling - if not proxy.startswith("socks"): - c.setopt(CurlOpt.HTTPPROXYTUNNEL, 1) + + if parts.scheme == "https": + if proxy.startswith("https://"): + warnings.warn( + "Make sure you are using https over https proxy, otherwise, " + "the proxy prefix should be 'http://' not 'https://', " + "see: https://github.com/yifeikong/curl_cffi/issues/6", + RuntimeWarning, + stacklevel=2, + ) + # For https site with http tunnel proxy, tell curl to enable tunneling + if not proxy.startswith("socks"): + c.setopt(CurlOpt.HTTPPROXYTUNNEL, 1) # proxy_auth proxy_auth = proxy_auth or self.proxy_auth