changeset 36905:93717f082af9

hgweb: use modern response type for index generation Differential Revision: https://phab.mercurial-scm.org/D2827
author Gregory Szorc <gregory.szorc@gmail.com>
date Sun, 11 Mar 2018 15:37:59 -0700
parents 092ab4ba7ee5
children 6a0e4efbc61e
files mercurial/hgweb/hgwebdir_mod.py
diffstat 1 files changed, 14 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/hgweb/hgwebdir_mod.py	Sun Mar 11 15:29:38 2018 -0700
+++ b/mercurial/hgweb/hgwebdir_mod.py	Sun Mar 11 15:37:59 2018 -0700
@@ -16,7 +16,6 @@
 from .common import (
     ErrorResponse,
     HTTP_NOT_FOUND,
-    HTTP_OK,
     HTTP_SERVER_ERROR,
     cspvalues,
     get_contact,
@@ -400,16 +399,14 @@
             repos = dict(self.repos)
 
             if (not virtual or virtual == 'index') and virtual not in repos:
-                wsgireq.respond(HTTP_OK, ctype)
-                return self.makeindex(req, tmpl)
+                return self.makeindex(req, res, tmpl)
 
             # nested indexes and hgwebs
 
             if virtual.endswith('/index') and virtual not in repos:
                 subdir = virtual[:-len('index')]
                 if any(r.startswith(subdir) for r in repos):
-                    wsgireq.respond(HTTP_OK, ctype)
-                    return self.makeindex(req, tmpl, subdir)
+                    return self.makeindex(req, res, tmpl, subdir)
 
             def _virtualdirs():
                 # Check the full virtual path, each parent, and the root ('')
@@ -442,8 +439,7 @@
             # browse subdirectories
             subdir = virtual + '/'
             if [r for r in repos if r.startswith(subdir)]:
-                wsgireq.respond(HTTP_OK, ctype)
-                return self.makeindex(req, tmpl, subdir)
+                return self.makeindex(req, res, tmpl, subdir)
 
             # prefixes not found
             wsgireq.respond(HTTP_NOT_FOUND, ctype)
@@ -455,7 +451,7 @@
         finally:
             tmpl = None
 
-    def makeindex(self, req, tmpl, subdir=""):
+    def makeindex(self, req, res, tmpl, subdir=""):
         self.refresh()
         sortable = ["name", "description", "contact", "lastchange"]
         sortcolumn, descending = None, False
@@ -478,10 +474,16 @@
                                self.stripecount, sortcolumn=sortcolumn,
                                descending=descending, subdir=subdir)
 
-        return tmpl("index", entries=entries, subdir=subdir,
-                    pathdef=hgweb_mod.makebreadcrumb('/' + subdir, self.prefix),
-                    sortcolumn=sortcolumn, descending=descending,
-                    **dict(sort))
+        res.setbodygen(tmpl(
+            'index',
+            entries=entries,
+            subdir=subdir,
+            pathdef=hgweb_mod.makebreadcrumb('/' + subdir, self.prefix),
+            sortcolumn=sortcolumn,
+            descending=descending,
+            **dict(sort)))
+
+        return res.sendresponse()
 
     def templater(self, wsgireq, nonce):