Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Proxy-Authorization header on proxy object, not on request object for CONNECT method (https://...) #1194

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions splash/network_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down