Commit Graph

125 Commits

Author SHA1 Message Date
Augie Fackler
22c84078c4 hgweb: more "http headers are native strs" cleanup
Differential Revision: https://phab.mercurial-scm.org/D1108
2017-10-15 00:38:33 -04:00
Augie Fackler
dfaf4b98bc hgweb: set sent_headers attr as early as practical
While doing Python 3 porting work, I've seen exceptions happen in
parts of hgweb we normally assume are robust. It won't hurt anything
to set this attribute significantly earlier, so let's do so and save
confusing during the porting process.

Differential Revision: https://phab.mercurial-scm.org/D1085
2017-10-14 15:37:33 -04:00
Augie Fackler
caec472139 hgweb: detect Python 3-era libraries and use modern attribute names
Differential Revision: https://phab.mercurial-scm.org/D1084
2017-10-05 14:53:52 -04:00
Augie Fackler
1f7e395752 server: indent block that's about to get conditionalized
Differential Revision: https://phab.mercurial-scm.org/D1083
2017-10-14 15:53:36 -04:00
Augie Fackler
bc69639184 hgweb: fix logging to use native strings as appropriate
Kind of a tangled mess, but now logging works in both Python 2 and 3.

# no-check-commit because of the interface required by Python's HTTP
server code.

Differential Revision: https://phab.mercurial-scm.org/D1080
2017-10-14 15:43:06 -04:00
Augie Fackler
58adac28f6 hgweb: more native string treatment in query string parsing
Differential Revision: https://phab.mercurial-scm.org/D1076
2017-10-05 14:29:51 -04:00
Jun Wu
2ae56b14de codemod: use pycompat.iswindows
This is done by:

  sed -i "s/pycompat\.osname == 'nt'/pycompat.iswindows/" **/*.py
  sed -i "s/pycompat\.osname != 'nt'/not pycompat.iswindows/" **/*.py
  sed -i 's/pycompat.osname == "nt"/pycompat.iswindows/' **/*.py

Differential Revision: https://phab.mercurial-scm.org/D1034
2017-10-12 23:30:46 -07:00
Augie Fackler
02378a67e1 hgweb: when constructing or adding to a wsgi environ dict, use native strs
That's what's required of us to work with the WSGI API on Python 3.

Differential Revision: https://phab.mercurial-scm.org/D967
2017-10-05 14:22:02 -04:00
Augie Fackler
3519ee0e52 hgweb: remove superfluous pass statements 2017-09-30 07:44:20 -04:00
Boris Feld
dd08c3c7c0 configitems: register the 'web.prefix' config 2017-06-30 03:45:49 +02:00
Boris Feld
88f87cb825 configitems: register the 'web.port' config 2017-06-30 03:45:48 +02:00
Boris Feld
67229c919a configitems: register the 'web.errorlog' config 2017-06-30 03:45:45 +02:00
Boris Feld
9ac692bc8c configitems: register the 'web.address' config 2017-06-30 03:45:32 +02:00
Boris Feld
b22253c4ad configitems: register the 'web.accesslog' config 2017-06-30 03:45:31 +02:00
Pulkit Goyal
4780c32e4c py3: replace os.name with pycompat.osname (part 1 of 2)
os.name returns unicodes on py3 and we have pycompat.osname which returns
bytes. This series of 2 patches will change every ocurrence of os.name with
pycompat.osname.
2016-12-19 00:16:52 +05:30
Yuya Nishihara
2d4abff2d9 hgweb: make log streams compatible with command server
Even though it would be useless to start a web server by a command server,
it should be doable in principle. Also, we can't use sys.stdout/err directly
on Python 3 because they are unicode streams.
2014-06-28 13:13:32 +09:00
Martijn Pieters
de1f10a894 hgweb: fix the MRO in Python 3
object should appear at the end, otherwise it tries to pre-empt the other
new-style classes in the MRO, resulting in an unresolvable MRO in Py3. We still
need to include object because otherwise in 2.7 we end up with an old-style
class if threading is not supported, new-style if it is.
2016-10-08 19:11:19 +02:00
Pulkit Goyal
6b3bc52b40 py3: conditionalize BaseHTTPServer, SimpleHTTPServer and CGIHTTPServer import
The BaseHTTPServer, SimpleHTTPServer and CGIHTTPServer has been merged into
http.server in python 3. All of them has been merged as util.httpserver to use
in both python 2 and 3. This patch adds a regex to check-code to warn against
the use of BaseHTTPServer. Moreover this patch also includes updates to lower
part of test-check-py3-compat.t which used to remain unchanged.
2016-07-13 23:38:29 +05:30
Gregory Szorc
c023f774e6 hgweb: use sslutil.wrapserversocket()
This patch transitions the built-in HTTPS server to use sslutil for
creating the server socket.

As part of this transition, we implement developer-only config options
to control CA loading and whether to require client certificates. This
eliminates the need for the custom extension in test-https.t to define
these.

There is a slight change in behavior with regards to protocol
selection. Before, we would always use the TLS 1.0 constant to define
the protocol version. This would *only* use TLS 1.0. sslutil defaults
to TLS 1.0+. So this patch improves the security of `hg serve` out of
the box by allowing it to use TLS 1.1 and 1.2 (if available).
2016-07-12 23:12:03 -07:00
Gregory Szorc
6052136b07 hgweb: pass ui into preparehttpserver
Upcoming patches will need the built-in HTTPS server to be more
configurable.
2016-07-13 00:14:50 -07:00
Pulkit Goyal
38a359ce5c py3: conditionalize SocketServer import
The SocketServer is renamed to socketserver in python 3
2016-06-27 16:48:54 +05:30
timeless
109fcbc79e pycompat: switch to util.urlreq/util.urlerr for py3 compat 2016-04-06 23:22:12 +00:00
Yuya Nishihara
47690f822c hgweb: use absolute_import 2015-10-31 22:07:40 +09:00
Siddharth Agarwal
6b30464363 hgweb.server: drop support for Python 2.4 2015-10-24 16:23:42 -07: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
timeless@mozdev.org
096175f16e hgweb.server: fix _httprequesthandlerssl help text 2015-09-08 15:32:20 -04: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
Gregory Szorc
9ccf5570f8 hgweb: send proper HTTP response after uncaught exception
This patch fixes a bug where hgweb would send an incomplete HTTP
response.

If an uncaught exception is raised when hgweb is processing a request,
hgweb attempts to send a generic error response and log that exception.

The server defaults to chunked transfer coding. If an uncaught exception
occurred, it was sending the error response string / chunk properly.
However, RFC 7230 Section 4.1 mandates a 0 size last chunk be sent to
indicate end of the entity body. hgweb was failing to send this last
chunk. As a result, properly written HTTP clients would assume more data
was coming and they would likely time out waiting for another chunk to
arrive.

Mercurial's own test harness was paving over the improper HTTP behavior
by not attempting to read the response body if the status code was 500.
This incorrect workaround was added in faced8f5c2af and has been removed
with this patch.
2014-11-28 10:59:02 -08:00
Augie Fackler
0e58e63b9c hgweb: disable SSLv3 serving (BC)
Because of recent attacks[0] on SSLv3, let's just drop support entirely.

0: http://googleonlinesecurity.blogspot.com/2014/10/this-poodle-bites-exploiting-ssl-30.html
2014-10-21 17:09:37 -04:00
Yuya Nishihara
cdb5aade4f hgweb: make sure sys module is loaded prior to reload hack
If sys is still a demandmod, reload(sys) fails with "TypeError: reload()
argument must be module".
2014-02-19 21:16:43 +09:00
Matt Mackall
fd6c6f9614 hgweb: hack around mimetypes encoding thinko (issue4160)
A correct patch for this has existed in Python's BTS for 3 years
(http://bugs.python.org/issue9291), so waiting for it to be fixed
upstream is probably not a viable strategy. Instead, we add this
horrible hack to workaround the issue in existing copies of Python
2.4-2.7.
2014-02-05 17:23:35 -06:00
David Soria Parra
4e97756fe4 hgweb: log headers only if headers were successfully parsed
The headers attribute is not initialized in certain error situations
(e.g. http 400 bad request). Check for self.headers before we attempt
to access it.
2013-10-01 09:54:46 +02:00
Mads Kiilerich
5cabd60d62 serve: don't send any content headers with 304 responses
Fixes HTTP protocol violation introduced in e4a5f5db7028. 'hg serve' would show
a stacktrace when loading pages that not had been modified.

There was test coverage for this, but the wrong response headers wasn't shown
and thus not detected.
2013-01-15 20:54:57 +01:00
Mads Kiilerich
3cb021c3b0 serve: use chunked encoding in hgweb responses
'hg serve' used to close connections when sending a response with unknown
length ... such as a bundle or archive.

Now chunked encoding will be used for responses with unknown length, and the
connection do thus not have to be closed to indicate the end of the response.

Chunked encoding is only used if the length is unknown, if the connection
wouldn't be closed for other reasons, AND if it is a HTTP 1.1 request.

This will not benefit other users of hgweb ... but it can serve as an example
that it can be done.
2013-01-15 01:10:08 +01:00
Mads Kiilerich
df2c27e00a serve: remove connection close hack for Python 2.3
Introduced in 172ac22869f4 and no longer needed - BaseHTTPServer handles
connection closing just fine if we don't mess with its internals.
2013-01-15 01:10:08 +01:00
Mads Kiilerich
01096c5713 serve: send response headers even if response has no body
The headers would usually be sent anyway because the app did a number of writes
of empty strings.
2013-01-15 01:05:12 +01:00
Mads Kiilerich
e973af65d0 improve some comments and docstrings, fixing issues found when spell checking 2012-08-21 02:41:20 +02:00
Mads Kiilerich
2f4504e446 fix trivial spelling errors 2012-08-15 22:38:42 +02:00
Matt Mackall
944b7f7b5c pyflakes: clean up some import noise 2011-10-11 23:16:05 -05:00
Augie Fackler
5997cc6e9c hgweb: move remaining hasattr calls to safehasattr 2011-07-25 15:38:46 -05:00
Thomas Arendsen Hein
692a53d202 classes: fix class style problems found by 06e968819ac9
This makes test-wireprotocol.py work on Python 2.4
2011-06-29 15:00:00 +02:00
Steven Brown
c1075f3880 httprepo: long arguments support (issue2126)
Send the command arguments in the HTTP headers. The command is still part
of the URL. If the server does not have the 'httpheader' capability, the
client will send the command arguments in the URL as it did previously.

Web servers typically allow more data to be placed within the headers than
in the URL, so this approach will:
- Avoid HTTP errors due to using a URL that is too large.
- Allow Mercurial to implement a more efficient wire protocol.

An alternate approach is to send the arguments as part of the request body.
This approach has been rejected because it requires the use of POST
requests, so it would break any existing configuration that relies on the
request type for authentication or caching.

Extensibility:
- The header size is provided by the server, which makes it possible to
  introduce an hgrc setting for it.
- The client ignores the capability value after the first comma, which
  allows more information to be included in the future.
2011-05-01 01:04:37 +08:00
Augie Fackler
c986a6137a hgweb: add support for 100-continue as recommended by PEP 333. 2010-02-06 04:27:28 -06:00
Mads Kiilerich
c77a84761e serve: catch and log all Exceptions, not only StandardException
Other exceptions than StandardExceptions were left to the default error handler
which was muted when running in daemon mode.

Now all Exceptions are handled and logged to the log file.
2011-02-21 00:52:23 +01:00
Mads Kiilerich
edd19f159b hgweb: let HTTPS serve use more compatible and less secure encryption
PROTOCOL_SSLv3 on the server side doesn't work everywhere. Sometimes the client
reports "EOF occurred in violation of protocol" (for example on Mac and Solaris).

The more compatible PROTOCOL_SSLv23 is now used instead. It works but is less
"secure" for some OpenSSL versions as it can fall back to weak encryption.
2010-10-21 03:18:52 +02:00
Mads Kiilerich
affe4fdcad hgweb: use Pythons ssl module for HTTPS serve when using Python 2.6 or later
pyOpenSSL apparently doesn't work for Python 2.7 and isn't very actively
maintained.

The built-in ssl module seems like a long-term winner, so we now use that with
Python 2.6 and higher.
2010-10-20 20:19:34 +02:00
Mads Kiilerich
1edb529392 hgweb: refactor all pyOpenSSL references into one class 2010-10-20 20:19:32 +02:00
Mads Kiilerich
c627f511ce serve: fix https mode and add test
The https mode failed in super because BaseRequestHandler is an old-style
class.

This introduces the first test of https client/server functionality - and
"hghave ssl". The test is currently only run on Python 2.6.
2010-10-17 04:13:35 +02:00
Brodie Rao
d1905b7d87 mail/hgweb: support service names for ports (issue2350)
This adds util.getport(port) which tries to parse port as an int, and
failing that, looks it up using socket.getservbyname(). Thus, the
following will work:

    [smtp]
    port = submission

    [web]
    port = http

This does not apply to ports in URLs used in clone, pull, etc.
2010-08-28 12:31:07 -04:00
Nicolas Dumazet
7f1a963829 pylint, pyflakes: remove unused or duplicate imports 2010-04-14 17:58:10 +09:00