mercurial/wireprotoserver.py
changeset 35986 98a00aa0288d
parent 35984 cdc93fe1da77
child 35987 6010fe1da619
equal deleted inserted replaced
35985:e69e65b2b4a9 35986:98a00aa0288d
   240 
   240 
   241     return {
   241     return {
   242         'cmd': cmd,
   242         'cmd': cmd,
   243         'proto': proto,
   243         'proto': proto,
   244         'dispatch': lambda: _callhttp(repo, req, proto, cmd),
   244         'dispatch': lambda: _callhttp(repo, req, proto, cmd),
       
   245         'handleerror': lambda ex: _handlehttperror(ex, req, cmd),
   245     }
   246     }
   246 
   247 
   247 def _callhttp(repo, req, proto, cmd):
   248 def _callhttp(repo, req, proto, cmd):
   248     def genversion2(gen, engine, engineopts):
   249     def genversion2(gen, engine, engineopts):
   249         # application/mercurial-0.2 always sends a payload header
   250         # application/mercurial-0.2 always sends a payload header
   300     elif isinstance(rsp, wireproto.ooberror):
   301     elif isinstance(rsp, wireproto.ooberror):
   301         rsp = rsp.message
   302         rsp = rsp.message
   302         req.respond(HTTP_OK, HGERRTYPE, body=rsp)
   303         req.respond(HTTP_OK, HGERRTYPE, body=rsp)
   303         return []
   304         return []
   304     raise error.ProgrammingError('hgweb.protocol internal failure', rsp)
   305     raise error.ProgrammingError('hgweb.protocol internal failure', rsp)
       
   306 
       
   307 def _handlehttperror(e, req, cmd):
       
   308     """Called when an ErrorResponse is raised during HTTP request processing."""
       
   309     # A client that sends unbundle without 100-continue will
       
   310     # break if we respond early.
       
   311     if (cmd == 'unbundle' and
       
   312         (req.env.get('HTTP_EXPECT',
       
   313                      '').lower() != '100-continue') or
       
   314         req.env.get('X-HgHttp2', '')):
       
   315         req.drain()
       
   316     else:
       
   317         req.headers.append((r'Connection', r'Close'))
       
   318 
       
   319     req.respond(e, HGTYPE, body='0\n%s\n' % e)
       
   320 
       
   321     return ''
   305 
   322 
   306 class sshserver(abstractserverproto):
   323 class sshserver(abstractserverproto):
   307     def __init__(self, ui, repo):
   324     def __init__(self, ui, repo):
   308         self._ui = ui
   325         self._ui = ui
   309         self._repo = repo
   326         self._repo = repo