Do not set _scheme_proxy unless necessary

This commit is contained in:
Adrián Chaves 2024-02-27 23:00:49 +01:00
parent c5446c0b85
commit 247e24e5f4
1 changed files with 4 additions and 3 deletions

View File

@ -50,13 +50,14 @@ class HttpProxyMiddleware:
creds, proxy_url = self._get_proxy(request.meta["proxy"], "")
elif self.proxies:
parsed = urlparse_cached(request)
scheme = parsed.scheme
_scheme = parsed.scheme
if (
# 'no_proxy' is only supported by http schemes
scheme not in ("http", "https")
_scheme not in ("http", "https")
or not proxy_bypass(parsed.hostname)
) and scheme in self.proxies:
) and _scheme in self.proxies:
creds, proxy_url = self.proxies[scheme]
scheme = _scheme
self._set_proxy_and_creds(request, proxy_url, creds, scheme)