diff mercurial/hgweb/common.py @ 2514:419c42223bee

Really fix http headers for web UI and issue 254. This also arranges for static content to allow a keepalive connection.
author Eric Hopper <hopper@omnifarious.org>
date Tue, 27 Jun 2006 09:33:12 -0700
parents d351a3be3371
children 345bac2bc4ec
line wrap: on
line diff
--- a/mercurial/hgweb/common.py
+++ b/mercurial/hgweb/common.py
@@ -17,7 +17,7 @@ def get_mtime(repo_path):
     else:
         return os.stat(hg_path).st_mtime
 
-def staticfile(directory, fname):
+def staticfile(directory, fname, req):
     """return a file inside directory with guessed content-type header
 
     fname always uses '/' as directory separator and isn't allowed to
@@ -36,7 +36,9 @@ def staticfile(directory, fname):
     try:
         os.stat(path)
         ct = mimetypes.guess_type(path)[0] or "text/plain"
-        return "Content-type: %s\n\n%s" % (ct, file(path).read())
+        req.header([('Content-type', ct),
+                    ('Content-length', os.path.getsize(path))])
+        return file(path).read()
     except (TypeError, OSError):
         # illegal fname or unreadable file
         return ""