145 self.no_list = no_list |
145 self.no_list = no_list |
146 |
146 |
147 # Keys and values need to be str because the standard library |
147 # Keys and values need to be str because the standard library |
148 # expects them to be. |
148 # expects them to be. |
149 proxyurl = str(proxy) |
149 proxyurl = str(proxy) |
150 proxies = {r'http': proxyurl, r'https': proxyurl} |
150 proxies = {'http': proxyurl, 'https': proxyurl} |
151 ui.debug(b'proxying through %s\n' % util.hidepassword(bytes(proxy))) |
151 ui.debug(b'proxying through %s\n' % util.hidepassword(bytes(proxy))) |
152 else: |
152 else: |
153 proxies = {} |
153 proxies = {} |
154 |
154 |
155 urlreq.proxyhandler.__init__(self, proxies) |
155 urlreq.proxyhandler.__init__(self, proxies) |
202 # Large parts of this function have their origin from before Python 2.6 |
202 # Large parts of this function have their origin from before Python 2.6 |
203 # and could potentially be removed. |
203 # and could potentially be removed. |
204 def _generic_start_transaction(handler, h, req): |
204 def _generic_start_transaction(handler, h, req): |
205 tunnel_host = req._tunnel_host |
205 tunnel_host = req._tunnel_host |
206 if tunnel_host: |
206 if tunnel_host: |
207 if tunnel_host[:7] not in [r'http://', r'https:/']: |
207 if tunnel_host[:7] not in ['http://', 'https:/']: |
208 tunnel_host = r'https://' + tunnel_host |
208 tunnel_host = 'https://' + tunnel_host |
209 new_tunnel = True |
209 new_tunnel = True |
210 else: |
210 else: |
211 tunnel_host = urllibcompat.getselector(req) |
211 tunnel_host = urllibcompat.getselector(req) |
212 new_tunnel = False |
212 new_tunnel = False |
213 |
213 |
226 def _generic_proxytunnel(self): |
226 def _generic_proxytunnel(self): |
227 proxyheaders = dict( |
227 proxyheaders = dict( |
228 [ |
228 [ |
229 (x, self.headers[x]) |
229 (x, self.headers[x]) |
230 for x in self.headers |
230 for x in self.headers |
231 if x.lower().startswith(r'proxy-') |
231 if x.lower().startswith('proxy-') |
232 ] |
232 ] |
233 ) |
233 ) |
234 self.send(b'CONNECT %s HTTP/1.0\r\n' % self.realhostport) |
234 self.send(b'CONNECT %s HTTP/1.0\r\n' % self.realhostport) |
235 for header in pycompat.iteritems(proxyheaders): |
235 for header in pycompat.iteritems(proxyheaders): |
236 self.send(b'%s: %s\r\n' % header) |
236 self.send(b'%s: %s\r\n' % header) |
520 user, pw = self.passwd.find_user_password( |
520 user, pw = self.passwd.find_user_password( |
521 realm, urllibcompat.getfullurl(req) |
521 realm, urllibcompat.getfullurl(req) |
522 ) |
522 ) |
523 if pw is not None: |
523 if pw is not None: |
524 raw = b"%s:%s" % (pycompat.bytesurl(user), pycompat.bytesurl(pw)) |
524 raw = b"%s:%s" % (pycompat.bytesurl(user), pycompat.bytesurl(pw)) |
525 auth = r'Basic %s' % pycompat.strurl(base64.b64encode(raw).strip()) |
525 auth = 'Basic %s' % pycompat.strurl(base64.b64encode(raw).strip()) |
526 if req.get_header(self.auth_header, None) == auth: |
526 if req.get_header(self.auth_header, None) == auth: |
527 return None |
527 return None |
528 self.auth = auth |
528 self.auth = auth |
529 req.add_unredirected_header(self.auth_header, auth) |
529 req.add_unredirected_header(self.auth_header, auth) |
530 return self.parent.open(req) |
530 return self.parent.open(req) |
653 # |
653 # |
654 # The custom user agent is for lfs, because unfortunately some servers |
654 # The custom user agent is for lfs, because unfortunately some servers |
655 # do look at this value. |
655 # do look at this value. |
656 if not useragent: |
656 if not useragent: |
657 agent = b'mercurial/proto-1.0 (Mercurial %s)' % util.version() |
657 agent = b'mercurial/proto-1.0 (Mercurial %s)' % util.version() |
658 opener.addheaders = [(r'User-agent', pycompat.sysstr(agent))] |
658 opener.addheaders = [('User-agent', pycompat.sysstr(agent))] |
659 else: |
659 else: |
660 opener.addheaders = [(r'User-agent', pycompat.sysstr(useragent))] |
660 opener.addheaders = [('User-agent', pycompat.sysstr(useragent))] |
661 |
661 |
662 # This header should only be needed by wire protocol requests. But it has |
662 # This header should only be needed by wire protocol requests. But it has |
663 # been sent on all requests since forever. We keep sending it for backwards |
663 # been sent on all requests since forever. We keep sending it for backwards |
664 # compatibility reasons. Modern versions of the wire protocol use |
664 # compatibility reasons. Modern versions of the wire protocol use |
665 # X-HgProto-<N> for advertising client support. |
665 # X-HgProto-<N> for advertising client support. |
666 if sendaccept: |
666 if sendaccept: |
667 opener.addheaders.append((r'Accept', r'application/mercurial-0.1')) |
667 opener.addheaders.append(('Accept', 'application/mercurial-0.1')) |
668 |
668 |
669 return opener |
669 return opener |
670 |
670 |
671 |
671 |
672 def open(ui, url_, data=None, sendaccept=True): |
672 def open(ui, url_, data=None, sendaccept=True): |