D2021: wireprotoserver: move error response handling out of hgweb
This revision was automatically updated to reflect the committed changes. Closed by commit rHG98a00aa0288d: wireprotoserver: move error response handling out of hgweb (authored by indygreg, committed by ). REPOSITORY rHG Mercurial CHANGES SINCE LAST UPDATE https://phab.mercurial-scm.org/D2021?vs=5260&id=5311 REVISION DETAIL https://phab.mercurial-scm.org/D2021 AFFECTED FILES mercurial/hgweb/hgweb_mod.py mercurial/wireprotoserver.py CHANGE DETAILS diff --git a/mercurial/wireprotoserver.py b/mercurial/wireprotoserver.py --- a/mercurial/wireprotoserver.py +++ b/mercurial/wireprotoserver.py @@ -242,6 +242,7 @@ 'cmd': cmd, 'proto': proto, 'dispatch': lambda: _callhttp(repo, req, proto, cmd), +'handleerror': lambda ex: _handlehttperror(ex, req, cmd), } def _callhttp(repo, req, proto, cmd): @@ -303,6 +304,22 @@ return [] raise error.ProgrammingError('hgweb.protocol internal failure', rsp) +def _handlehttperror(e, req, cmd): +"""Called when an ErrorResponse is raised during HTTP request processing.""" +# A client that sends unbundle without 100-continue will +# break if we respond early. +if (cmd == 'unbundle' and +(req.env.get('HTTP_EXPECT', + '').lower() != '100-continue') or +req.env.get('X-HgHttp2', '')): +req.drain() +else: +req.headers.append((r'Connection', r'Close')) + +req.respond(e, HGTYPE, body='0\n%s\n' % e) + +return '' + class sshserver(abstractserverproto): def __init__(self, ui, repo): self._ui = ui diff --git a/mercurial/hgweb/hgweb_mod.py b/mercurial/hgweb/hgweb_mod.py --- a/mercurial/hgweb/hgweb_mod.py +++ b/mercurial/hgweb/hgweb_mod.py @@ -369,18 +369,7 @@ if cmd in perms: self.check_perm(rctx, req, perms[cmd]) except ErrorResponse as inst: -# A client that sends unbundle without 100-continue will -# break if we respond early. -if (cmd == 'unbundle' and -(req.env.get('HTTP_EXPECT', - '').lower() != '100-continue') or -req.env.get('X-HgHttp2', '')): -req.drain() -else: -req.headers.append((r'Connection', r'Close')) -req.respond(inst, wireprotoserver.HGTYPE, -body='0\n%s\n' % inst) -return '' +return protohandler['handleerror'](inst) return protohandler['dispatch']() To: indygreg, #hg-reviewers, durin42 Cc: mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
D2021: wireprotoserver: move error response handling out of hgweb
indygreg updated this revision to Diff 5260. REPOSITORY rHG Mercurial CHANGES SINCE LAST UPDATE https://phab.mercurial-scm.org/D2021?vs=5175&id=5260 REVISION DETAIL https://phab.mercurial-scm.org/D2021 AFFECTED FILES mercurial/hgweb/hgweb_mod.py mercurial/wireprotoserver.py CHANGE DETAILS diff --git a/mercurial/wireprotoserver.py b/mercurial/wireprotoserver.py --- a/mercurial/wireprotoserver.py +++ b/mercurial/wireprotoserver.py @@ -236,6 +236,7 @@ 'cmd': cmd, 'proto': proto, 'dispatch': lambda: _callhttp(repo, req, proto, cmd), +'handleerror': lambda ex: _handlehttperror(ex, req, cmd), } def _callhttp(repo, req, proto, cmd): @@ -297,6 +298,22 @@ return [] raise error.ProgrammingError('hgweb.protocol internal failure', rsp) +def _handlehttperror(e, req, cmd): +"""Called when an ErrorResponse is raised during HTTP request processing.""" +# A client that sends unbundle without 100-continue will +# break if we respond early. +if (cmd == 'unbundle' and +(req.env.get('HTTP_EXPECT', + '').lower() != '100-continue') or +req.env.get('X-HgHttp2', '')): +req.drain() +else: +req.headers.append((r'Connection', r'Close')) + +req.respond(e, HGTYPE, body='0\n%s\n' % e) + +return '' + class sshserver(abstractserverproto): def __init__(self, ui, repo): self._ui = ui diff --git a/mercurial/hgweb/hgweb_mod.py b/mercurial/hgweb/hgweb_mod.py --- a/mercurial/hgweb/hgweb_mod.py +++ b/mercurial/hgweb/hgweb_mod.py @@ -369,18 +369,7 @@ if cmd in perms: self.check_perm(rctx, req, perms[cmd]) except ErrorResponse as inst: -# A client that sends unbundle without 100-continue will -# break if we respond early. -if (cmd == 'unbundle' and -(req.env.get('HTTP_EXPECT', - '').lower() != '100-continue') or -req.env.get('X-HgHttp2', '')): -req.drain() -else: -req.headers.append((r'Connection', r'Close')) -req.respond(inst, wireprotoserver.HGTYPE, -body='0\n%s\n' % inst) -return '' +return protohandler['handleerror'](inst) return protohandler['dispatch']() To: indygreg, #hg-reviewers Cc: mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
D2021: wireprotoserver: move error response handling out of hgweb
indygreg created this revision. Herald added a subscriber: mercurial-devel. Herald added a reviewer: hg-reviewers. REVISION SUMMARY The exception handler for ErrorResponse has more to do with the wire protocol than the generic HTTP server. Move the code so it lives alongside other wire protocol code. REPOSITORY rHG Mercurial REVISION DETAIL https://phab.mercurial-scm.org/D2021 AFFECTED FILES mercurial/hgweb/hgweb_mod.py mercurial/wireprotoserver.py CHANGE DETAILS diff --git a/mercurial/wireprotoserver.py b/mercurial/wireprotoserver.py --- a/mercurial/wireprotoserver.py +++ b/mercurial/wireprotoserver.py @@ -239,6 +239,7 @@ 'cmd': cmd, 'proto': proto, 'dispatch': lambda: _callhttp(repo, req, proto, cmd), +'handleerror': lambda ex: _handlehttperror(ex, req, cmd), } def _callhttp(repo, req, proto, cmd): @@ -300,6 +301,22 @@ return [] raise error.ProgrammingError('hgweb.protocol internal failure', rsp) +def _handlehttperror(e, req, cmd): +"""Called when an ErrorResponse is raised during HTTP request processing.""" +# A client that sends unbundle without 100-continue will +# break if we respond early. +if (cmd == 'unbundle' and +(req.env.get('HTTP_EXPECT', + '').lower() != '100-continue') or +req.env.get('X-HgHttp2', '')): +req.drain() +else: +req.headers.append((r'Connection', r'Close')) + +req.respond(e, HGTYPE, body='0\n%s\n' % e) + +return '' + class sshserver(abstractserverproto): def __init__(self, ui, repo): self._ui = ui diff --git a/mercurial/hgweb/hgweb_mod.py b/mercurial/hgweb/hgweb_mod.py --- a/mercurial/hgweb/hgweb_mod.py +++ b/mercurial/hgweb/hgweb_mod.py @@ -369,18 +369,7 @@ if cmd in perms: self.check_perm(rctx, req, perms[cmd]) except ErrorResponse as inst: -# A client that sends unbundle without 100-continue will -# break if we respond early. -if (cmd == 'unbundle' and -(req.env.get('HTTP_EXPECT', - '').lower() != '100-continue') or -req.env.get('X-HgHttp2', '')): -req.drain() -else: -req.headers.append((r'Connection', r'Close')) -req.respond(inst, wireprotoserver.HGTYPE, -body='0\n%s\n' % inst) -return '' +return protohandler['handleerror'](inst) return protohandler['dispatch']() To: indygreg, #hg-reviewers Cc: mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel