Commit Graph

22 Commits

Author SHA1 Message Date
Gregory Szorc
b4f1111abe tests: store ETag when using --headeronly
Previously, --headeronly would prevent --twice from working
because the ETag wasn't stored when --headeronly was used.
This feels like a bug. That feeling is reaffirmed by the fact
that this change doesn't regress any tests.
2017-04-01 00:21:52 -07:00
Gregory Szorc
f71c86b7e9 protocol: send application/mercurial-0.2 responses to capable clients
With this commit, the HTTP transport now parses the X-HgProto-<N>
header to determine what media type and compression engine to use for
responses. So far, we only compress responses that are already being
compressed with zlib today (stream response types to specific
commands). We can expand things to cover additional response types
later.

The practical side-effect of this commit is that non-zlib compression
engines will be used if both ends support them. This means if both
ends have zstd support, zstd - not zlib - will be used to compress
data!

When cloning the mozilla-unified repository between a local HTTP
server and client, the benefits of non-zlib compression are quite
noticeable:

  engine     server CPU (s)   client CPU (s)    bundle size
zlib (l=6)      174.1            283.2         1,148,547,026
zstd (l=1)       99.2            267.3         1,127,513,841
zstd (l=3)      103.1            266.9         1,018,861,363
zstd (l=7)      128.3            269.7           919,190,278
zstd (l=10)     162.0               -            894,547,179
none             95.3            277.2         4,097,566,064

The default zstd compression level is 3. So if you deploy zstd
capable Mercurial to your clients and servers and CPU time on
your server is dominated by "getbundle" requests (clients cloning
and pulling) - and my experience at Mozilla tells me this is often
the case - this commit could drastically reduce your server-side
CPU usage *and* save on bandwidth costs!

Another benefit of this change is that server operators can install
*any* compression engine. While it isn't enabled by default, the
"none" compression engine can now be used to disable wire protocol
compression completely. Previously, commands like "getbundle" always
zlib compressed output, adding considerable overhead to generating
responses. If you are on a high speed network and your server is under
high load, it might be advantageous to trade bandwidth for CPU.
Although, zstd at level 1 doesn't use that much CPU, so I'm not
convinced that disabling compression wholesale is worthwhile. And, my
data seems to indicate a slow down on the client without compression.
I suspect this is due to a lack of buffering resulting in an increase
in socket read() calls and/or the fact we're transferring an extra 3 GB
of data (parsing HTTP chunked transfer and processing extra TCP packets
can add up). This is definitely worth investigating and optimizing. But
since the "none" compressor isn't enabled by default, I'm inclined to
punt on this issue.

This commit introduces tons of tests. Some of these should arguably
have been implemented on previous commits. But it was difficult to
test without the server functionality in place.
2016-12-24 15:29:32 -07:00
Pulkit Goyal
af9d7f66d0 py3: conditionalize httplib import
The httplib library is renamed to http.client in python 3. So the
import is conditionalized and a test is added in check-code to warn
to use util.httplib
2016-06-28 16:01:53 +05:30
Robert Stanca
f151e77de8 py3: use print_function in get-with-headers.py 2016-04-02 18:12:33 +03:00
Gregory Szorc
df8d1f17a7 tests: use absolute_import in /get-with-headers.py
While I was here, I removed condition code for failure to import json.
This code was necessary to support Python < 2.6, which didn't include
the json module.
2015-12-06 22:25:41 -08:00
Pierre-Yves David
5802440b41 tests: just use 'response.reason'
There is no reason to not have simple code now that Python 2.4 is dead.
2015-05-18 16:52:28 -05:00
Gregory Szorc
3a983954a1 get-with-headers: support parsing and pretty printing JSON
Upcoming patches will add support for JSON output from hgweb.

Because JSON output from the templater is hard to read and because it
is easy to introduce malformed JSON, we introduce a JSON processing
mode to get-with-headers.py that will parse and pretty print JSON
from HTTP responses. This will make tests easier to read and write
and it will ensure hgweb is emitting well-formed JSON.
2015-03-30 20:56:54 -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
Javi Merino
e80cfee2b0 get-with-headers: don't block indefinitely if the server had an internal error
If the server had an internal error and returned 500, there's nothing
to read, so "response.read()" blocks indefinitely.  Only output the
response if there's really a response.
2013-10-02 22:46:32 +01:00
Pierre-Yves David
b7643c351c get-with-headers: add a --headeronly switch
In some case we do not care about the actual rendering.
2013-01-16 14:26:19 +01:00
Mads Kiilerich
ab59efec7d tests: make test-hgweb.t output stable
Instability introduced in combination of 08b18bf1e0f3 and 072a5d64ecaa.
2013-01-16 02:01:11 +01: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
1fda0b1af1 tests: prepare get-with-headers.py for MSYS
get-with-headers.py took the http GET parameter as a command line parameter
that had to start with '/'. MSYS on windows will mangle such paths.

Instead of applying a workaround everywhere (such as an extra '/') we let
get-with-headers.py add the mandatory '/'. That is consistent with the
url path handling in the Mercurial url class.

A few tests sent 'GET ?cmd=...' which is invalid. They will now send 'GET
/?cmd=...'.

This will not enable any tests for being run on windows - only remove one
reason they were disabled.
2012-06-21 03:05:02 +02:00
Dirkjan Ochtman
5ec1a29d90 tests: fix incompatibility with python-2.4 in test-hgweb
Thanks to lcantey for catching it.
2010-09-11 10:57:35 +02:00
Dirkjan Ochtman
ea62f97a35 tests: extend get-with-headers to support cache testing 2010-09-08 15:11:35 +02:00
Nicolas Dumazet
7f1a963829 pylint, pyflakes: remove unused or duplicate imports 2010-04-14 17:58:10 +09:00
Dirkjan Ochtman
c08c589861 templater: readable dates older than 24 months revert to ISO8601 (issue1006) 2009-11-05 15:19:54 +01:00
Martin Geisler
9aedf5dabd tests: fix doc string in get-with-headers.py 2009-05-17 01:24:45 +02:00
Gilles Moris
9b7deb4420 test-hgweb-*: replace "XX years ago" by a fixed string in get-with-headers.py
Note that other sed replacement commands are also filtering get-with-headers.py,
but they seem to be more test specific, hence not handled here.
2008-12-25 17:49:08 +01:00
Patrick Mezard
4813e1621f get-with-headers: fix stream modes under Windows 2008-09-28 20:40:38 +02:00
Bryan O'Sullivan
e19dabc11f hgweb: return meaningful HTTP status codes instead of nonsense 2007-11-28 08:38:42 -08:00
Eric Hopper
6ae7c3c284 Add a test for getting raw files via the web UI. 2006-06-29 16:44:23 -07:00