summaryrefslogtreecommitdiff
path: root/Lib/urllib/request.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/urllib/request.py')
-rw-r--r--Lib/urllib/request.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py
index 6da9007ac8..3ba7c01eb0 100644
--- a/Lib/urllib/request.py
+++ b/Lib/urllib/request.py
@@ -916,6 +916,21 @@ class ProxyBasicAuthHandler(AbstractBasicAuthHandler, BaseHandler):
return response
+class HTTPBasicPriorAuthHandler(HTTPBasicAuthHandler):
+ handler_order = 400
+
+ def http_request(self, req):
+ if not req.has_header('Authorization'):
+ user, passwd = self.passwd.find_user_password(None, req.host)
+ credentials = '{0}:{1}'.format(user, passwd).encode()
+ auth_str = base64.standard_b64encode(credentials).decode()
+ req.add_unredirected_header('Authorization',
+ 'Basic {}'.format(auth_str.strip()))
+ return req
+
+ https_request = http_request
+
+
# Return n random bytes.
_randombytes = os.urandom