diff mercurial/hgweb/webcommands.py @ 5890:a0e20a5eba3c

hgweb: fast path for sending raw files
author Dirkjan Ochtman <dirkjan@ochtman.nl>
date Fri, 18 Jan 2008 19:53:38 +0100
parents 9d900f7282e6
children d0576d065993
line wrap: on
line diff
--- a/mercurial/hgweb/webcommands.py	Fri Jan 18 19:53:38 2008 +0100
+++ b/mercurial/hgweb/webcommands.py	Fri Jan 18 19:53:38 2008 +0100
@@ -5,8 +5,8 @@
 # This software may be used and distributed according to the terms
 # of the GNU General Public License, incorporated herein by reference.
 
-import os
-from mercurial import revlog
+import os, mimetypes
+from mercurial import revlog, util
 from common import staticfile
 
 def log(web, req, tmpl):
@@ -15,6 +15,27 @@
     else:
         changelog(web, req, tmpl)
 
+def rawfile(web, req, tmpl):
+    path = web.cleanpath(req.form.get('file', [''])[0])
+    if not path:
+        req.write(web.manifest(tmpl, web.changectx(req), path))
+        return
+
+    try:
+        fctx = web.filectx(req)
+    except revlog.LookupError:
+        req.write(web.manifest(tmpl, web.changectx(req), path))
+        return
+
+    path = fctx.path()
+    text = fctx.data()
+    mt = mimetypes.guess_type(path)[0]
+    if util.binary(text):
+        mt = mt or 'application/octet-stream'
+
+    req.httphdr(mt, path, len(text))
+    req.write(text)
+
 def file(web, req, tmpl):
     path = web.cleanpath(req.form.get('file', [''])[0])
     if path: