diff --git a/mercurial/configitems.py b/mercurial/configitems.py --- a/mercurial/configitems.py +++ b/mercurial/configitems.py @@ -1252,6 +1252,9 @@ coreconfigitem('web', 'refreshinterval', default=20, ) +coreconfigitem('web', 'server-header', + default=None, +) coreconfigitem('web', 'staticurl', default=None, ) 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/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/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/tests/test-archive.t b/tests/test-archive.t --- a/tests/test-archive.t +++ b/tests/test-archive.t @@ -128,7 +128,7 @@ 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 @@ -137,7 +137,7 @@ 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 @@ -145,7 +145,7 @@ 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,7 +156,7 @@ 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 @@ -165,7 +165,7 @@ 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 @@ -173,7 +173,7 @@ 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,7 +184,7 @@ content-type: application/zip date: $HTTP_DATE$ etag: W/"*" (glob) - server: * (glob) + server: testing stub value transfer-encoding: chunked body: size=1377, sha1=677b14d3d048778d5eb5552c14a67e6192068650 @@ -193,7 +193,7 @@ 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 @@ -201,7 +201,7 @@ 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,7 +215,7 @@ 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 @@ -224,7 +224,7 @@ 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 @@ -232,7 +232,7 @@ 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,7 +243,7 @@ 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 @@ -252,7 +252,7 @@ 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 @@ -260,7 +260,7 @@ 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,7 +271,7 @@ content-type: application/zip date: $HTTP_DATE$ etag: W/"*" (glob) - server: * (glob) + server: testing stub value transfer-encoding: chunked body: size=1377, sha1=677b14d3d048778d5eb5552c14a67e6192068650 @@ -280,7 +280,7 @@ 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 @@ -288,7 +288,7 @@ 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/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-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-hgweb-commands.t b/tests/test-hgweb-commands.t --- a/tests/test-hgweb-commands.t +++ b/tests/test-hgweb-commands.t @@ -1923,7 +1923,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-http-protocol.t b/tests/test-http-protocol.t --- a/tests/test-http-protocol.t +++ b/tests/test-http-protocol.t @@ -50,7 +50,7 @@ 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 @@ -59,7 +59,7 @@ 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 @@ -68,14 +68,14 @@ 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 @@ -84,7 +84,7 @@ 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