Patchwork [1,of,3,V2] highlight: peek Content-Type header set by hgweb

login
register
mail settings
Submitter Yuya Nishihara
Date March 19, 2018, 1:45 p.m.
Message ID <75c311c2a72be114b791.1521467103@mimosa>
Download mbox | patch
Permalink /patch/29618/
State Accepted
Headers show

Comments

Yuya Nishihara - March 19, 2018, 1:45 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1521461363 -32400
#      Mon Mar 19 21:09:23 2018 +0900
# Node ID 75c311c2a72be114b791e0a6d4dd0d1cef20fa7b
# Parent  b6a4881cec1937a8d9cd2e9bbbdf5ca31cfa73dd
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.

Patch

diff --git a/hgext/highlight/__init__.py b/hgext/highlight/__init__.py
--- a/hgext/highlight/__init__.py
+++ b/hgext/highlight/__init__.py
@@ -35,7 +35,6 @@  from mercurial.hgweb import (
 )
 
 from mercurial import (
-    encoding,
     extensions,
     fileset,
 )
@@ -59,7 +58,7 @@  def pygmentize(web, field, fctx, tmpl):
                 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 @@  def filerevision_highlight(orig, web, fc
     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)