D2840: hgweb: allow defining Server response header for HTTP server
indygreg (Gregory Szorc)
phabricator at mercurial-scm.org
Tue Mar 20 01:41:23 UTC 2018
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG5890e5872f36: hgweb: allow defining Server response header for HTTP server (authored by indygreg, committed by ).
REPOSITORY
rHG Mercurial
CHANGES SINCE LAST UPDATE
https://phab.mercurial-scm.org/D2840?vs=6993&id=7155
REVISION DETAIL
https://phab.mercurial-scm.org/D2840
AFFECTED FILES
mercurial/configitems.py
mercurial/help/config.txt
mercurial/hgweb/server.py
tests/run-tests.py
tests/test-archive.t
tests/test-basic.t
tests/test-commandserver.t
tests/test-hgweb-commands.t
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
@@ -50,41 +50,41 @@
200 Script output follows
content-type: application/mercurial-0.1
date: $HTTP_DATE$
- server: * (glob)
+ server: testing stub value
transfer-encoding: chunked
Server should send application/mercurial-0.1 when client says it wants it
$ get-with-headers.py --hgproto '0.1' --headeronly $LOCALIP:$HGPORT '?cmd=getbundle&heads=e93700bd72895c5addab234c56d4024b487a362f&common=0000000000000000000000000000000000000000' -
200 Script output follows
content-type: application/mercurial-0.1
date: $HTTP_DATE$
- server: * (glob)
+ server: testing stub value
transfer-encoding: chunked
Server should send application/mercurial-0.2 when client says it wants it
$ get-with-headers.py --hgproto '0.2' --headeronly $LOCALIP:$HGPORT '?cmd=getbundle&heads=e93700bd72895c5addab234c56d4024b487a362f&common=0000000000000000000000000000000000000000' -
200 Script output follows
content-type: application/mercurial-0.2
date: $HTTP_DATE$
- server: * (glob)
+ server: testing stub value
transfer-encoding: chunked
$ get-with-headers.py --hgproto '0.1 0.2' --headeronly $LOCALIP:$HGPORT '?cmd=getbundle&heads=e93700bd72895c5addab234c56d4024b487a362f&common=0000000000000000000000000000000000000000' -
200 Script output follows
content-type: application/mercurial-0.2
date: $HTTP_DATE$
- server: * (glob)
+ server: testing stub value
transfer-encoding: chunked
Requesting a compression format that server doesn't support results will fall back to 0.1
$ get-with-headers.py --hgproto '0.2 comp=aa' --headeronly $LOCALIP:$HGPORT '?cmd=getbundle&heads=e93700bd72895c5addab234c56d4024b487a362f&common=0000000000000000000000000000000000000000' -
200 Script output follows
content-type: application/mercurial-0.1
date: $HTTP_DATE$
- server: * (glob)
+ server: testing stub value
transfer-encoding: chunked
#if zstd
@@ -106,7 +106,7 @@
content-length: 41
content-type: application/mercurial-0.1
date: $HTTP_DATE$
- server: * (glob)
+ server: testing stub value
e93700bd72895c5addab234c56d4024b487a362f
diff --git a/tests/test-hgweb-commands.t b/tests/test-hgweb-commands.t
--- a/tests/test-hgweb-commands.t
+++ b/tests/test-hgweb-commands.t
@@ -1924,7 +1924,7 @@
content-length: 12
content-type: application/mercurial-0.1
date: $HTTP_DATE$
- server: * (glob)
+ server: testing stub value
0
Not Found
diff --git a/tests/test-commandserver.t b/tests/test-commandserver.t
--- a/tests/test-commandserver.t
+++ b/tests/test-commandserver.t
@@ -215,6 +215,7 @@
ui.nontty=true
web.address=localhost
web\.ipv6=(?:True|False) (re)
+ web.server-header=testing stub value
*** runcommand init foo
*** runcommand -R foo showconfig ui defaults
ui.slash=True
diff --git a/tests/test-basic.t b/tests/test-basic.t
--- a/tests/test-basic.t
+++ b/tests/test-basic.t
@@ -12,6 +12,7 @@
ui.promptecho=True
web.address=localhost
web\.ipv6=(?:True|False) (re)
+ web.server-header=testing stub value
$ hg init t
$ cd t
diff --git a/tests/test-archive.t b/tests/test-archive.t
--- a/tests/test-archive.t
+++ b/tests/test-archive.t
@@ -128,24 +128,24 @@
content-type: application/x-gzip
date: $HTTP_DATE$
etag: W/"*" (glob)
- server: * (glob)
+ server: testing stub value
transfer-encoding: chunked
body: size=408, sha1=8fa06531bddecc365a9f5edb0f88b65974bfe505
% tar.bz2 and zip disallowed should both give 403
403 Archive type not allowed: bz2
content-type: text/html; charset=ascii
date: $HTTP_DATE$
etag: W/"*" (glob)
- server: * (glob)
+ server: testing stub value
transfer-encoding: chunked
body: size=1451, sha1=4c5cf0f574446c44feb7f88f4e0e2a56bd92c352
403 Archive type not allowed: zip
content-type: text/html; charset=ascii
date: $HTTP_DATE$
etag: W/"*" (glob)
- server: * (glob)
+ server: testing stub value
transfer-encoding: chunked
body: size=1451, sha1=cbfa5574b337348bfd0564cc534474d002e7d6c7
@@ -156,24 +156,24 @@
content-type: application/x-bzip2
date: $HTTP_DATE$
etag: W/"*" (glob)
- server: * (glob)
+ server: testing stub value
transfer-encoding: chunked
body: size=426, sha1=8d87f5aba6e14f1bfea6c232985982c278b2fb0b
% zip and tar.gz disallowed should both give 403
403 Archive type not allowed: zip
content-type: text/html; charset=ascii
date: $HTTP_DATE$
etag: W/"*" (glob)
- server: * (glob)
+ server: testing stub value
transfer-encoding: chunked
body: size=1451, sha1=cbfa5574b337348bfd0564cc534474d002e7d6c7
403 Archive type not allowed: gz
content-type: text/html; charset=ascii
date: $HTTP_DATE$
etag: W/"*" (glob)
- server: * (glob)
+ server: testing stub value
transfer-encoding: chunked
body: size=1450, sha1=71f0b12d59f85fdcfe8ff493e2dc66863f2f7734
@@ -184,24 +184,24 @@
content-type: application/zip
date: $HTTP_DATE$
etag: W/"*" (glob)
- server: * (glob)
+ server: testing stub value
transfer-encoding: chunked
body: size=1377, sha1=677b14d3d048778d5eb5552c14a67e6192068650
% tar.gz and tar.bz2 disallowed should both give 403
403 Archive type not allowed: gz
content-type: text/html; charset=ascii
date: $HTTP_DATE$
etag: W/"*" (glob)
- server: * (glob)
+ server: testing stub value
transfer-encoding: chunked
body: size=1450, sha1=71f0b12d59f85fdcfe8ff493e2dc66863f2f7734
403 Archive type not allowed: bz2
content-type: text/html; charset=ascii
date: $HTTP_DATE$
etag: W/"*" (glob)
- server: * (glob)
+ server: testing stub value
transfer-encoding: chunked
body: size=1451, sha1=4c5cf0f574446c44feb7f88f4e0e2a56bd92c352
@@ -215,24 +215,24 @@
content-type: application/x-gzip
date: $HTTP_DATE$
etag: W/"*" (glob)
- server: * (glob)
+ server: testing stub value
transfer-encoding: chunked
body: size=408, sha1=8fa06531bddecc365a9f5edb0f88b65974bfe505
% tar.bz2 and zip disallowed should both give 403
403 Archive type not allowed: bz2
content-type: text/html; charset=ascii
date: $HTTP_DATE$
etag: W/"*" (glob)
- server: * (glob)
+ server: testing stub value
transfer-encoding: chunked
body: size=1451, sha1=4c5cf0f574446c44feb7f88f4e0e2a56bd92c352
403 Archive type not allowed: zip
content-type: text/html; charset=ascii
date: $HTTP_DATE$
etag: W/"*" (glob)
- server: * (glob)
+ server: testing stub value
transfer-encoding: chunked
body: size=1451, sha1=cbfa5574b337348bfd0564cc534474d002e7d6c7
@@ -243,24 +243,24 @@
content-type: application/x-bzip2
date: $HTTP_DATE$
etag: W/"*" (glob)
- server: * (glob)
+ server: testing stub value
transfer-encoding: chunked
body: size=426, sha1=8d87f5aba6e14f1bfea6c232985982c278b2fb0b
% zip and tar.gz disallowed should both give 403
403 Archive type not allowed: zip
content-type: text/html; charset=ascii
date: $HTTP_DATE$
etag: W/"*" (glob)
- server: * (glob)
+ server: testing stub value
transfer-encoding: chunked
body: size=1451, sha1=cbfa5574b337348bfd0564cc534474d002e7d6c7
403 Archive type not allowed: gz
content-type: text/html; charset=ascii
date: $HTTP_DATE$
etag: W/"*" (glob)
- server: * (glob)
+ server: testing stub value
transfer-encoding: chunked
body: size=1450, sha1=71f0b12d59f85fdcfe8ff493e2dc66863f2f7734
@@ -271,24 +271,24 @@
content-type: application/zip
date: $HTTP_DATE$
etag: W/"*" (glob)
- server: * (glob)
+ server: testing stub value
transfer-encoding: chunked
body: size=1377, sha1=677b14d3d048778d5eb5552c14a67e6192068650
% tar.gz and tar.bz2 disallowed should both give 403
403 Archive type not allowed: gz
content-type: text/html; charset=ascii
date: $HTTP_DATE$
etag: W/"*" (glob)
- server: * (glob)
+ server: testing stub value
transfer-encoding: chunked
body: size=1450, sha1=71f0b12d59f85fdcfe8ff493e2dc66863f2f7734
403 Archive type not allowed: bz2
content-type: text/html; charset=ascii
date: $HTTP_DATE$
etag: W/"*" (glob)
- server: * (glob)
+ server: testing stub value
transfer-encoding: chunked
body: size=1451, sha1=4c5cf0f574446c44feb7f88f4e0e2a56bd92c352
diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -1119,6 +1119,7 @@
hgrc.write(b'[web]\n')
hgrc.write(b'address = localhost\n')
hgrc.write(b'ipv6 = %s\n' % str(self._useipv6).encode('ascii'))
+ hgrc.write(b'server-header = testing stub value\n')
for opt in self._extraconfigopts:
section, key = opt.encode('utf-8').split(b'.', 1)
diff --git a/mercurial/hgweb/server.py b/mercurial/hgweb/server.py
--- a/mercurial/hgweb/server.py
+++ b/mercurial/hgweb/server.py
@@ -231,6 +231,11 @@
self.wfile.write('0\r\n\r\n')
self.wfile.flush()
+ def version_string(self):
+ if self.server.serverheader:
+ return self.server.serverheader
+ return httpservermod.basehttprequesthandler.version_string(self)
+
class _httprequesthandlerssl(_httprequesthandler):
"""HTTPS handler based on Python's ssl module"""
@@ -304,6 +309,8 @@
self.addr, self.port = self.socket.getsockname()[0:2]
self.fqaddr = socket.getfqdn(addr[0])
+ self.serverheader = ui.config('web', 'server-header')
+
class IPv6HTTPServer(MercurialHTTPServer):
address_family = getattr(socket, 'AF_INET6', None)
def __init__(self, *args, **kwargs):
diff --git a/mercurial/help/config.txt b/mercurial/help/config.txt
--- a/mercurial/help/config.txt
+++ b/mercurial/help/config.txt
@@ -2527,6 +2527,9 @@
Values less than or equal to 0 always refresh.
(default: 20)
+``server-header``
+ Value for HTTP ``Server`` response header.
+
``staticurl``
Base URL to use for static files. If unset, static files (e.g. the
hgicon.png favicon) will be served by the CGI script itself. Use
diff --git a/mercurial/configitems.py b/mercurial/configitems.py
--- a/mercurial/configitems.py
+++ b/mercurial/configitems.py
@@ -1255,6 +1255,9 @@
coreconfigitem('web', 'refreshinterval',
default=20,
)
+coreconfigitem('web', 'server-header',
+ default=None,
+)
coreconfigitem('web', 'staticurl',
default=None,
)
To: indygreg, #hg-reviewers, lothiraldan, durin42
Cc: mercurial-devel
More information about the Mercurial-devel
mailing list