changeset 37021:3e74d3cc500f

highlight: peek Content-Type header set by hgweb There should be no need to re-render the mimetype template since it's set before dispatching webcommands.
author Yuya Nishihara <yuya@tcha.org>
date Mon, 19 Mar 2018 21:09:23 +0900
parents 98c14e857e71
children c97b936d8bb5
files hgext/highlight/__init__.py
diffstat 1 files changed, 2 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/highlight/__init__.py	Tue Mar 20 14:12:05 2018 +0800
+++ b/hgext/highlight/__init__.py	Mon Mar 19 21:09:23 2018 +0900
@@ -35,7 +35,6 @@
 )
 
 from mercurial import (
-    encoding,
     extensions,
     fileset,
 )
@@ -59,7 +58,7 @@
                 guessfilenameonly=filenameonly)
 
 def filerevision_highlight(orig, web, fctx):
-    mt = ''.join(web.tmpl('mimetype', encoding=encoding.encoding))
+    mt = web.res.headers['Content-Type']
     # only pygmentize for mimetype containing 'html' so we both match
     # 'text/html' and possibly 'application/xhtml+xml' in the future
     # so that we don't have to touch the extension when the mimetype
@@ -73,7 +72,7 @@
     return orig(web, fctx)
 
 def annotate_highlight(orig, web):
-    mt = ''.join(web.tmpl('mimetype', encoding=encoding.encoding))
+    mt = web.res.headers['Content-Type']
     if 'html' in mt:
         fctx = webutil.filectx(web.repo, web.req)
         pygmentize(web, 'annotateline', fctx, web.tmpl)