D1850: hgweb: when no agreement on compression can be found, fail for v2
joerg.sonnenberger (Joerg Sonnenberger)
phabricator at mercurial-scm.org
Fri Jan 12 08:04:58 UTC 2018
joerg.sonnenberger created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.
REVISION SUMMARY
When the client supports v2 responses, the fallback to the legacy
response is undesirable. If the zlib is acceptable for the client,
it should have said so in first place.
REPOSITORY
rHG Mercurial
REVISION DETAIL
https://phab.mercurial-scm.org/D1850
AFFECTED FILES
mercurial/hgweb/common.py
mercurial/hgweb/protocol.py
tests/test-http-protocol.t
CHANGE DETAILS
diff --git a/tests/test-http-protocol.t b/tests/test-http-protocol.t
--- a/tests/test-http-protocol.t
+++ b/tests/test-http-protocol.t
@@ -78,14 +78,15 @@
server: * (glob)
transfer-encoding: chunked
-Requesting a compression format that server doesn't support results will fall back to 0.1
+Server should fail when it can't agree with client on a compression format
$ get-with-headers.py --hgproto '0.2 comp=aa' --headeronly $LOCALIP:$HGPORT '?cmd=getbundle&heads=e93700bd72895c5addab234c56d4024b487a362f&common=0000000000000000000000000000000000000000' -
- 200 Script output follows
+ 406 No common compression format
+ content-length: 31
content-type: application/mercurial-0.1
date: * (glob)
server: * (glob)
- transfer-encoding: chunked
+ [1]
#if zstd
zstd is used if available
diff --git a/mercurial/hgweb/protocol.py b/mercurial/hgweb/protocol.py
--- a/mercurial/hgweb/protocol.py
+++ b/mercurial/hgweb/protocol.py
@@ -11,6 +11,8 @@
import struct
from .common import (
+ ErrorResponse,
+ HTTP_NOT_ACCEPTABLE,
HTTP_OK,
)
@@ -140,8 +142,8 @@
return HGTYPE2, engine, opts
- # No mutually supported compression format. Fall back to the
- # legacy protocol.
+ raise ErrorResponse(HTTP_NOT_ACCEPTABLE,
+ 'No common compression format')
# Don't allow untrusted settings because disabling compression or
# setting a very high compression level could lead to flooding
diff --git a/mercurial/hgweb/common.py b/mercurial/hgweb/common.py
--- a/mercurial/hgweb/common.py
+++ b/mercurial/hgweb/common.py
@@ -28,6 +28,7 @@
HTTP_FORBIDDEN = 403
HTTP_NOT_FOUND = 404
HTTP_METHOD_NOT_ALLOWED = 405
+HTTP_NOT_ACCEPTABLE = 406
HTTP_SERVER_ERROR = 500
To: joerg.sonnenberger, #hg-reviewers
Cc: mercurial-devel
More information about the Mercurial-devel
mailing list