[PATCH] hgweb: Serve raw non-binary files as text/plain

Rocco Rutte pdmef at gmx.net
Wed Sep 3 08:47:48 CDT 2008


# HG changeset patch
# User Rocco Rutte <pdmef at gmx.net>
# Date 1220449606 -7200
# Node ID 41ce554da11789e5ab648f966df781071f04f2c2
# Parent  a3fd4aa154afff901779639df0963e4e2848b7dd
hgweb: Serve raw non-binary files as text/plain

Previously these were served as application/octet-stream usually making
browers download them as files though can be displayed inline just
fine. This is useful to refer to e.g. /project/raw-file/tip/README.

diff --git a/mercurial/hgweb/webcommands.py b/mercurial/hgweb/webcommands.py
--- a/mercurial/hgweb/webcommands.py
+++ b/mercurial/hgweb/webcommands.py
@@ -50,8 +50,8 @@ def rawfile(web, req, tmpl):
     path = fctx.path()
     text = fctx.data()
     mt = mimetypes.guess_type(path)[0]
-    if mt is None or binary(text):
-        mt = mt or 'application/octet-stream'
+    if mt is None:
+        mt = binary(text) and 'application/octet-stream' or 'text/plain'
 
     req.respond(HTTP_OK, mt, path, len(text))
     return [text]


More information about the Mercurial-devel mailing list