# HG changeset patch # User Mads Kiilerich # Date 1358208312 -3600 # Node ID 853221386f4896842df2f4fdaf19f4fc6849117a # Parent 6c2563b2c1c6a2d92a6bb712be2e04c345a2a1d6 hgweb: make type a mandatory parameter to request.respond There will thus always be headers and the runtime check can be removed. diff -r 6c2563b2c1c6 -r 853221386f48 mercurial/hgweb/request.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('"', '\\"')) diff -r 6c2563b2c1c6 -r 853221386f48 mercurial/hgweb/webcommands.py --- 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,