changeset 5926:15ef6b9c1f2f

hgweb: be sure to send a valid content-type for raw files
author Dirkjan Ochtman <dirkjan@ochtman.nl>
date Tue, 22 Jan 2008 12:31:55 +0100
parents c6274913eba5
children b06c56f8fab7
files mercurial/hgweb/request.py mercurial/hgweb/webcommands.py
diffstat 2 files changed, 5 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/hgweb/request.py	Tue Jan 22 09:28:51 2008 +0100
+++ b/mercurial/hgweb/request.py	Tue Jan 22 12:31:55 2008 +0100
@@ -38,6 +38,10 @@
             if not self.headers:
                 raise RuntimeError("request.write called before headers sent")
 
+            for k, v in self.headers:
+                if not isinstance(v, str):
+                    raise TypeError('header value must be string: %r' % v)
+
             if isinstance(status, ErrorResponse):
                 status = statusmessage(status.code)
             elif isinstance(status, int):
--- a/mercurial/hgweb/webcommands.py	Tue Jan 22 09:28:51 2008 +0100
+++ b/mercurial/hgweb/webcommands.py	Tue Jan 22 12:31:55 2008 +0100
@@ -30,7 +30,7 @@
     path = fctx.path()
     text = fctx.data()
     mt = mimetypes.guess_type(path)[0]
-    if util.binary(text):
+    if mt is None or util.binary(text):
         mt = mt or 'application/octet-stream'
 
     req.httphdr(mt, path, len(text))