Mercurial > hg
changeset 37009:5890e5872f36
hgweb: allow defining Server response header for HTTP server
By default, the string contains the Python version. Server
operators may want to change this.
Because we like deterministic tests, we change the test harness
to always set this value to a known string. Various globs over
the server header have now been removed.
# no-check-commit because we add version_string()
Differential Revision: https://phab.mercurial-scm.org/D2840
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Tue, 13 Mar 2018 09:45:56 -0700 |
parents | 16203c6079e7 |
children | 8453699a1f21 |
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 |
diffstat | 9 files changed, 41 insertions(+), 25 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/configitems.py Tue Mar 13 08:58:52 2018 -0700 +++ b/mercurial/configitems.py Tue Mar 13 09:45:56 2018 -0700 @@ -1255,6 +1255,9 @@ coreconfigitem('web', 'refreshinterval', default=20, ) +coreconfigitem('web', 'server-header', + default=None, +) coreconfigitem('web', 'staticurl', default=None, )
--- a/mercurial/help/config.txt Tue Mar 13 08:58:52 2018 -0700 +++ b/mercurial/help/config.txt Tue Mar 13 09:45:56 2018 -0700 @@ -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
--- a/mercurial/hgweb/server.py Tue Mar 13 08:58:52 2018 -0700 +++ b/mercurial/hgweb/server.py Tue Mar 13 09:45:56 2018 -0700 @@ -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):
--- a/tests/run-tests.py Tue Mar 13 08:58:52 2018 -0700 +++ b/tests/run-tests.py Tue Mar 13 09:45:56 2018 -0700 @@ -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)
--- a/tests/test-archive.t Tue Mar 13 08:58:52 2018 -0700 +++ b/tests/test-archive.t Tue Mar 13 09:45:56 2018 -0700 @@ -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
--- a/tests/test-basic.t Tue Mar 13 08:58:52 2018 -0700 +++ b/tests/test-basic.t Tue Mar 13 09:45:56 2018 -0700 @@ -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
--- a/tests/test-commandserver.t Tue Mar 13 08:58:52 2018 -0700 +++ b/tests/test-commandserver.t Tue Mar 13 09:45:56 2018 -0700 @@ -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
--- a/tests/test-hgweb-commands.t Tue Mar 13 08:58:52 2018 -0700 +++ b/tests/test-hgweb-commands.t Tue Mar 13 09:45:56 2018 -0700 @@ -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
--- a/tests/test-http-protocol.t Tue Mar 13 08:58:52 2018 -0700 +++ b/tests/test-http-protocol.t Tue Mar 13 09:45:56 2018 -0700 @@ -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