Mercurial > hg
comparison mercurial/wireprotov2server.py @ 40023: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 |
comparison
equal
deleted
inserted
replaced
40022:33eb670e2834 | 40023:10cf8b116dd8 |
---|---|
515 | 515 |
516 if streamclone.allowservergeneration(repo): | 516 if streamclone.allowservergeneration(repo): |
517 caps['rawrepoformats'] = sorted(repo.requirements & | 517 caps['rawrepoformats'] = sorted(repo.requirements & |
518 repo.supportedformats) | 518 repo.supportedformats) |
519 | 519 |
520 targets = getadvertisedredirecttargets(repo, proto) | |
521 if targets: | |
522 caps[b'redirect'] = { | |
523 b'targets': [], | |
524 b'hashes': [b'sha256', b'sha1'], | |
525 } | |
526 | |
527 for target in targets: | |
528 entry = { | |
529 b'name': target['name'], | |
530 b'protocol': target['protocol'], | |
531 b'uris': target['uris'], | |
532 } | |
533 | |
534 for key in ('snirequired', 'tlsversions'): | |
535 if key in target: | |
536 entry[key] = target[key] | |
537 | |
538 caps[b'redirect'][b'targets'].append(entry) | |
539 | |
520 return proto.addcapabilities(repo, caps) | 540 return proto.addcapabilities(repo, caps) |
541 | |
542 def getadvertisedredirecttargets(repo, proto): | |
543 """Obtain a list of content redirect targets. | |
544 | |
545 Returns a list containing potential redirect targets that will be | |
546 advertised in capabilities data. Each dict MUST have the following | |
547 keys: | |
548 | |
549 name | |
550 The name of this redirect target. This is the identifier clients use | |
551 to refer to a target. It is transferred as part of every command | |
552 request. | |
553 | |
554 protocol | |
555 Network protocol used by this target. Typically this is the string | |
556 in front of the ``://`` in a URL. e.g. ``https``. | |
557 | |
558 uris | |
559 List of representative URIs for this target. Clients can use the | |
560 URIs to test parsing for compatibility or for ordering preference | |
561 for which target to use. | |
562 | |
563 The following optional keys are recognized: | |
564 | |
565 snirequired | |
566 Bool indicating if Server Name Indication (SNI) is required to | |
567 connect to this target. | |
568 | |
569 tlsversions | |
570 List of bytes indicating which TLS versions are supported by this | |
571 target. | |
572 | |
573 By default, clients reflect the target order advertised by servers | |
574 and servers will use the first client-advertised target when picking | |
575 a redirect target. So targets should be advertised in the order the | |
576 server prefers they be used. | |
577 """ | |
578 return [] | |
521 | 579 |
522 def wireprotocommand(name, args=None, permission='push', cachekeyfn=None): | 580 def wireprotocommand(name, args=None, permission='push', cachekeyfn=None): |
523 """Decorator to declare a wire protocol command. | 581 """Decorator to declare a wire protocol command. |
524 | 582 |
525 ``name`` is the name of the wire protocol command being provided. | 583 ``name`` is the name of the wire protocol command being provided. |