From edff4b6833c898c5f66d7970375fde6637668c99 Mon Sep 17 00:00:00 2001 From: Fabien Vauchelles Date: Fri, 2 Aug 2024 11:25:29 +0200 Subject: [PATCH] fix(proxy): use proxy-auth header on proxy, not on request for connect --- splash/network_manager.py | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/splash/network_manager.py b/splash/network_manager.py index 6963b9185..78b92ce54 100644 --- a/splash/network_manager.py +++ b/splash/network_manager.py @@ -273,23 +273,28 @@ def _handle_custom_proxies(self, request): if splash_proxy_factory: proxy_query = QNetworkProxyQuery(request.url()) proxy = splash_proxy_factory.queryProxy(proxy_query)[0] - self.setProxy(proxy) + if proxy: + user, password = proxy.user(), proxy.password() + if request.url().toString().startswith('https:'): + if user or password: + # Handle proxy auth. We're setting Proxy-Authorization header + # explicitly because Qt loves to cache proxy credentials. + auth = b"Basic " + base64.b64encode("{}:{}".format(user, password).encode("utf-8")) + proxy.setRawHeader(b"Proxy-Authorization", auth) + else: + if user or password: + # Handle proxy auth. We're setting Proxy-Authorization header + # explicitly because Qt loves to cache proxy credentials. + auth = b"Basic " + base64.b64encode("{}:{}".format(user, password).encode("utf-8")) + request.setRawHeader(b"Proxy-Authorization", auth) + + self.setProxy(proxy) # proxies set in on_request if hasattr(request, 'custom_proxy'): proxy = request.custom_proxy self.setProxy(proxy) - # Handle proxy auth. We're setting Proxy-Authorization header - # explicitly because Qt loves to cache proxy credentials. - if proxy is None: - return - user, password = proxy.user(), proxy.password() - if not user and not password: - return - auth = b"Basic " + base64.b64encode("{}:{}".format(user, password).encode("utf-8")) - request.setRawHeader(b"Proxy-Authorization", auth) - def _handle_custom_headers(self, request): if self._get_webpage_attribute(request, "skip_custom_headers"): # XXX: this hack assumes that new requests between