comparison mercurial/wireprotoserver.py @ 37129:aaabd709df72

wireproto: review fixups Capture various TODOs and return an explicit value. This represents feedback from Yuya and Augie on various commits. Differential Revision: https://phab.mercurial-scm.org/D2944
author Gregory Szorc <gregory.szorc@gmail.com>
date Mon, 26 Mar 2018 09:21:07 -0700
parents a8a902d7176e
children 3ed344546d9e
comparison
equal deleted inserted replaced
37128:1236beb5d150 37129:aaabd709df72
351 res.status = b'404 Not Found' 351 res.status = b'404 Not Found'
352 res.headers[b'Content-Type'] = b'text/plain' 352 res.headers[b'Content-Type'] = b'text/plain'
353 res.setbodybytes(_('invalid wire protocol command: %s') % command) 353 res.setbodybytes(_('invalid wire protocol command: %s') % command)
354 return 354 return
355 355
356 # TODO consider cases where proxies may add additional Accept headers.
356 if req.headers.get(b'Accept') != FRAMINGTYPE: 357 if req.headers.get(b'Accept') != FRAMINGTYPE:
357 res.status = b'406 Not Acceptable' 358 res.status = b'406 Not Acceptable'
358 res.headers[b'Content-Type'] = b'text/plain' 359 res.headers[b'Content-Type'] = b'text/plain'
359 res.setbodybytes(_('client MUST specify Accept header with value: %s\n') 360 res.setbodybytes(_('client MUST specify Accept header with value: %s\n')
360 % FRAMINGTYPE) 361 % FRAMINGTYPE)
505 res.headers[b'Content-Type'] = b'text/plain' 506 res.headers[b'Content-Type'] = b'text/plain'
506 res.setbodybytes(_('wire protocol command not available: %s') % 507 res.setbodybytes(_('wire protocol command not available: %s') %
507 command['command']) 508 command['command'])
508 return True 509 return True
509 510
511 # TODO don't use assert here, since it may be elided by -O.
510 assert authedperm in (b'ro', b'rw') 512 assert authedperm in (b'ro', b'rw')
511 wirecommand = wireproto.commands[command['command']] 513 wirecommand = wireproto.commands[command['command']]
512 assert wirecommand.permission in ('push', 'pull') 514 assert wirecommand.permission in ('push', 'pull')
513 515
514 if authedperm == b'ro' and wirecommand.permission != 'pull': 516 if authedperm == b'ro' and wirecommand.permission != 'pull':
554 556
555 if action == 'sendframes': 557 if action == 'sendframes':
556 res.setbodygen(meta['framegen']) 558 res.setbodygen(meta['framegen'])
557 return True 559 return True
558 elif action == 'noop': 560 elif action == 'noop':
559 pass 561 return False
560 else: 562 else:
561 raise error.ProgrammingError('unhandled event from reactor: %s' % 563 raise error.ProgrammingError('unhandled event from reactor: %s' %
562 action) 564 action)
563 565
564 # Maps API name to metadata so custom API can be registered. 566 # Maps API name to metadata so custom API can be registered.