Mercurial > public > mercurial-scm > hg-stable
diff mercurial/wireprotov2server.py @ 40024:10cf8b116dd8
wireprotov2: advertise redirect targets in capabilities
This is pretty straightforward.
Redirect targets will require an extension to support. So we've added
a function that can be wrapped to define redirect targets.
To test this, we teach our simple cache test extension to read
redirect targets from a file. It's a bit hacky. But it gets the
job done.
Differential Revision: https://phab.mercurial-scm.org/D4775
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Wed, 26 Sep 2018 17:46:48 -0700 |
parents | c537144fdbef |
children | b099e6032f38 |
line wrap: on
line diff
--- a/mercurial/wireprotov2server.py Wed Sep 26 18:02:06 2018 -0700 +++ b/mercurial/wireprotov2server.py Wed Sep 26 17:46:48 2018 -0700 @@ -517,8 +517,66 @@ caps['rawrepoformats'] = sorted(repo.requirements & repo.supportedformats) + targets = getadvertisedredirecttargets(repo, proto) + if targets: + caps[b'redirect'] = { + b'targets': [], + b'hashes': [b'sha256', b'sha1'], + } + + for target in targets: + entry = { + b'name': target['name'], + b'protocol': target['protocol'], + b'uris': target['uris'], + } + + for key in ('snirequired', 'tlsversions'): + if key in target: + entry[key] = target[key] + + caps[b'redirect'][b'targets'].append(entry) + return proto.addcapabilities(repo, caps) +def getadvertisedredirecttargets(repo, proto): + """Obtain a list of content redirect targets. + + Returns a list containing potential redirect targets that will be + advertised in capabilities data. Each dict MUST have the following + keys: + + name + The name of this redirect target. This is the identifier clients use + to refer to a target. It is transferred as part of every command + request. + + protocol + Network protocol used by this target. Typically this is the string + in front of the ``://`` in a URL. e.g. ``https``. + + uris + List of representative URIs for this target. Clients can use the + URIs to test parsing for compatibility or for ordering preference + for which target to use. + + The following optional keys are recognized: + + snirequired + Bool indicating if Server Name Indication (SNI) is required to + connect to this target. + + tlsversions + List of bytes indicating which TLS versions are supported by this + target. + + By default, clients reflect the target order advertised by servers + and servers will use the first client-advertised target when picking + a redirect target. So targets should be advertised in the order the + server prefers they be used. + """ + return [] + def wireprotocommand(name, args=None, permission='push', cachekeyfn=None): """Decorator to declare a wire protocol command.