Mercurial > public > mercurial-scm > hg-stable
annotate mercurial/url.py @ 34429:0ee9cf8d054a
url: use native strings for header values
Differential Revision: https://phab.mercurial-scm.org/D889
author | Augie Fackler <augie@google.com> |
---|---|
date | Sun, 01 Oct 2017 12:16:34 -0400 |
parents | 0407a51b9d8c |
children | 1232f7fa00c3 |
rev | line source |
---|---|
7270
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
1 # url.py - HTTP handling for mercurial |
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
2 # |
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
3 # Copyright 2005, 2006, 2007, 2008 Matt Mackall <mpm@selenic.com> |
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
4 # Copyright 2006, 2007 Alexis S. L. Carvalho <alexis@cecm.usp.br> |
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
5 # Copyright 2006 Vadim Gelfer <vadim.gelfer@gmail.com> |
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
6 # |
8225
46293a0c7e9f
updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents:
8208
diff
changeset
|
7 # This software may be used and distributed according to the terms of the |
10263 | 8 # GNU General Public License version 2 or any later version. |
7270
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
9 |
25990
c3efcdba08ea
url: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25837
diff
changeset
|
10 from __future__ import absolute_import |
c3efcdba08ea
url: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25837
diff
changeset
|
11 |
c3efcdba08ea
url: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25837
diff
changeset
|
12 import base64 |
c3efcdba08ea
url: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25837
diff
changeset
|
13 import os |
c3efcdba08ea
url: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25837
diff
changeset
|
14 import socket |
c3efcdba08ea
url: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25837
diff
changeset
|
15 |
c3efcdba08ea
url: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25837
diff
changeset
|
16 from .i18n import _ |
c3efcdba08ea
url: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25837
diff
changeset
|
17 from . import ( |
30820
6a70cf94d1b5
py3: replace pycompat.getenv with encoding.environ.get
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30763
diff
changeset
|
18 encoding, |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25990
diff
changeset
|
19 error, |
25990
c3efcdba08ea
url: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25837
diff
changeset
|
20 httpconnection as httpconnectionmod, |
c3efcdba08ea
url: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25837
diff
changeset
|
21 keepalive, |
34429
0ee9cf8d054a
url: use native strings for header values
Augie Fackler <augie@google.com>
parents:
33499
diff
changeset
|
22 pycompat, |
25990
c3efcdba08ea
url: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25837
diff
changeset
|
23 sslutil, |
c3efcdba08ea
url: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25837
diff
changeset
|
24 util, |
c3efcdba08ea
url: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25837
diff
changeset
|
25 ) |
29455
0c741fd6158a
py3: conditionalize httplib import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29379
diff
changeset
|
26 |
0c741fd6158a
py3: conditionalize httplib import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29379
diff
changeset
|
27 httplib = util.httplib |
28861
86db5cb55d46
pycompat: switch to util.stringio for py3 compat
timeless <timeless@mozdev.org>
parents:
26806
diff
changeset
|
28 stringio = util.stringio |
28883
032c4c2f802a
pycompat: switch to util.urlreq/util.urlerr for py3 compat
timeless <timeless@mozdev.org>
parents:
28861
diff
changeset
|
29 urlerr = util.urlerr |
032c4c2f802a
pycompat: switch to util.urlreq/util.urlerr for py3 compat
timeless <timeless@mozdev.org>
parents:
28861
diff
changeset
|
30 urlreq = util.urlreq |
032c4c2f802a
pycompat: switch to util.urlreq/util.urlerr for py3 compat
timeless <timeless@mozdev.org>
parents:
28861
diff
changeset
|
31 |
29377
2c019aac6b99
url: extract password database from password manager
liscju <piotr.listkiewicz@gmail.com>
parents:
29252
diff
changeset
|
32 class passwordmgr(object): |
2c019aac6b99
url: extract password database from password manager
liscju <piotr.listkiewicz@gmail.com>
parents:
29252
diff
changeset
|
33 def __init__(self, ui, passwddb): |
7270
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
34 self.ui = ui |
29377
2c019aac6b99
url: extract password database from password manager
liscju <piotr.listkiewicz@gmail.com>
parents:
29252
diff
changeset
|
35 self.passwddb = passwddb |
2c019aac6b99
url: extract password database from password manager
liscju <piotr.listkiewicz@gmail.com>
parents:
29252
diff
changeset
|
36 |
2c019aac6b99
url: extract password database from password manager
liscju <piotr.listkiewicz@gmail.com>
parents:
29252
diff
changeset
|
37 def add_password(self, realm, uri, user, passwd): |
2c019aac6b99
url: extract password database from password manager
liscju <piotr.listkiewicz@gmail.com>
parents:
29252
diff
changeset
|
38 return self.passwddb.add_password(realm, uri, user, passwd) |
7270
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
39 |
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
40 def find_user_password(self, realm, authuri): |
29377
2c019aac6b99
url: extract password database from password manager
liscju <piotr.listkiewicz@gmail.com>
parents:
29252
diff
changeset
|
41 authinfo = self.passwddb.find_user_password(realm, authuri) |
7270
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
42 user, passwd = authinfo |
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
43 if user and passwd: |
8333
89c80c3dc584
allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
8225
diff
changeset
|
44 self._writedebug(user, passwd) |
7270
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
45 return (user, passwd) |
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
46 |
15005
4a43e23b8c55
hgweb: do not ignore [auth] if url has a username (issue2822)
Patrick Mezard <pmezard@gmail.com>
parents:
14244
diff
changeset
|
47 if not user or not passwd: |
15025
0593e8f81c71
http: pass user to readauthforuri() (fix 4a43e23b8c55)
Patrick Mezard <pmezard@gmail.com>
parents:
15005
diff
changeset
|
48 res = httpconnectionmod.readauthforuri(self.ui, authuri, user) |
13372
5bced0d28a39
url: return the matched authentication group name from readauthforuri()
Steve Borho <steve@borho.org>
parents:
13371
diff
changeset
|
49 if res: |
5bced0d28a39
url: return the matched authentication group name from readauthforuri()
Steve Borho <steve@borho.org>
parents:
13371
diff
changeset
|
50 group, auth = res |
8847
7951f385fcb7
url: support client certificate files over HTTPS (issue643)
Henrik Stuart <hg@hstuart.dk>
parents:
8590
diff
changeset
|
51 user, passwd = auth.get('username'), auth.get('password') |
13372
5bced0d28a39
url: return the matched authentication group name from readauthforuri()
Steve Borho <steve@borho.org>
parents:
13371
diff
changeset
|
52 self.ui.debug("using auth.%s.* for authentication\n" % group) |
8333
89c80c3dc584
allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
8225
diff
changeset
|
53 if not user or not passwd: |
20291
7d589d923b8a
url: added authuri when login information is requested (issue3209)
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20174
diff
changeset
|
54 u = util.url(authuri) |
7d589d923b8a
url: added authuri when login information is requested (issue3209)
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20174
diff
changeset
|
55 u.query = None |
8333
89c80c3dc584
allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
8225
diff
changeset
|
56 if not self.ui.interactive(): |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25990
diff
changeset
|
57 raise error.Abort(_('http authorization required for %s') % |
20291
7d589d923b8a
url: added authuri when login information is requested (issue3209)
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20174
diff
changeset
|
58 util.hidepassword(str(u))) |
7270
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
59 |
20291
7d589d923b8a
url: added authuri when login information is requested (issue3209)
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20174
diff
changeset
|
60 self.ui.write(_("http authorization required for %s\n") % |
7d589d923b8a
url: added authuri when login information is requested (issue3209)
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
20174
diff
changeset
|
61 util.hidepassword(str(u))) |
12862
9d6adddc8eea
url: show realm/user when asking for username/password
timeless <timeless@gmail.com>
parents:
12770
diff
changeset
|
62 self.ui.write(_("realm: %s\n") % realm) |
8333
89c80c3dc584
allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
8225
diff
changeset
|
63 if user: |
12862
9d6adddc8eea
url: show realm/user when asking for username/password
timeless <timeless@gmail.com>
parents:
12770
diff
changeset
|
64 self.ui.write(_("user: %s\n") % user) |
8333
89c80c3dc584
allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
8225
diff
changeset
|
65 else: |
89c80c3dc584
allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
8225
diff
changeset
|
66 user = self.ui.prompt(_("user:"), default=None) |
7270
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
67 |
8333
89c80c3dc584
allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
8225
diff
changeset
|
68 if not passwd: |
89c80c3dc584
allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
8225
diff
changeset
|
69 passwd = self.ui.getpass() |
7270
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
70 |
29377
2c019aac6b99
url: extract password database from password manager
liscju <piotr.listkiewicz@gmail.com>
parents:
29252
diff
changeset
|
71 self.passwddb.add_password(realm, authuri, user, passwd) |
8333
89c80c3dc584
allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
8225
diff
changeset
|
72 self._writedebug(user, passwd) |
7270
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
73 return (user, passwd) |
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
74 |
8333
89c80c3dc584
allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
8225
diff
changeset
|
75 def _writedebug(self, user, passwd): |
89c80c3dc584
allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
8225
diff
changeset
|
76 msg = _('http auth: user %s, password %s\n') |
89c80c3dc584
allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
8225
diff
changeset
|
77 self.ui.debug(msg % (user, passwd and '*' * len(passwd) or 'not set')) |
89c80c3dc584
allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
8225
diff
changeset
|
78 |
15025
0593e8f81c71
http: pass user to readauthforuri() (fix 4a43e23b8c55)
Patrick Mezard <pmezard@gmail.com>
parents:
15005
diff
changeset
|
79 def find_stored_password(self, authuri): |
29377
2c019aac6b99
url: extract password database from password manager
liscju <piotr.listkiewicz@gmail.com>
parents:
29252
diff
changeset
|
80 return self.passwddb.find_user_password(None, authuri) |
15025
0593e8f81c71
http: pass user to readauthforuri() (fix 4a43e23b8c55)
Patrick Mezard <pmezard@gmail.com>
parents:
15005
diff
changeset
|
81 |
28883
032c4c2f802a
pycompat: switch to util.urlreq/util.urlerr for py3 compat
timeless <timeless@mozdev.org>
parents:
28861
diff
changeset
|
82 class proxyhandler(urlreq.proxyhandler): |
7270
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
83 def __init__(self, ui): |
30667
69acfd2ca11e
py3: replace os.getenv with pycompat.osgetenv
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30665
diff
changeset
|
84 proxyurl = (ui.config("http_proxy", "host") or |
30820
6a70cf94d1b5
py3: replace pycompat.getenv with encoding.environ.get
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30763
diff
changeset
|
85 encoding.environ.get('http_proxy')) |
7270
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
86 # XXX proxyauthinfo = None |
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
87 |
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
88 if proxyurl: |
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
89 # proxy can be proper url or host[:port] |
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
90 if not (proxyurl.startswith('http:') or |
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
91 proxyurl.startswith('https:')): |
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
92 proxyurl = 'http://' + proxyurl + '/' |
14076
924c82157d46
url: move URL parsing functions into util to improve startup time
Brodie Rao <brodie@bitheap.org>
parents:
14071
diff
changeset
|
93 proxy = util.url(proxyurl) |
13820
65b89e80f892
url: use url.url in proxyhandler
Brodie Rao <brodie@bitheap.org>
parents:
13819
diff
changeset
|
94 if not proxy.user: |
65b89e80f892
url: use url.url in proxyhandler
Brodie Rao <brodie@bitheap.org>
parents:
13819
diff
changeset
|
95 proxy.user = ui.config("http_proxy", "user") |
65b89e80f892
url: use url.url in proxyhandler
Brodie Rao <brodie@bitheap.org>
parents:
13819
diff
changeset
|
96 proxy.passwd = ui.config("http_proxy", "passwd") |
7270
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
97 |
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
98 # see if we should use a proxy for this url |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10263
diff
changeset
|
99 no_list = ["localhost", "127.0.0.1"] |
7270
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
100 no_list.extend([p.lower() for |
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
101 p in ui.configlist("http_proxy", "no")]) |
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
102 no_list.extend([p.strip().lower() for |
30820
6a70cf94d1b5
py3: replace pycompat.getenv with encoding.environ.get
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30763
diff
changeset
|
103 p in encoding.environ.get("no_proxy", '').split(',') |
7270
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
104 if p.strip()]) |
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
105 # "http_proxy.always" config is for running tests on localhost |
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
106 if ui.configbool("http_proxy", "always"): |
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
107 self.no_list = [] |
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
108 else: |
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
109 self.no_list = no_list |
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
110 |
13820
65b89e80f892
url: use url.url in proxyhandler
Brodie Rao <brodie@bitheap.org>
parents:
13819
diff
changeset
|
111 proxyurl = str(proxy) |
7270
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
112 proxies = {'http': proxyurl, 'https': proxyurl} |
9467
4c041f1ee1b4
do not attempt to translate ui.debug output
Martin Geisler <mg@lazybytes.net>
parents:
9347
diff
changeset
|
113 ui.debug('proxying through http://%s:%s\n' % |
13820
65b89e80f892
url: use url.url in proxyhandler
Brodie Rao <brodie@bitheap.org>
parents:
13819
diff
changeset
|
114 (proxy.host, proxy.port)) |
7270
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
115 else: |
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
116 proxies = {} |
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
117 |
28883
032c4c2f802a
pycompat: switch to util.urlreq/util.urlerr for py3 compat
timeless <timeless@mozdev.org>
parents:
28861
diff
changeset
|
118 urlreq.proxyhandler.__init__(self, proxies) |
7270
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
119 self.ui = ui |
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
120 |
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
121 def proxy_open(self, req, proxy, type_): |
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
122 host = req.get_host().split(':')[0] |
19535
df2155ebf502
proxy: allow wildcards in the no proxy list (issue1821)
Matt Mackall <mpm@selenic.com>
parents:
18176
diff
changeset
|
123 for e in self.no_list: |
df2155ebf502
proxy: allow wildcards in the no proxy list (issue1821)
Matt Mackall <mpm@selenic.com>
parents:
18176
diff
changeset
|
124 if host == e: |
df2155ebf502
proxy: allow wildcards in the no proxy list (issue1821)
Matt Mackall <mpm@selenic.com>
parents:
18176
diff
changeset
|
125 return None |
df2155ebf502
proxy: allow wildcards in the no proxy list (issue1821)
Matt Mackall <mpm@selenic.com>
parents:
18176
diff
changeset
|
126 if e.startswith('*.') and host.endswith(e[2:]): |
df2155ebf502
proxy: allow wildcards in the no proxy list (issue1821)
Matt Mackall <mpm@selenic.com>
parents:
18176
diff
changeset
|
127 return None |
df2155ebf502
proxy: allow wildcards in the no proxy list (issue1821)
Matt Mackall <mpm@selenic.com>
parents:
18176
diff
changeset
|
128 if e.startswith('.') and host.endswith(e[1:]): |
df2155ebf502
proxy: allow wildcards in the no proxy list (issue1821)
Matt Mackall <mpm@selenic.com>
parents:
18176
diff
changeset
|
129 return None |
7270
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
130 |
28883
032c4c2f802a
pycompat: switch to util.urlreq/util.urlerr for py3 compat
timeless <timeless@mozdev.org>
parents:
28861
diff
changeset
|
131 return urlreq.proxyhandler.proxy_open(self, req, proxy, type_) |
7270
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
132 |
13420
051f498628f7
url: refactor _gen_sendfile
Mads Kiilerich <mads@kiilerich.com>
parents:
13419
diff
changeset
|
133 def _gen_sendfile(orgsend): |
7270
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
134 def _sendfile(self, data): |
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
135 # send a file |
14244
e7525a555a64
url: use new http support if requested by the user
Augie Fackler <durin42@gmail.com>
parents:
14204
diff
changeset
|
136 if isinstance(data, httpconnectionmod.httpsendfile): |
7270
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
137 # if auth required, some data sent twice, so rewind here |
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
138 data.seek(0) |
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
139 for chunk in util.filechunkiter(data): |
13420
051f498628f7
url: refactor _gen_sendfile
Mads Kiilerich <mads@kiilerich.com>
parents:
13419
diff
changeset
|
140 orgsend(self, chunk) |
7270
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
141 else: |
13420
051f498628f7
url: refactor _gen_sendfile
Mads Kiilerich <mads@kiilerich.com>
parents:
13419
diff
changeset
|
142 orgsend(self, data) |
7270
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
143 return _sendfile |
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
144 |
28883
032c4c2f802a
pycompat: switch to util.urlreq/util.urlerr for py3 compat
timeless <timeless@mozdev.org>
parents:
28861
diff
changeset
|
145 has_https = util.safehasattr(urlreq, 'httpshandler') |
10409
4c94a3df4b10
url: SSL server certificate verification using web.cacerts file (issue1174)
Henrik Stuart <hg@hstuart.dk>
parents:
10408
diff
changeset
|
146 |
7270
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
147 class httpconnection(keepalive.HTTPConnection): |
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
148 # must be able to send big bundle as stream. |
13420
051f498628f7
url: refactor _gen_sendfile
Mads Kiilerich <mads@kiilerich.com>
parents:
13419
diff
changeset
|
149 send = _gen_sendfile(keepalive.HTTPConnection.send) |
7270
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
150 |
8590
59acb9c7d90f
url: use CONNECT for HTTPS connections through HTTP proxy (issue967)
Henrik Stuart <hg@hstuart.dk>
parents:
8344
diff
changeset
|
151 def getresponse(self): |
59acb9c7d90f
url: use CONNECT for HTTPS connections through HTTP proxy (issue967)
Henrik Stuart <hg@hstuart.dk>
parents:
8344
diff
changeset
|
152 proxyres = getattr(self, 'proxyres', None) |
59acb9c7d90f
url: use CONNECT for HTTPS connections through HTTP proxy (issue967)
Henrik Stuart <hg@hstuart.dk>
parents:
8344
diff
changeset
|
153 if proxyres: |
59acb9c7d90f
url: use CONNECT for HTTPS connections through HTTP proxy (issue967)
Henrik Stuart <hg@hstuart.dk>
parents:
8344
diff
changeset
|
154 if proxyres.will_close: |
59acb9c7d90f
url: use CONNECT for HTTPS connections through HTTP proxy (issue967)
Henrik Stuart <hg@hstuart.dk>
parents:
8344
diff
changeset
|
155 self.close() |
59acb9c7d90f
url: use CONNECT for HTTPS connections through HTTP proxy (issue967)
Henrik Stuart <hg@hstuart.dk>
parents:
8344
diff
changeset
|
156 self.proxyres = None |
59acb9c7d90f
url: use CONNECT for HTTPS connections through HTTP proxy (issue967)
Henrik Stuart <hg@hstuart.dk>
parents:
8344
diff
changeset
|
157 return proxyres |
59acb9c7d90f
url: use CONNECT for HTTPS connections through HTTP proxy (issue967)
Henrik Stuart <hg@hstuart.dk>
parents:
8344
diff
changeset
|
158 return keepalive.HTTPConnection.getresponse(self) |
59acb9c7d90f
url: use CONNECT for HTTPS connections through HTTP proxy (issue967)
Henrik Stuart <hg@hstuart.dk>
parents:
8344
diff
changeset
|
159 |
9852
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
160 # general transaction handler to support different ways to handle |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
161 # HTTPS proxying before and after Python 2.6.3. |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
162 def _generic_start_transaction(handler, h, req): |
14964
376c32a5ccdc
url: replace uses of hasattr with safehasattr or getattr
Augie Fackler <durin42@gmail.com>
parents:
14244
diff
changeset
|
163 tunnel_host = getattr(req, '_tunnel_host', None) |
376c32a5ccdc
url: replace uses of hasattr with safehasattr or getattr
Augie Fackler <durin42@gmail.com>
parents:
14244
diff
changeset
|
164 if tunnel_host: |
9852
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
165 if tunnel_host[:7] not in ['http://', 'https:/']: |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
166 tunnel_host = 'https://' + tunnel_host |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
167 new_tunnel = True |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
168 else: |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
169 tunnel_host = req.get_selector() |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
170 new_tunnel = False |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
171 |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
172 if new_tunnel or tunnel_host == req.get_full_url(): # has proxy |
14076
924c82157d46
url: move URL parsing functions into util to improve startup time
Brodie Rao <brodie@bitheap.org>
parents:
14071
diff
changeset
|
173 u = util.url(tunnel_host) |
13820
65b89e80f892
url: use url.url in proxyhandler
Brodie Rao <brodie@bitheap.org>
parents:
13819
diff
changeset
|
174 if new_tunnel or u.scheme == 'https': # only use CONNECT for HTTPS |
65b89e80f892
url: use url.url in proxyhandler
Brodie Rao <brodie@bitheap.org>
parents:
13819
diff
changeset
|
175 h.realhostport = ':'.join([u.host, (u.port or '443')]) |
9852
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
176 h.headers = req.headers.copy() |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
177 h.headers.update(handler.parent.addheaders) |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
178 return |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
179 |
10415
677f15da38c1
url: proxy handling, simplify and correctly deal with IPv6
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10411
diff
changeset
|
180 h.realhostport = None |
9852
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
181 h.headers = None |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
182 |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
183 def _generic_proxytunnel(self): |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
184 proxyheaders = dict( |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
185 [(x, self.headers[x]) for x in self.headers |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
186 if x.lower().startswith('proxy-')]) |
10415
677f15da38c1
url: proxy handling, simplify and correctly deal with IPv6
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10411
diff
changeset
|
187 self.send('CONNECT %s HTTP/1.0\r\n' % self.realhostport) |
9852
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
188 for header in proxyheaders.iteritems(): |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
189 self.send('%s: %s\r\n' % header) |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
190 self.send('\r\n') |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
191 |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
192 # majority of the following code is duplicated from |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
193 # httplib.HTTPConnection as there are no adequate places to |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
194 # override functions to provide the needed functionality |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
195 res = self.response_class(self.sock, |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
196 strict=self.strict, |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
197 method=self._method) |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
198 |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
199 while True: |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
200 version, status, reason = res._read_status() |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
201 if status != httplib.CONTINUE: |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
202 break |
29741
44ea12756fef
url: use `iter(callable, sentinel)` instead of while True
Augie Fackler <augie@google.com>
parents:
29682
diff
changeset
|
203 # skip lines that are all whitespace |
44ea12756fef
url: use `iter(callable, sentinel)` instead of while True
Augie Fackler <augie@google.com>
parents:
29682
diff
changeset
|
204 list(iter(lambda: res.fp.readline().strip(), '')) |
9852
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
205 res.status = status |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
206 res.reason = reason.strip() |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
207 |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
208 if res.status == 200: |
29741
44ea12756fef
url: use `iter(callable, sentinel)` instead of while True
Augie Fackler <augie@google.com>
parents:
29682
diff
changeset
|
209 # skip lines until we find a blank line |
44ea12756fef
url: use `iter(callable, sentinel)` instead of while True
Augie Fackler <augie@google.com>
parents:
29682
diff
changeset
|
210 list(iter(res.fp.readline, '\r\n')) |
9852
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
211 return True |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
212 |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
213 if version == 'HTTP/1.0': |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
214 res.version = 10 |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
215 elif version.startswith('HTTP/1.'): |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
216 res.version = 11 |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
217 elif version == 'HTTP/0.9': |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
218 res.version = 9 |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
219 else: |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
220 raise httplib.UnknownProtocol(version) |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
221 |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
222 if res.version == 9: |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
223 res.length = None |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
224 res.chunked = 0 |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
225 res.will_close = 1 |
28861
86db5cb55d46
pycompat: switch to util.stringio for py3 compat
timeless <timeless@mozdev.org>
parents:
26806
diff
changeset
|
226 res.msg = httplib.HTTPMessage(stringio()) |
9852
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
227 return False |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
228 |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
229 res.msg = httplib.HTTPMessage(res.fp) |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
230 res.msg.fp = None |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
231 |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
232 # are we using the chunked-style of transfer encoding? |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
233 trenc = res.msg.getheader('transfer-encoding') |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
234 if trenc and trenc.lower() == "chunked": |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
235 res.chunked = 1 |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
236 res.chunk_left = None |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
237 else: |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
238 res.chunked = 0 |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
239 |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
240 # will the connection close at the end of the response? |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
241 res.will_close = res._check_close() |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
242 |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
243 # do we have a Content-Length? |
17428
72803c8edaa4
avoid using abbreviations that look like spelling errors
Mads Kiilerich <mads@kiilerich.com>
parents:
17424
diff
changeset
|
244 # NOTE: RFC 2616, section 4.4, #3 says we ignore this if |
72803c8edaa4
avoid using abbreviations that look like spelling errors
Mads Kiilerich <mads@kiilerich.com>
parents:
17424
diff
changeset
|
245 # transfer-encoding is "chunked" |
9852
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
246 length = res.msg.getheader('content-length') |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
247 if length and not res.chunked: |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
248 try: |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
249 res.length = int(length) |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
250 except ValueError: |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
251 res.length = None |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
252 else: |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
253 if res.length < 0: # ignore nonsensical negative lengths |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
254 res.length = None |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
255 else: |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
256 res.length = None |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
257 |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
258 # does the body have a fixed length? (of zero) |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
259 if (status == httplib.NO_CONTENT or status == httplib.NOT_MODIFIED or |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
260 100 <= status < 200 or # 1xx codes |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
261 res._method == 'HEAD'): |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
262 res.length = 0 |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
263 |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
264 # if the connection remains open, and we aren't using chunked, and |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
265 # a content-length was not provided, then assume that the connection |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
266 # WILL close. |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
267 if (not res.will_close and |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
268 not res.chunked and |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
269 res.length is None): |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
270 res.will_close = 1 |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
271 |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
272 self.proxyres = res |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
273 |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
274 return False |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
275 |
7270
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
276 class httphandler(keepalive.HTTPHandler): |
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
277 def http_open(self, req): |
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
278 return self.do_open(httpconnection, req) |
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
279 |
8590
59acb9c7d90f
url: use CONNECT for HTTPS connections through HTTP proxy (issue967)
Henrik Stuart <hg@hstuart.dk>
parents:
8344
diff
changeset
|
280 def _start_transaction(self, h, req): |
9852
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
281 _generic_start_transaction(self, h, req) |
8590
59acb9c7d90f
url: use CONNECT for HTTPS connections through HTTP proxy (issue967)
Henrik Stuart <hg@hstuart.dk>
parents:
8344
diff
changeset
|
282 return keepalive.HTTPHandler._start_transaction(self, h, req) |
59acb9c7d90f
url: use CONNECT for HTTPS connections through HTTP proxy (issue967)
Henrik Stuart <hg@hstuart.dk>
parents:
8344
diff
changeset
|
283 |
7270
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
284 if has_https: |
25414
f7ccbc2776b7
https: do not inherit httplib.HTTPSConnection that creates unused SSLContext
Yuya Nishihara <yuya@tcha.org>
parents:
25207
diff
changeset
|
285 class httpsconnection(httplib.HTTPConnection): |
13424
08f9c587141f
url: merge BetterHTTPS with httpsconnection to get some proxy https validation
Mads Kiilerich <mads@kiilerich.com>
parents:
13422
diff
changeset
|
286 response_class = keepalive.HTTPResponse |
25414
f7ccbc2776b7
https: do not inherit httplib.HTTPSConnection that creates unused SSLContext
Yuya Nishihara <yuya@tcha.org>
parents:
25207
diff
changeset
|
287 default_port = httplib.HTTPS_PORT |
13424
08f9c587141f
url: merge BetterHTTPS with httpsconnection to get some proxy https validation
Mads Kiilerich <mads@kiilerich.com>
parents:
13422
diff
changeset
|
288 # must be able to send big bundle as stream. |
08f9c587141f
url: merge BetterHTTPS with httpsconnection to get some proxy https validation
Mads Kiilerich <mads@kiilerich.com>
parents:
13422
diff
changeset
|
289 send = _gen_sendfile(keepalive.safesend) |
25414
f7ccbc2776b7
https: do not inherit httplib.HTTPSConnection that creates unused SSLContext
Yuya Nishihara <yuya@tcha.org>
parents:
25207
diff
changeset
|
290 getresponse = keepalive.wrapgetresponse(httplib.HTTPConnection) |
f7ccbc2776b7
https: do not inherit httplib.HTTPSConnection that creates unused SSLContext
Yuya Nishihara <yuya@tcha.org>
parents:
25207
diff
changeset
|
291 |
f7ccbc2776b7
https: do not inherit httplib.HTTPSConnection that creates unused SSLContext
Yuya Nishihara <yuya@tcha.org>
parents:
25207
diff
changeset
|
292 def __init__(self, host, port=None, key_file=None, cert_file=None, |
f7ccbc2776b7
https: do not inherit httplib.HTTPSConnection that creates unused SSLContext
Yuya Nishihara <yuya@tcha.org>
parents:
25207
diff
changeset
|
293 *args, **kwargs): |
f7ccbc2776b7
https: do not inherit httplib.HTTPSConnection that creates unused SSLContext
Yuya Nishihara <yuya@tcha.org>
parents:
25207
diff
changeset
|
294 httplib.HTTPConnection.__init__(self, host, port, *args, **kwargs) |
f7ccbc2776b7
https: do not inherit httplib.HTTPSConnection that creates unused SSLContext
Yuya Nishihara <yuya@tcha.org>
parents:
25207
diff
changeset
|
295 self.key_file = key_file |
f7ccbc2776b7
https: do not inherit httplib.HTTPSConnection that creates unused SSLContext
Yuya Nishihara <yuya@tcha.org>
parents:
25207
diff
changeset
|
296 self.cert_file = cert_file |
9726
430e59ff3437
keepalive: handle broken pipes gracefully during large POSTs
Augie Fackler <durin42@gmail.com>
parents:
9467
diff
changeset
|
297 |
10409
4c94a3df4b10
url: SSL server certificate verification using web.cacerts file (issue1174)
Henrik Stuart <hg@hstuart.dk>
parents:
10408
diff
changeset
|
298 def connect(self): |
29682
b76ea1384bf2
url: drop compatibility wrapper of socket.create_connection()
Yuya Nishihara <yuya@tcha.org>
parents:
29639
diff
changeset
|
299 self.sock = socket.create_connection((self.host, self.port)) |
13422
ebce5196b9db
url: always create BetterHTTPS connections the same way
Mads Kiilerich <mads@kiilerich.com>
parents:
13421
diff
changeset
|
300 |
13421
bd8bfa85d5a5
url: refactor BetterHTTPS.connect
Mads Kiilerich <mads@kiilerich.com>
parents:
13420
diff
changeset
|
301 host = self.host |
13424
08f9c587141f
url: merge BetterHTTPS with httpsconnection to get some proxy https validation
Mads Kiilerich <mads@kiilerich.com>
parents:
13422
diff
changeset
|
302 if self.realhostport: # use CONNECT proxy |
14064
e4bfb9c337f3
remove unused imports and variables
Alexander Solovyov <alexander@solovyov.net>
parents:
13902
diff
changeset
|
303 _generic_proxytunnel(self) |
13424
08f9c587141f
url: merge BetterHTTPS with httpsconnection to get some proxy https validation
Mads Kiilerich <mads@kiilerich.com>
parents:
13422
diff
changeset
|
304 host = self.realhostport.rsplit(':', 1)[0] |
25429
9d1c61715939
ssl: rename ssl_wrap_socket() to conform to our naming convention
Yuya Nishihara <yuya@tcha.org>
parents:
25415
diff
changeset
|
305 self.sock = sslutil.wrapsocket( |
29248
e6de6ef3e426
sslutil: remove ui from sslkwargs (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29227
diff
changeset
|
306 self.sock, self.key_file, self.cert_file, ui=self.ui, |
29252
f1fe92c6c03c
url: remove use of sslkwargs
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29248
diff
changeset
|
307 serverhostname=host) |
29227
dffe78d80a6c
sslutil: convert socket validation from a class to a function (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28883
diff
changeset
|
308 sslutil.validatesocket(self.sock) |
10409
4c94a3df4b10
url: SSL server certificate verification using web.cacerts file (issue1174)
Henrik Stuart <hg@hstuart.dk>
parents:
10408
diff
changeset
|
309 |
28883
032c4c2f802a
pycompat: switch to util.urlreq/util.urlerr for py3 compat
timeless <timeless@mozdev.org>
parents:
28861
diff
changeset
|
310 class httpshandler(keepalive.KeepAliveHandler, urlreq.httpshandler): |
8847
7951f385fcb7
url: support client certificate files over HTTPS (issue643)
Henrik Stuart <hg@hstuart.dk>
parents:
8590
diff
changeset
|
311 def __init__(self, ui): |
7951f385fcb7
url: support client certificate files over HTTPS (issue643)
Henrik Stuart <hg@hstuart.dk>
parents:
8590
diff
changeset
|
312 keepalive.KeepAliveHandler.__init__(self) |
28883
032c4c2f802a
pycompat: switch to util.urlreq/util.urlerr for py3 compat
timeless <timeless@mozdev.org>
parents:
28861
diff
changeset
|
313 urlreq.httpshandler.__init__(self) |
8847
7951f385fcb7
url: support client certificate files over HTTPS (issue643)
Henrik Stuart <hg@hstuart.dk>
parents:
8590
diff
changeset
|
314 self.ui = ui |
29377
2c019aac6b99
url: extract password database from password manager
liscju <piotr.listkiewicz@gmail.com>
parents:
29252
diff
changeset
|
315 self.pwmgr = passwordmgr(self.ui, |
29378
fea71f66ebff
url: remember http password database in ui object
liscju <piotr.listkiewicz@gmail.com>
parents:
29377
diff
changeset
|
316 self.ui.httppasswordmgrdb) |
8847
7951f385fcb7
url: support client certificate files over HTTPS (issue643)
Henrik Stuart <hg@hstuart.dk>
parents:
8590
diff
changeset
|
317 |
9852
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
318 def _start_transaction(self, h, req): |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
319 _generic_start_transaction(self, h, req) |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
320 return keepalive.KeepAliveHandler._start_transaction(self, h, req) |
917cf6bb6d0c
url: generalise HTTPS proxy handling to accomodate Python changes
Henrik Stuart <hg@hstuart.dk>
parents:
9726
diff
changeset
|
321 |
7270
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
322 def https_open(self, req): |
15025
0593e8f81c71
http: pass user to readauthforuri() (fix 4a43e23b8c55)
Patrick Mezard <pmezard@gmail.com>
parents:
15005
diff
changeset
|
323 # req.get_full_url() does not contain credentials and we may |
0593e8f81c71
http: pass user to readauthforuri() (fix 4a43e23b8c55)
Patrick Mezard <pmezard@gmail.com>
parents:
15005
diff
changeset
|
324 # need them to match the certificates. |
0593e8f81c71
http: pass user to readauthforuri() (fix 4a43e23b8c55)
Patrick Mezard <pmezard@gmail.com>
parents:
15005
diff
changeset
|
325 url = req.get_full_url() |
0593e8f81c71
http: pass user to readauthforuri() (fix 4a43e23b8c55)
Patrick Mezard <pmezard@gmail.com>
parents:
15005
diff
changeset
|
326 user, password = self.pwmgr.find_stored_password(url) |
0593e8f81c71
http: pass user to readauthforuri() (fix 4a43e23b8c55)
Patrick Mezard <pmezard@gmail.com>
parents:
15005
diff
changeset
|
327 res = httpconnectionmod.readauthforuri(self.ui, url, user) |
13372
5bced0d28a39
url: return the matched authentication group name from readauthforuri()
Steve Borho <steve@borho.org>
parents:
13371
diff
changeset
|
328 if res: |
5bced0d28a39
url: return the matched authentication group name from readauthforuri()
Steve Borho <steve@borho.org>
parents:
13371
diff
changeset
|
329 group, auth = res |
5bced0d28a39
url: return the matched authentication group name from readauthforuri()
Steve Borho <steve@borho.org>
parents:
13371
diff
changeset
|
330 self.auth = auth |
5bced0d28a39
url: return the matched authentication group name from readauthforuri()
Steve Borho <steve@borho.org>
parents:
13371
diff
changeset
|
331 self.ui.debug("using auth.%s.* for authentication\n" % group) |
5bced0d28a39
url: return the matched authentication group name from readauthforuri()
Steve Borho <steve@borho.org>
parents:
13371
diff
changeset
|
332 else: |
5bced0d28a39
url: return the matched authentication group name from readauthforuri()
Steve Borho <steve@borho.org>
parents:
13371
diff
changeset
|
333 self.auth = None |
8847
7951f385fcb7
url: support client certificate files over HTTPS (issue643)
Henrik Stuart <hg@hstuart.dk>
parents:
8590
diff
changeset
|
334 return self.do_open(self._makeconnection, req) |
7951f385fcb7
url: support client certificate files over HTTPS (issue643)
Henrik Stuart <hg@hstuart.dk>
parents:
8590
diff
changeset
|
335 |
10408
50fb1fe143ff
url: httplib.HTTPSConnection already handles IPv6 and port parsing fine
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10282
diff
changeset
|
336 def _makeconnection(self, host, port=None, *args, **kwargs): |
8847
7951f385fcb7
url: support client certificate files over HTTPS (issue643)
Henrik Stuart <hg@hstuart.dk>
parents:
8590
diff
changeset
|
337 keyfile = None |
7951f385fcb7
url: support client certificate files over HTTPS (issue643)
Henrik Stuart <hg@hstuart.dk>
parents:
8590
diff
changeset
|
338 certfile = None |
7951f385fcb7
url: support client certificate files over HTTPS (issue643)
Henrik Stuart <hg@hstuart.dk>
parents:
8590
diff
changeset
|
339 |
10511
6f61c480f51c
url: *args argument is a tuple, not a list (found by pylint)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10484
diff
changeset
|
340 if len(args) >= 1: # key_file |
6f61c480f51c
url: *args argument is a tuple, not a list (found by pylint)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10484
diff
changeset
|
341 keyfile = args[0] |
6f61c480f51c
url: *args argument is a tuple, not a list (found by pylint)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10484
diff
changeset
|
342 if len(args) >= 2: # cert_file |
6f61c480f51c
url: *args argument is a tuple, not a list (found by pylint)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10484
diff
changeset
|
343 certfile = args[1] |
6f61c480f51c
url: *args argument is a tuple, not a list (found by pylint)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10484
diff
changeset
|
344 args = args[2:] |
8847
7951f385fcb7
url: support client certificate files over HTTPS (issue643)
Henrik Stuart <hg@hstuart.dk>
parents:
8590
diff
changeset
|
345 |
7951f385fcb7
url: support client certificate files over HTTPS (issue643)
Henrik Stuart <hg@hstuart.dk>
parents:
8590
diff
changeset
|
346 # if the user has specified different key/cert files in |
7951f385fcb7
url: support client certificate files over HTTPS (issue643)
Henrik Stuart <hg@hstuart.dk>
parents:
8590
diff
changeset
|
347 # hgrc, we prefer these |
7951f385fcb7
url: support client certificate files over HTTPS (issue643)
Henrik Stuart <hg@hstuart.dk>
parents:
8590
diff
changeset
|
348 if self.auth and 'key' in self.auth and 'cert' in self.auth: |
7951f385fcb7
url: support client certificate files over HTTPS (issue643)
Henrik Stuart <hg@hstuart.dk>
parents:
8590
diff
changeset
|
349 keyfile = self.auth['key'] |
7951f385fcb7
url: support client certificate files over HTTPS (issue643)
Henrik Stuart <hg@hstuart.dk>
parents:
8590
diff
changeset
|
350 certfile = self.auth['cert'] |
7951f385fcb7
url: support client certificate files over HTTPS (issue643)
Henrik Stuart <hg@hstuart.dk>
parents:
8590
diff
changeset
|
351 |
16683 | 352 conn = httpsconnection(host, port, keyfile, certfile, *args, |
353 **kwargs) | |
10409
4c94a3df4b10
url: SSL server certificate verification using web.cacerts file (issue1174)
Henrik Stuart <hg@hstuart.dk>
parents:
10408
diff
changeset
|
354 conn.ui = self.ui |
4c94a3df4b10
url: SSL server certificate verification using web.cacerts file (issue1174)
Henrik Stuart <hg@hstuart.dk>
parents:
10408
diff
changeset
|
355 return conn |
7270
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
356 |
28883
032c4c2f802a
pycompat: switch to util.urlreq/util.urlerr for py3 compat
timeless <timeless@mozdev.org>
parents:
28861
diff
changeset
|
357 class httpdigestauthhandler(urlreq.httpdigestauthhandler): |
11457
2ec346160783
http digest auth: reset redirect counter on new requests (issue2255)
Mads Kiilerich <mads@kiilerich.com>
parents:
11415
diff
changeset
|
358 def __init__(self, *args, **kwargs): |
28883
032c4c2f802a
pycompat: switch to util.urlreq/util.urlerr for py3 compat
timeless <timeless@mozdev.org>
parents:
28861
diff
changeset
|
359 urlreq.httpdigestauthhandler.__init__(self, *args, **kwargs) |
11457
2ec346160783
http digest auth: reset redirect counter on new requests (issue2255)
Mads Kiilerich <mads@kiilerich.com>
parents:
11415
diff
changeset
|
360 self.retried_req = None |
2ec346160783
http digest auth: reset redirect counter on new requests (issue2255)
Mads Kiilerich <mads@kiilerich.com>
parents:
11415
diff
changeset
|
361 |
2ec346160783
http digest auth: reset redirect counter on new requests (issue2255)
Mads Kiilerich <mads@kiilerich.com>
parents:
11415
diff
changeset
|
362 def reset_retry_count(self): |
2ec346160783
http digest auth: reset redirect counter on new requests (issue2255)
Mads Kiilerich <mads@kiilerich.com>
parents:
11415
diff
changeset
|
363 # Python 2.6.5 will call this on 401 or 407 errors and thus loop |
2ec346160783
http digest auth: reset redirect counter on new requests (issue2255)
Mads Kiilerich <mads@kiilerich.com>
parents:
11415
diff
changeset
|
364 # forever. We disable reset_retry_count completely and reset in |
2ec346160783
http digest auth: reset redirect counter on new requests (issue2255)
Mads Kiilerich <mads@kiilerich.com>
parents:
11415
diff
changeset
|
365 # http_error_auth_reqed instead. |
2ec346160783
http digest auth: reset redirect counter on new requests (issue2255)
Mads Kiilerich <mads@kiilerich.com>
parents:
11415
diff
changeset
|
366 pass |
2ec346160783
http digest auth: reset redirect counter on new requests (issue2255)
Mads Kiilerich <mads@kiilerich.com>
parents:
11415
diff
changeset
|
367 |
7270
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
368 def http_error_auth_reqed(self, auth_header, host, req, headers): |
11457
2ec346160783
http digest auth: reset redirect counter on new requests (issue2255)
Mads Kiilerich <mads@kiilerich.com>
parents:
11415
diff
changeset
|
369 # Reset the retry counter once for each request. |
2ec346160783
http digest auth: reset redirect counter on new requests (issue2255)
Mads Kiilerich <mads@kiilerich.com>
parents:
11415
diff
changeset
|
370 if req is not self.retried_req: |
2ec346160783
http digest auth: reset redirect counter on new requests (issue2255)
Mads Kiilerich <mads@kiilerich.com>
parents:
11415
diff
changeset
|
371 self.retried_req = req |
2ec346160783
http digest auth: reset redirect counter on new requests (issue2255)
Mads Kiilerich <mads@kiilerich.com>
parents:
11415
diff
changeset
|
372 self.retried = 0 |
28883
032c4c2f802a
pycompat: switch to util.urlreq/util.urlerr for py3 compat
timeless <timeless@mozdev.org>
parents:
28861
diff
changeset
|
373 return urlreq.httpdigestauthhandler.http_error_auth_reqed( |
26806
ec12ebe20200
url: drop support for python2.5
timeless <timeless@mozdev.org>
parents:
26587
diff
changeset
|
374 self, auth_header, host, req, headers) |
7270
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
375 |
28883
032c4c2f802a
pycompat: switch to util.urlreq/util.urlerr for py3 compat
timeless <timeless@mozdev.org>
parents:
28861
diff
changeset
|
376 class httpbasicauthhandler(urlreq.httpbasicauthhandler): |
11844
6c51a5056020
http basic auth: reset redirect counter on new requests (issue2255)
Wagner Bruna <wbruna@softwareexpress.com.br>
parents:
11457
diff
changeset
|
377 def __init__(self, *args, **kwargs): |
20964
a939eeb94833
http: reuse authentication info after the first failed request (issue3567)
St?phane Klein <contact@stephane-klein.info>
parents:
20291
diff
changeset
|
378 self.auth = None |
28883
032c4c2f802a
pycompat: switch to util.urlreq/util.urlerr for py3 compat
timeless <timeless@mozdev.org>
parents:
28861
diff
changeset
|
379 urlreq.httpbasicauthhandler.__init__(self, *args, **kwargs) |
11844
6c51a5056020
http basic auth: reset redirect counter on new requests (issue2255)
Wagner Bruna <wbruna@softwareexpress.com.br>
parents:
11457
diff
changeset
|
380 self.retried_req = None |
6c51a5056020
http basic auth: reset redirect counter on new requests (issue2255)
Wagner Bruna <wbruna@softwareexpress.com.br>
parents:
11457
diff
changeset
|
381 |
20964
a939eeb94833
http: reuse authentication info after the first failed request (issue3567)
St?phane Klein <contact@stephane-klein.info>
parents:
20291
diff
changeset
|
382 def http_request(self, request): |
a939eeb94833
http: reuse authentication info after the first failed request (issue3567)
St?phane Klein <contact@stephane-klein.info>
parents:
20291
diff
changeset
|
383 if self.auth: |
a939eeb94833
http: reuse authentication info after the first failed request (issue3567)
St?phane Klein <contact@stephane-klein.info>
parents:
20291
diff
changeset
|
384 request.add_unredirected_header(self.auth_header, self.auth) |
a939eeb94833
http: reuse authentication info after the first failed request (issue3567)
St?phane Klein <contact@stephane-klein.info>
parents:
20291
diff
changeset
|
385 |
a939eeb94833
http: reuse authentication info after the first failed request (issue3567)
St?phane Klein <contact@stephane-klein.info>
parents:
20291
diff
changeset
|
386 return request |
a939eeb94833
http: reuse authentication info after the first failed request (issue3567)
St?phane Klein <contact@stephane-klein.info>
parents:
20291
diff
changeset
|
387 |
a939eeb94833
http: reuse authentication info after the first failed request (issue3567)
St?phane Klein <contact@stephane-klein.info>
parents:
20291
diff
changeset
|
388 def https_request(self, request): |
a939eeb94833
http: reuse authentication info after the first failed request (issue3567)
St?phane Klein <contact@stephane-klein.info>
parents:
20291
diff
changeset
|
389 if self.auth: |
a939eeb94833
http: reuse authentication info after the first failed request (issue3567)
St?phane Klein <contact@stephane-klein.info>
parents:
20291
diff
changeset
|
390 request.add_unredirected_header(self.auth_header, self.auth) |
a939eeb94833
http: reuse authentication info after the first failed request (issue3567)
St?phane Klein <contact@stephane-klein.info>
parents:
20291
diff
changeset
|
391 |
a939eeb94833
http: reuse authentication info after the first failed request (issue3567)
St?phane Klein <contact@stephane-klein.info>
parents:
20291
diff
changeset
|
392 return request |
a939eeb94833
http: reuse authentication info after the first failed request (issue3567)
St?phane Klein <contact@stephane-klein.info>
parents:
20291
diff
changeset
|
393 |
11844
6c51a5056020
http basic auth: reset redirect counter on new requests (issue2255)
Wagner Bruna <wbruna@softwareexpress.com.br>
parents:
11457
diff
changeset
|
394 def reset_retry_count(self): |
6c51a5056020
http basic auth: reset redirect counter on new requests (issue2255)
Wagner Bruna <wbruna@softwareexpress.com.br>
parents:
11457
diff
changeset
|
395 # Python 2.6.5 will call this on 401 or 407 errors and thus loop |
6c51a5056020
http basic auth: reset redirect counter on new requests (issue2255)
Wagner Bruna <wbruna@softwareexpress.com.br>
parents:
11457
diff
changeset
|
396 # forever. We disable reset_retry_count completely and reset in |
6c51a5056020
http basic auth: reset redirect counter on new requests (issue2255)
Wagner Bruna <wbruna@softwareexpress.com.br>
parents:
11457
diff
changeset
|
397 # http_error_auth_reqed instead. |
6c51a5056020
http basic auth: reset redirect counter on new requests (issue2255)
Wagner Bruna <wbruna@softwareexpress.com.br>
parents:
11457
diff
changeset
|
398 pass |
6c51a5056020
http basic auth: reset redirect counter on new requests (issue2255)
Wagner Bruna <wbruna@softwareexpress.com.br>
parents:
11457
diff
changeset
|
399 |
6c51a5056020
http basic auth: reset redirect counter on new requests (issue2255)
Wagner Bruna <wbruna@softwareexpress.com.br>
parents:
11457
diff
changeset
|
400 def http_error_auth_reqed(self, auth_header, host, req, headers): |
6c51a5056020
http basic auth: reset redirect counter on new requests (issue2255)
Wagner Bruna <wbruna@softwareexpress.com.br>
parents:
11457
diff
changeset
|
401 # Reset the retry counter once for each request. |
6c51a5056020
http basic auth: reset redirect counter on new requests (issue2255)
Wagner Bruna <wbruna@softwareexpress.com.br>
parents:
11457
diff
changeset
|
402 if req is not self.retried_req: |
6c51a5056020
http basic auth: reset redirect counter on new requests (issue2255)
Wagner Bruna <wbruna@softwareexpress.com.br>
parents:
11457
diff
changeset
|
403 self.retried_req = req |
6c51a5056020
http basic auth: reset redirect counter on new requests (issue2255)
Wagner Bruna <wbruna@softwareexpress.com.br>
parents:
11457
diff
changeset
|
404 self.retried = 0 |
28883
032c4c2f802a
pycompat: switch to util.urlreq/util.urlerr for py3 compat
timeless <timeless@mozdev.org>
parents:
28861
diff
changeset
|
405 return urlreq.httpbasicauthhandler.http_error_auth_reqed( |
11844
6c51a5056020
http basic auth: reset redirect counter on new requests (issue2255)
Wagner Bruna <wbruna@softwareexpress.com.br>
parents:
11457
diff
changeset
|
406 self, auth_header, host, req, headers) |
6c51a5056020
http basic auth: reset redirect counter on new requests (issue2255)
Wagner Bruna <wbruna@softwareexpress.com.br>
parents:
11457
diff
changeset
|
407 |
20964
a939eeb94833
http: reuse authentication info after the first failed request (issue3567)
St?phane Klein <contact@stephane-klein.info>
parents:
20291
diff
changeset
|
408 def retry_http_basic_auth(self, host, req, realm): |
a939eeb94833
http: reuse authentication info after the first failed request (issue3567)
St?phane Klein <contact@stephane-klein.info>
parents:
20291
diff
changeset
|
409 user, pw = self.passwd.find_user_password(realm, req.get_full_url()) |
a939eeb94833
http: reuse authentication info after the first failed request (issue3567)
St?phane Klein <contact@stephane-klein.info>
parents:
20291
diff
changeset
|
410 if pw is not None: |
a939eeb94833
http: reuse authentication info after the first failed request (issue3567)
St?phane Klein <contact@stephane-klein.info>
parents:
20291
diff
changeset
|
411 raw = "%s:%s" % (user, pw) |
a939eeb94833
http: reuse authentication info after the first failed request (issue3567)
St?phane Klein <contact@stephane-klein.info>
parents:
20291
diff
changeset
|
412 auth = 'Basic %s' % base64.b64encode(raw).strip() |
29639
6fd751fa58d3
url: avoid re-issuing incorrect password (issue3210)
Kim Randell <Kim.Randell@vicon.com>
parents:
29599
diff
changeset
|
413 if req.get_header(self.auth_header, None) == auth: |
20964
a939eeb94833
http: reuse authentication info after the first failed request (issue3567)
St?phane Klein <contact@stephane-klein.info>
parents:
20291
diff
changeset
|
414 return None |
a939eeb94833
http: reuse authentication info after the first failed request (issue3567)
St?phane Klein <contact@stephane-klein.info>
parents:
20291
diff
changeset
|
415 self.auth = auth |
a939eeb94833
http: reuse authentication info after the first failed request (issue3567)
St?phane Klein <contact@stephane-klein.info>
parents:
20291
diff
changeset
|
416 req.add_unredirected_header(self.auth_header, auth) |
a939eeb94833
http: reuse authentication info after the first failed request (issue3567)
St?phane Klein <contact@stephane-klein.info>
parents:
20291
diff
changeset
|
417 return self.parent.open(req) |
a939eeb94833
http: reuse authentication info after the first failed request (issue3567)
St?phane Klein <contact@stephane-klein.info>
parents:
20291
diff
changeset
|
418 else: |
a939eeb94833
http: reuse authentication info after the first failed request (issue3567)
St?phane Klein <contact@stephane-klein.info>
parents:
20291
diff
changeset
|
419 return None |
a939eeb94833
http: reuse authentication info after the first failed request (issue3567)
St?phane Klein <contact@stephane-klein.info>
parents:
20291
diff
changeset
|
420 |
31936
806f9a883b4f
url: support auth.cookiesfile for adding cookies to HTTP requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30820
diff
changeset
|
421 class cookiehandler(urlreq.basehandler): |
806f9a883b4f
url: support auth.cookiesfile for adding cookies to HTTP requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30820
diff
changeset
|
422 def __init__(self, ui): |
806f9a883b4f
url: support auth.cookiesfile for adding cookies to HTTP requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30820
diff
changeset
|
423 self.cookiejar = None |
806f9a883b4f
url: support auth.cookiesfile for adding cookies to HTTP requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30820
diff
changeset
|
424 |
806f9a883b4f
url: support auth.cookiesfile for adding cookies to HTTP requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30820
diff
changeset
|
425 cookiefile = ui.config('auth', 'cookiefile') |
806f9a883b4f
url: support auth.cookiesfile for adding cookies to HTTP requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30820
diff
changeset
|
426 if not cookiefile: |
806f9a883b4f
url: support auth.cookiesfile for adding cookies to HTTP requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30820
diff
changeset
|
427 return |
806f9a883b4f
url: support auth.cookiesfile for adding cookies to HTTP requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30820
diff
changeset
|
428 |
806f9a883b4f
url: support auth.cookiesfile for adding cookies to HTTP requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30820
diff
changeset
|
429 cookiefile = util.expandpath(cookiefile) |
806f9a883b4f
url: support auth.cookiesfile for adding cookies to HTTP requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30820
diff
changeset
|
430 try: |
806f9a883b4f
url: support auth.cookiesfile for adding cookies to HTTP requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30820
diff
changeset
|
431 cookiejar = util.cookielib.MozillaCookieJar(cookiefile) |
806f9a883b4f
url: support auth.cookiesfile for adding cookies to HTTP requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30820
diff
changeset
|
432 cookiejar.load() |
806f9a883b4f
url: support auth.cookiesfile for adding cookies to HTTP requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30820
diff
changeset
|
433 self.cookiejar = cookiejar |
806f9a883b4f
url: support auth.cookiesfile for adding cookies to HTTP requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30820
diff
changeset
|
434 except util.cookielib.LoadError as e: |
806f9a883b4f
url: support auth.cookiesfile for adding cookies to HTTP requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30820
diff
changeset
|
435 ui.warn(_('(error loading cookie file %s: %s; continuing without ' |
806f9a883b4f
url: support auth.cookiesfile for adding cookies to HTTP requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30820
diff
changeset
|
436 'cookies)\n') % (cookiefile, str(e))) |
806f9a883b4f
url: support auth.cookiesfile for adding cookies to HTTP requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30820
diff
changeset
|
437 |
806f9a883b4f
url: support auth.cookiesfile for adding cookies to HTTP requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30820
diff
changeset
|
438 def http_request(self, request): |
806f9a883b4f
url: support auth.cookiesfile for adding cookies to HTTP requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30820
diff
changeset
|
439 if self.cookiejar: |
806f9a883b4f
url: support auth.cookiesfile for adding cookies to HTTP requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30820
diff
changeset
|
440 self.cookiejar.add_cookie_header(request) |
806f9a883b4f
url: support auth.cookiesfile for adding cookies to HTTP requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30820
diff
changeset
|
441 |
806f9a883b4f
url: support auth.cookiesfile for adding cookies to HTTP requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30820
diff
changeset
|
442 return request |
806f9a883b4f
url: support auth.cookiesfile for adding cookies to HTTP requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30820
diff
changeset
|
443 |
806f9a883b4f
url: support auth.cookiesfile for adding cookies to HTTP requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30820
diff
changeset
|
444 def https_request(self, request): |
806f9a883b4f
url: support auth.cookiesfile for adding cookies to HTTP requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30820
diff
changeset
|
445 if self.cookiejar: |
806f9a883b4f
url: support auth.cookiesfile for adding cookies to HTTP requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30820
diff
changeset
|
446 self.cookiejar.add_cookie_header(request) |
806f9a883b4f
url: support auth.cookiesfile for adding cookies to HTTP requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30820
diff
changeset
|
447 |
806f9a883b4f
url: support auth.cookiesfile for adding cookies to HTTP requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30820
diff
changeset
|
448 return request |
806f9a883b4f
url: support auth.cookiesfile for adding cookies to HTTP requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30820
diff
changeset
|
449 |
9347
d0474b184347
url: add support for custom handlers in extensions
Henrik Stuart <hg@hstuart.dk>
parents:
9122
diff
changeset
|
450 handlerfuncs = [] |
d0474b184347
url: add support for custom handlers in extensions
Henrik Stuart <hg@hstuart.dk>
parents:
9122
diff
changeset
|
451 |
7270
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
452 def opener(ui, authinfo=None): |
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
453 ''' |
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
454 construct an opener suitable for urllib2 |
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
455 authinfo will be added to the password manager |
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
456 ''' |
25837
d343806dcf68
http2: mark experimental and developer options
Matt Mackall <mpm@selenic.com>
parents:
25660
diff
changeset
|
457 # experimental config: ui.usehttp2 |
33499
0407a51b9d8c
codemod: register core configitems using a script
Jun Wu <quark@fb.com>
parents:
31936
diff
changeset
|
458 if ui.configbool('ui', 'usehttp2'): |
29377
2c019aac6b99
url: extract password database from password manager
liscju <piotr.listkiewicz@gmail.com>
parents:
29252
diff
changeset
|
459 handlers = [ |
2c019aac6b99
url: extract password database from password manager
liscju <piotr.listkiewicz@gmail.com>
parents:
29252
diff
changeset
|
460 httpconnectionmod.http2handler( |
2c019aac6b99
url: extract password database from password manager
liscju <piotr.listkiewicz@gmail.com>
parents:
29252
diff
changeset
|
461 ui, |
29378
fea71f66ebff
url: remember http password database in ui object
liscju <piotr.listkiewicz@gmail.com>
parents:
29377
diff
changeset
|
462 passwordmgr(ui, ui.httppasswordmgrdb)) |
29377
2c019aac6b99
url: extract password database from password manager
liscju <piotr.listkiewicz@gmail.com>
parents:
29252
diff
changeset
|
463 ] |
14244
e7525a555a64
url: use new http support if requested by the user
Augie Fackler <durin42@gmail.com>
parents:
14204
diff
changeset
|
464 else: |
e7525a555a64
url: use new http support if requested by the user
Augie Fackler <durin42@gmail.com>
parents:
14204
diff
changeset
|
465 handlers = [httphandler()] |
e7525a555a64
url: use new http support if requested by the user
Augie Fackler <durin42@gmail.com>
parents:
14204
diff
changeset
|
466 if has_https: |
e7525a555a64
url: use new http support if requested by the user
Augie Fackler <durin42@gmail.com>
parents:
14204
diff
changeset
|
467 handlers.append(httpshandler(ui)) |
7270
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
468 |
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
469 handlers.append(proxyhandler(ui)) |
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
470 |
29378
fea71f66ebff
url: remember http password database in ui object
liscju <piotr.listkiewicz@gmail.com>
parents:
29377
diff
changeset
|
471 passmgr = passwordmgr(ui, ui.httppasswordmgrdb) |
7270
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
472 if authinfo is not None: |
29379
fc777c855d66
largefiles: make cloning not ask two times about password (issue4883)
liscju <piotr.listkiewicz@gmail.com>
parents:
29378
diff
changeset
|
473 realm, uris, user, passwd = authinfo |
fc777c855d66
largefiles: make cloning not ask two times about password (issue4883)
liscju <piotr.listkiewicz@gmail.com>
parents:
29378
diff
changeset
|
474 saveduser, savedpass = passmgr.find_stored_password(uris[0]) |
fc777c855d66
largefiles: make cloning not ask two times about password (issue4883)
liscju <piotr.listkiewicz@gmail.com>
parents:
29378
diff
changeset
|
475 if user != saveduser or passwd: |
fc777c855d66
largefiles: make cloning not ask two times about password (issue4883)
liscju <piotr.listkiewicz@gmail.com>
parents:
29378
diff
changeset
|
476 passmgr.add_password(realm, uris, user, passwd) |
9467
4c041f1ee1b4
do not attempt to translate ui.debug output
Martin Geisler <mg@lazybytes.net>
parents:
9347
diff
changeset
|
477 ui.debug('http auth: user %s, password %s\n' % |
7270
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
478 (user, passwd and '*' * len(passwd) or 'not set')) |
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
479 |
11844
6c51a5056020
http basic auth: reset redirect counter on new requests (issue2255)
Wagner Bruna <wbruna@softwareexpress.com.br>
parents:
11457
diff
changeset
|
480 handlers.extend((httpbasicauthhandler(passmgr), |
7270
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
481 httpdigestauthhandler(passmgr))) |
9347
d0474b184347
url: add support for custom handlers in extensions
Henrik Stuart <hg@hstuart.dk>
parents:
9122
diff
changeset
|
482 handlers.extend([h(ui, passmgr) for h in handlerfuncs]) |
31936
806f9a883b4f
url: support auth.cookiesfile for adding cookies to HTTP requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30820
diff
changeset
|
483 handlers.append(cookiehandler(ui)) |
28883
032c4c2f802a
pycompat: switch to util.urlreq/util.urlerr for py3 compat
timeless <timeless@mozdev.org>
parents:
28861
diff
changeset
|
484 opener = urlreq.buildopener(*handlers) |
7270
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
485 |
29589
486de14eb394
url: add distribution and version to user-agent request header (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29455
diff
changeset
|
486 # The user agent should should *NOT* be used by servers for e.g. |
486de14eb394
url: add distribution and version to user-agent request header (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29455
diff
changeset
|
487 # protocol detection or feature negotiation: there are other |
486de14eb394
url: add distribution and version to user-agent request header (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29455
diff
changeset
|
488 # facilities for that. |
486de14eb394
url: add distribution and version to user-agent request header (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29455
diff
changeset
|
489 # |
486de14eb394
url: add distribution and version to user-agent request header (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29455
diff
changeset
|
490 # "mercurial/proto-1.0" was the original user agent string and |
486de14eb394
url: add distribution and version to user-agent request header (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29455
diff
changeset
|
491 # exists for backwards compatibility reasons. |
486de14eb394
url: add distribution and version to user-agent request header (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29455
diff
changeset
|
492 # |
486de14eb394
url: add distribution and version to user-agent request header (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29455
diff
changeset
|
493 # The "(Mercurial %s)" string contains the distribution |
486de14eb394
url: add distribution and version to user-agent request header (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29455
diff
changeset
|
494 # name and version. Other client implementations should choose their |
486de14eb394
url: add distribution and version to user-agent request header (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29455
diff
changeset
|
495 # own distribution name. Since servers should not be using the user |
486de14eb394
url: add distribution and version to user-agent request header (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29455
diff
changeset
|
496 # agent string for anything, clients should be able to define whatever |
486de14eb394
url: add distribution and version to user-agent request header (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29455
diff
changeset
|
497 # user agent they deem appropriate. |
486de14eb394
url: add distribution and version to user-agent request header (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29455
diff
changeset
|
498 agent = 'mercurial/proto-1.0 (Mercurial %s)' % util.version() |
34429
0ee9cf8d054a
url: use native strings for header values
Augie Fackler <augie@google.com>
parents:
33499
diff
changeset
|
499 opener.addheaders = [(r'User-agent', pycompat.sysstr(agent))] |
30763
a520aefb96f1
httppeer: advertise and support application/mercurial-0.2
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30667
diff
changeset
|
500 |
a520aefb96f1
httppeer: advertise and support application/mercurial-0.2
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30667
diff
changeset
|
501 # This header should only be needed by wire protocol requests. But it has |
a520aefb96f1
httppeer: advertise and support application/mercurial-0.2
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30667
diff
changeset
|
502 # been sent on all requests since forever. We keep sending it for backwards |
a520aefb96f1
httppeer: advertise and support application/mercurial-0.2
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30667
diff
changeset
|
503 # compatibility reasons. Modern versions of the wire protocol use |
a520aefb96f1
httppeer: advertise and support application/mercurial-0.2
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30667
diff
changeset
|
504 # X-HgProto-<N> for advertising client support. |
34429
0ee9cf8d054a
url: use native strings for header values
Augie Fackler <augie@google.com>
parents:
33499
diff
changeset
|
505 opener.addheaders.append((r'Accept', r'application/mercurial-0.1')) |
7270
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
506 return opener |
2db33c1a5654
factor out the url handling from httprepo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
507 |
13818
bf6156bab41b
url: use url.url in url.open()
Brodie Rao <brodie@bitheap.org>
parents:
13817
diff
changeset
|
508 def open(ui, url_, data=None): |
14076
924c82157d46
url: move URL parsing functions into util to improve startup time
Brodie Rao <brodie@bitheap.org>
parents:
14071
diff
changeset
|
509 u = util.url(url_) |
13818
bf6156bab41b
url: use url.url in url.open()
Brodie Rao <brodie@bitheap.org>
parents:
13817
diff
changeset
|
510 if u.scheme: |
bf6156bab41b
url: use url.url in url.open()
Brodie Rao <brodie@bitheap.org>
parents:
13817
diff
changeset
|
511 u.scheme = u.scheme.lower() |
bf6156bab41b
url: use url.url in url.open()
Brodie Rao <brodie@bitheap.org>
parents:
13817
diff
changeset
|
512 url_, authinfo = u.authinfo() |
bf6156bab41b
url: use url.url in url.open()
Brodie Rao <brodie@bitheap.org>
parents:
13817
diff
changeset
|
513 else: |
bf6156bab41b
url: use url.url in url.open()
Brodie Rao <brodie@bitheap.org>
parents:
13817
diff
changeset
|
514 path = util.normpath(os.path.abspath(url_)) |
28883
032c4c2f802a
pycompat: switch to util.urlreq/util.urlerr for py3 compat
timeless <timeless@mozdev.org>
parents:
28861
diff
changeset
|
515 url_ = 'file://' + urlreq.pathname2url(path) |
7284
ac81ffac0f35
url: fix file:// URL handling
Patrick Mezard <pmezard@gmail.com>
parents:
7270
diff
changeset
|
516 authinfo = None |
13818
bf6156bab41b
url: use url.url in url.open()
Brodie Rao <brodie@bitheap.org>
parents:
13817
diff
changeset
|
517 return opener(ui, authinfo).open(url_, data) |