hgweb: make type a mandatory parameter to request.respond
authorMads Kiilerich <mads@kiilerich.com>
Tue, 15 Jan 2013 01:05:12 +0100
changeset 18347 853221386f48
parent 18346 6c2563b2c1c6
child 18348 764a758780b6
hgweb: make type a mandatory parameter to request.respond There will thus always be headers and the runtime check can be removed.
mercurial/hgweb/request.py
mercurial/hgweb/webcommands.py
--- a/mercurial/hgweb/request.py	Tue Jan 15 01:05:12 2013 +0100
+++ b/mercurial/hgweb/request.py	Tue Jan 15 01:05:12 2013 +0100
@@ -70,12 +70,10 @@
         for s in util.filechunkiter(self.inp, limit=length):
             pass
 
-    def respond(self, status, type=None, filename=None, length=None):
+    def respond(self, status, type, filename=None, length=None):
         if self._start_response is not None:
 
             self.httphdr(type, filename, length)
-            if not self.headers:
-                raise RuntimeError("request.write called before headers sent")
 
             for k, v in self.headers:
                 if not isinstance(v, str):
@@ -125,10 +123,9 @@
     def header(self, headers=[('Content-Type','text/html')]):
         self.headers.extend(headers)
 
-    def httphdr(self, type=None, filename=None, length=None, headers={}):
+    def httphdr(self, type, filename=None, length=None, headers={}):
         headers = headers.items()
-        if type is not None:
-            headers.append(('Content-Type', type))
+        headers.append(('Content-Type', type))
         if filename:
             filename = (filename.split('/')[-1]
                         .replace('\\', '\\\\').replace('"', '\\"'))
--- a/mercurial/hgweb/webcommands.py	Tue Jan 15 01:05:12 2013 +0100
+++ b/mercurial/hgweb/webcommands.py	Tue Jan 15 01:05:12 2013 +0100
@@ -800,13 +800,12 @@
     name = "%s-%s" % (reponame, arch_version)
     mimetype, artype, extension, encoding = web.archive_specs[type_]
     headers = [
-        ('Content-Type', mimetype),
         ('Content-Disposition', 'attachment; filename=%s%s' % (name, extension))
-    ]
+        ]
     if encoding:
         headers.append(('Content-Encoding', encoding))
     req.header(headers)
-    req.respond(HTTP_OK)
+    req.respond(HTTP_OK, mimetype)
 
     ctx = webutil.changectx(web.repo, req)
     archival.archive(web.repo, req, cnode, artype, prefix=name,