Commit Graph

115 Commits

Author SHA1 Message Date
timeless
803e780536 url: drop support for python2.5 2015-10-15 17:21:08 -04:00
Pierre-Yves David
30913031d4 error: get Abort from 'error' instead of 'util'
The home of 'Abort' is 'error' not 'util' however, a lot of code seems to be
confused about that and gives all the credit to 'util' instead of the
hardworking 'error'. In a spirit of equity, we break the cycle of injustice and
give back to 'error' the respect it deserves. And screw that 'util' poser.

For great justice.
2015-10-08 12:55:45 -07:00
Gregory Szorc
249d8b2408 url: use absolute_import 2015-08-08 20:14:50 -07:00
Matt Mackall
3e2882b908 http2: mark experimental and developer options 2015-06-25 17:48:43 -05:00
Gregory Szorc
5380dea2a7 global: mass rewrite to use modern exception syntax
Python 2.6 introduced the "except type as instance" syntax, replacing
the "except type, instance" syntax that came before. Python 3 dropped
support for the latter syntax. Since we no longer support Python 2.4 or
2.5, we have no need to continue supporting the "except type, instance".

This patch mass rewrites the exception syntax to be Python 2.6+ and
Python 3 compatible.

This patch was produced by running `2to3 -f except -w -n .`.
2015-06-23 22:20:08 -07:00
Yuya Nishihara
d3afea0260 ssl: rename ssl_wrap_socket() to conform to our naming convention
I've removed ssl_ prefix because the module name contains ssl.
2015-06-05 21:25:28 +09:00
Yuya Nishihara
1bf0df3c69 ssl: prompt passphrase of client key file via ui.getpass() (issue4648)
This is necessary to communicate with third-party tools through command-server
channel. This requires SSLContext backported to Python 2.7.9+.

It doesn't look nice to pass ui by sslkwargs, but I think it is the only way
to do without touching various client codes including httpclient (aka http2).
ui is mandatory if certfile is specified, so it has no default value.

BTW, test-check-commit-hg.t complains that ssl_wrap_socket() has foo_bar
naming. Should I bulk-replace it to sslwrapsocket() ?
2015-05-07 17:15:24 +09:00
Yuya Nishihara
a7ad5964ea https: do not inherit httplib.HTTPSConnection that creates unused SSLContext
HTTPSConnection of Python 2.7.9 creates SSLContext in __init__, which involves
a password prompt for decrypting the private key. This means the password was
asked twice, one for unused SSLContext, and next for our ssl function.

Because our httpsconnection replaces connect() method at all, we can simply
drop httplib.HTTPSConnection. Instead, class and instance attributes are copied
from it.

HTTPSConnection of Python 2.7.8 and 2.6.9 seem to have no such problem.

https://hg.python.org/cpython/file/v2.7.9/Lib/httplib.py#l1183
2015-05-07 17:02:20 +09:00
Pierre-Yves David
a55b3e4405 url: drop awful hack around bug in Python 2.4
It's all just a memory now.
2015-05-18 16:51:02 -05:00
Alex Orange
04223e707f https: support tls sni (server name indication) for https urls (issue3090)
SNI is a common way of sharing servers across multiple domains using separate
SSL certificates. As of Python 2.7.9 SSLContext has been backported from
Python 3. This patch changes sslutil's ssl_wrap_socket to use SSLContext and
take a server hostname as and argument. It also changes the url module to make
use of this argument.

The new code for 2.7.9 achieves it's task by attempting to get the SSLContext
object from the ssl module. If this fails the try/except goes back to what was
there before with the exception that the ssl_wrap_socket functions take a
server_hostname argument that doesn't get used. Assuming the SSLContext
exists, the arguments to wrap_socket at the module level are emulated on the
SSLContext. The SSLContext is initialized with the specified ssl_version. If
certfile is not None load_cert_chain is called with certfile and keyfile.
keyfile being None is not a problem, load_cert_chain will simply expect the
private key to be in the certificate file. verify_mode is set to cert_reqs. If
ca_certs is not None load_verify_locations is called with ca_certs as the
cafile. Finally the wrap_socket method of the SSLContext is called with the
socket and server hostname.

Finally, this fails test-check-commit-hg.t because the "new" function
ssl_wrap_socket has underscores in its names and underscores in its arguments.
All the underscore identifiers are taken from the other functions and as such
can't be changed to match naming conventions.
2015-01-12 18:01:20 -07:00
Yuya Nishihara
1cdd3cec9a proxy: remove unneeded _set_hostport for compatibility with Python 2.7.7rc1
With Python 2.7.7rc1, "hg pull" through HTTP CONNECT tunnel fails due to the
removal of _set_hostport [1].

      ...
      File "mercurial/url.py", line 372, in https_open
        return self.do_open(self._makeconnection, req)
      ...
      File "mercurial/url.py", line 342, in connect
        _generic_proxytunnel(self)
      File "mercurial/url.py", line 228, in _generic_proxytunnel
        self._set_hostport(self.host, self.port)
    AttributeError: httpsconnection instance has no attribute '_set_hostport'

self._set_hostport(self.host, self.port) should be noop and can be removed
because:

 - _set_hostport() [2] was the function to parse "host:port" string and
   set them to self.host and self.port,
 - and (self.host, self.port) pair should be valid since connect() is called
   prior to _generic_proxytunnel().

 [1]: http://hg.python.org/cpython/rev/568041fd8090
 [2]: http://hg.python.org/cpython/file/3a1db0d2747e/Lib/httplib.py#l721
2014-05-22 22:05:26 +09:00
Stéphane Klein
f029558dda http: reuse authentication info after the first failed request (issue3567)
[This was applied in df58533adb15 but backed out again in 8127f169caa4 because
of Python 2.4 issues. This edition and test-http.t works with Python 2.4.]

Context: mercurial access to repository server with http access, and this
server is protected by basic auth.

Before patch:

* mercurial try an anonymous access to server, server return 401 response and
  mercurial resend request with login / password information

After patch:

* mercurial try an anonymous access to server, server return
  401 response. For all next requests, mercurial keep in memory this
  information (this server need basic auth information).

This patch reduce the number of http access against mercurial server.

Example, before patch:

10.10.168.170 - - [25/Oct/2013:15:44:51 +0200] "GET /hg/testagt?cmd=capabilities
HTTP/1.1" 401 260 "-" "mercurial/proto-1.0"
10.10.168.170 - - [25/Oct/2013:15:44:52 +0200] "GET /hg/testagt?cmd=capabilities
HTTP/1.1" 200 147 "-" "mercurial/proto-1.0"
10.10.168.170 - - [25/Oct/2013:15:45:00 +0200] "GET /hg/testagt?cmd=capabilities
HTTP/1.1" 401 260 "-" "mercurial/proto-1.0"
10.10.168.170 - - [25/Oct/2013:15:45:01 +0200] "GET /hg/testagt?cmd=capabilities
HTTP/1.1" 200 147 "-" "mercurial/proto-1.0"
10.10.168.170 - - [25/Oct/2013:15:45:03 +0200] "GET /hg/testagt?cmd=batch
HTTP/1.1" 401 260 "-" "mercurial/proto-1.0"
10.10.168.170 - - [25/Oct/2013:15:45:04 +0200] "GET /hg/testagt?cmd=batch
HTTP/1.1" 200 42 "-" "mercurial/proto-1.0"
10.10.168.170 - - [25/Oct/2013:15:45:06 +0200] "GET /hg/testagt?cmd=getbundle
HTTP/1.1" 401 260 "-" "mercurial/proto-1.0"
10.10.168.170 - - [25/Oct/2013:15:45:07 +0200] "GET /hg/testagt?cmd=getbundle
HTTP/1.1" 200 61184 "-" "mercurial/proto-1.0"
10.10.168.170 - - [25/Oct/2013:15:45:09 +0200] "GET /hg/testagt?cmd=listkeys
HTTP/1.1" 401 260 "-" "mercurial/proto-1.0"
10.10.168.170 - - [25/Oct/2013:15:45:10 +0200] "GET /hg/testagt?cmd=listkeys
HTTP/1.1" 200 15 "-" "mercurial/proto-1.0"
10.10.168.170 - - [25/Oct/2013:15:45:12 +0200] "GET /hg/testagt?cmd=listkeys
HTTP/1.1" 401 260 "-" "mercurial/proto-1.0"
10.10.168.170 - - [25/Oct/2013:15:45:12 +0200] "GET /hg/testagt?cmd=listkeys
HTTP/1.1" 200 - "-" "mercurial/proto-1.0"

Example after patch:

10.10.168.170 - - [28/Oct/2013:11:49:14 +0100] "GET /hg/testagt?cmd=capabilities
HTTP/1.1" 401 260 "-" "mercurial/proto-1.0"
10.10.168.170 - - [28/Oct/2013:11:49:15 +0100] "GET /hg/testagt?cmd=capabilities
HTTP/1.1" 200 147 "-" "mercurial/proto-1.0"
10.10.168.170 - - [28/Oct/2013:11:49:17 +0100] "GET /hg/testagt?cmd=batch
HTTP/1.1" 200 42 "-" "mercurial/proto-1.0"
10.10.168.170 - - [28/Oct/2013:11:49:19 +0100] "GET /hg/testagt?cmd=getbundle
HTTP/1.1" 200 61184 "-" "mercurial/proto-1.0"
10.10.168.170 - - [28/Oct/2013:11:49:22 +0100] "GET /hg/testagt?cmd=listkeys
HTTP/1.1" 200 15 "-" "mercurial/proto-1.0"
10.10.168.170 - - [28/Oct/2013:11:49:24 +0100] "GET /hg/testagt?cmd=listkeys
HTTP/1.1" 200 - "-" "mercurial/proto-1.0"

In this last example, you can see only one 401 response.
2013-12-20 14:56:05 +01:00
Lucas Moscovicz
178ffcb15d url: added authuri when login information is requested (issue3209)
When users are using a revset they can get multiple password prompts.
This prompts have no extra information about which password is being requested
so I added the authuri to the prompt to make it recognizable.

As in:
$ hg log -r "outgoing('https://bitbucket.org/mg/test') -
outgoing('https://bitbucket.org/nesneros/test')"
http authorization required
realm: Bitbucket.org HTTP
user: interrupted!

I changed it to describe the url when prompting for password.
As in:
$ hg log -r "outgoing('https://bitbucket.org/mg/test') -
outgoing('https://bitbucket.org/nesneros/test')"
http authorization required for https://bitbucket.org/mg/test
realm: Bitbucket.org HTTP
user: interrupted!
2014-01-15 16:46:20 -08:00
Matt Mackall
8384e61b90 proxy: allow wildcards in the no proxy list (issue1821) 2013-08-03 13:23:48 -05:00
Augie Fackler
fc13516f60 url: clean up use of two-argument raise
This makes any attempt to port to Python 3 harder, and the new syntax
is supported in 2.4 already.
2013-01-01 12:50:46 -06:00
Mads Kiilerich
5e3dc3e383 avoid using abbreviations that look like spelling errors 2012-08-27 23:14:27 +02:00
Mads Kiilerich
2f4504e446 fix trivial spelling errors 2012-08-15 22:38:42 +02:00
Brodie Rao
d6a6abf2b0 cleanup: eradicate long lines 2012-05-12 15:54:54 +02:00
Matt Mackall
757bb24a98 merge with stable 2011-09-10 17:56:42 -05:00
Renato Cunha
fca28dd4ac url: Remove the proxy env variables only when needed (issue2451)
This is an attempt to fix issue 2451 and its duplicates (2599 and 2949, AFAIK).
Its main idea is that it is only necessary to clean the proxy environment
variables *when* http_proxy is set in the config file (since it takes
precedence over the environment variables). Otherwise, hg shouldn't bother with
them, since they will most likely be used to reach the server.
2011-09-08 20:40:24 -03:00
Patrick Mezard
107949ab73 http: pass user to readauthforuri() (fix f7ae45a69fcd)
urllib2 never handles URIs with credentials, we have to extract them and store
them in the password manager before handing the stripped URI. Half of the
changes deducing the username from the URI in f7ae45a69fcd were incorrect.
Instead, we retrieve the username from the password manager before passing to
readauthforuri().

test-hgweb-auth.py was passing because the test itself was flawed: it was
passing URIs with credentials to find_password(), which never happens.
2011-08-05 21:05:41 +02:00
Patrick Mezard
8028e79c02 hgweb: do not ignore [auth] if url has a username (issue2822)
The [auth] section was ignored when handling URLs like:

  http://user@example.com/foo

Instead, we look in [auth] for an entry matching the URL and supplied user
name. Entries without username can match URL with a username. Prefix length
ties are resolved in favor of entries matching the username. With:

  foo.prefix = http://example.org
  foo.username = user
  foo.password = password
  bar.prefix = http://example.org/bar

and the input URL:

  http://user@example.org/bar

the 'bar' entry will be selected because of prefix length, therefore prompting
for a password. This behaviour ensure that entries selection is consistent when
looking for credentials or for certificates, and that certificates can be
picked even if their entries do no define usernames while the URL does.
Additionally, entries without a username matched against a username are
returned as if they did have requested username set to avoid prompting again
for a username if the password is not set.

v2: reparse the URL in readauthforuri() to handle HTTP and HTTPS similarly.
v3: allow unset usernames to match URL usernames to pick certificates. Resolve
prefix length ties in favor of entries with usernames.
2011-08-01 23:58:50 +02:00
Matt Mackall
96e41d94f5 merge with stable 2011-08-05 16:07:51 -05:00
Matt Mackall
bd0261e46e merge with stable 2011-08-01 18:10:05 -05:00
Augie Fackler
35b86083cf url: replace uses of hasattr with safehasattr or getattr 2011-07-25 15:55:51 -05:00
Augie Fackler
33ebd50b83 url: use new http support if requested by the user
The new http library is wired in via an extra module
(httpconnection.py), as it requires similar but different plumbing to
connect the library to Mercurial's internals and urllib2. Eventualy we
should be able to remove all of keepalive.py and its associated tangle
in url.py and replace it all with the code in httpconnection.py.

To use the new library, set 'ui.usehttp2' to true. The underlying http
library uses the logging module liberally, so if things break you can
use 'ui.http2debuglevel' to set the log level to INFO or DEBUG to get
that logging information (for example, ui.http2debuglevel=info.)
2011-05-06 10:22:08 -05:00
Augie Fackler
71eea02c91 sslutil: extracted ssl methods from httpsconnection in url.py
This makes it easier to share ssl cert validation with other http
implementations.
2011-05-04 22:08:55 -05:00
Brodie Rao
b7f0d2a103 url: move URL parsing functions into util to improve startup time
The introduction of the new URL parsing code has created a startup
time regression. This is mainly due to the use of url.hasscheme() in
the ui class. It ends up importing many libraries that the url module
requires.

This fix helps marginally, but if we can get rid of the urllib import
in the URL parser all together, startup time will go back to normal.

perfstartup time before the URL refactoring (707e4b1e8064):

! wall 0.050692 comb 0.000000 user 0.000000 sys 0.000000 (best of 100)

current startup time (9ad1dce9e7f4):

! wall 0.070685 comb 0.000000 user 0.000000 sys 0.000000 (best of 100)

after this change:

! wall 0.064667 comb 0.000000 user 0.000000 sys 0.000000 (best of 100)
2011-04-30 09:43:20 -07:00
Brodie Rao
56a02820c3 url: remove unused/obsolete functions 2011-04-30 07:00:13 -07:00
Alexander Solovyov
0eb3836642 remove unused imports and variables 2011-04-30 13:59:14 +02:00
Brodie Rao
3bbcdd41bc url: be stricter about detecting schemes
While the URL parser is very forgiving about what characters are
allowed in each component, it's useful to be strict about the scheme
so we don't accidentally interpret local paths with colons as URLs.

This restricts schemes to containing alphanumeric characters, dashes,
pluses, and dots (as specified in RFC 2396).
2011-03-31 17:37:33 -07:00
Matt Mackall
d0ca936e58 url: nuke some newly-introduced underbars in identifiers 2011-03-31 10:43:53 -05:00
Brodie Rao
3a43fa887e url: refactor util.drop_scheme() and hg.localpath() into url.localpath()
This replaces util.drop_scheme() with url.localpath(), using url.url for
parsing instead of doing it on its own. The function is moved from
util to url to avoid an import cycle.

hg.localpath() is removed in favor of using url.localpath(). This
provides more consistent behavior between "hg clone" and other
commands.

To preserve backwards compatibility, URLs like bundle://../foo still
refer to ../foo, not /foo.

If a URL contains a scheme, percent-encoded entities are decoded. When
there's no scheme, all characters are left untouched.

Comparison of old and new behaviors:

URL                      drop_scheme()   hg.localpath()    url.localpath()
===                      =============   ==============    ===============
file://foo/foo           /foo            foo/foo           /foo
file://localhost:80/foo  /foo            localhost:80/foo  /foo
file://localhost:/foo    /foo            localhost:/foo    /foo
file://localhost/foo     /foo            /foo              /foo
file:///foo              /foo            /foo              /foo
file://foo               (empty string)  foo               /
file:/foo                /foo            /foo              /foo
file:foo                 foo             foo               foo
file:foo%23bar           foo%23bar       foo%23bar         foo#bar
foo%23bar                foo%23bar       foo%23bar         foo%23bar
/foo                     /foo            /foo              /foo

Windows-related paths on Windows:

URL                      drop_scheme()   hg.localpath()    url.localpath()
===                      =============   ==============    ===============
file:///C:/foo           C:/C:/foo       /C:/foo           C:/foo
file:///D:/foo           C:/D:/foo       /D:/foo           D:/foo
file://C:/foo            C:/foo          C:/foo            C:/foo
file://D:/foo            C:/foo          D:/foo            D:/foo
file:////foo/bar         //foo/bar       //foo/bar         //foo/bar
//foo/bar                //foo/bar       //foo/bar         //foo/bar
\\foo\bar                //foo/bar       //foo/bar         \\foo\bar

Windows-related paths on other platforms:

file:///C:/foo           C:/C:/foo       /C:/foo           C:/foo
file:///D:/foo           C:/D:/foo       /D:/foo           D:/foo
file://C:/foo            C:/foo          C:/foo            C:/foo
file://D:/foo            C:/foo          D:/foo            D:/foo
file:////foo/bar         //foo/bar       //foo/bar         //foo/bar
//foo/bar                //foo/bar       //foo/bar         //foo/bar
\\foo\bar                //foo/bar       //foo/bar         \\foo\bar

For more information about file:// URL handling, see:
http://www-archive.mozilla.org/quality/networking/testing/filetests.html

Related issues:

- issue1153: File URIs aren't handled correctly in windows

  This patch should preserve the fix implemented in
  5c92d05b064e. However, it goes a step further and "promotes"
  Windows-style drive letters from being interpreted as host names to
  being part of the path.

- issue2154: Cannot escape '#' in Mercurial URLs (#1172 in THG)

  The fragment is still interpreted as a revision or a branch, even in
  paths to bundles. However, when file: is used, percent-encoded
  entities are decoded, so file:test%23bundle.hg can refer to
  test#bundle.hg ond isk.
2011-03-30 20:03:05 -07:00
Brodie Rao
82ebe71a03 url: use url.url in proxyhandler 2011-03-30 20:01:44 -07:00
Brodie Rao
de32ed5320 httprepo/sshrepo: use url.url
Like the previous patch to getauthinfo(), this also makes
username/password parsing more forgiving for SSH URLs.

This also opens up the possibility of allowing non-numeric ports,
since the URL parser has no problem handling them.

Related issues:

- issue851: @ in password in http url
- issue2055: nonnumeric port bug with https protocol
2011-03-30 20:01:35 -07:00
Brodie Rao
c01046e0d6 url: use url.url in url.open() 2011-03-30 20:01:34 -07:00
Brodie Rao
80fd2713db url: abort on file:// URLs with non-localhost hosts 2011-03-30 20:01:31 -07:00
Brodie Rao
7db4593199 url: special case bundle URL parsing to preserve backwards compatibility
This allows bundle://../foo to continue to refer to the relative path
../foo (bundle URLs do not take host names).
2011-03-30 20:00:24 -07:00
Brodie Rao
40c99bbacb url: add trailing slashes to URLs with hostnames that don't have one
This works around a potential issue in Python 2.4 where cloning a repo
with a URL like http://foo:8080 would cause urllib2 to query on
http://foo:8080?cmd=capabilities instead of
http://foo:8080/?cmd=capabilities.

In the past, this issue has been masked by the fact that
url.getauthinfo() added a trailing slash when it was missing.
2011-03-30 20:00:23 -07:00
Brodie Rao
193402d9df url: move drive letter checking into has_drive_letter() for extensions
This will let the schemes extension override drive letter detection to
allow single letter schemes.
2011-03-30 19:50:56 -07:00
Matt Mackall
712f3e23d9 url: deal with drive letters 2011-03-30 13:34:39 -05:00
Brodie Rao
a4072d0def url: use url.url in hidepassword() and removeauth() 2011-03-25 22:59:09 -07:00
Brodie Rao
186bc90ec4 url: provide url object
This adds a url object that re-implements urlsplit() and
unsplit(). The implementation splits out usernames, passwords, and
ports.

The implementation is based on the behavior specified by RFC
2396[1]. However, it is much more forgiving than the RFC's
specification; it places no specific restrictions on what characters
are allowed in each segment of the URL other than what is necessary to
split the URL into its constituent parts.

[1]: http://www.ietf.org/rfc/rfc2396.txt
2011-03-25 22:58:56 -07:00
timeless
49d2d3233b cacert: improve error report when web.cacert file does not exist 2011-03-06 10:27:07 -06:00
Mads Kiilerich
1edc9de542 url: merge BetterHTTPS with httpsconnection to get some proxy https validation 2011-02-16 04:36:36 +01:00
Mads Kiilerich
c7b145f8d2 url: always create BetterHTTPS connections the same way 2011-02-16 04:28:17 +01:00
Mads Kiilerich
ed367d71cf url: refactor BetterHTTPS.connect 2011-02-16 04:28:17 +01:00
Mads Kiilerich
6c8a377242 url: refactor _gen_sendfile 2011-02-16 04:28:17 +01:00
Mads Kiilerich
caabaf5584 url: remove test for self.ui in BetterHTTPS
We use self.ui unconditionally anyway so we would have noticed if it in some
cases wasn't set.
2011-02-16 04:28:17 +01:00
Steve Borho
712b02dd36 url: return the matched authentication group name from readauthforuri()
Internally, the group name is only used in debug statements, but readauthforuri
can be also used externally to determine which group will be matched for a given
URL.
2011-02-13 12:19:58 -06:00