# HG changeset patch # User Matt Mackall # Date 1165193225 21600 # Node ID 713e35dcc3217aad20bae20b8ca5b25c82d82a71 # Parent d0a48313b0f6509a4186746183a60bf9935b3518 hgweb: report detected character set Add comments on overriding charset to CGI scripts diff --git a/hgweb.cgi b/hgweb.cgi --- a/hgweb.cgi +++ b/hgweb.cgi @@ -10,6 +10,13 @@ from mercurial.hgweb.hgweb_mod import hg from mercurial.hgweb.request import wsgiapplication import mercurial.hgweb.wsgicgi as wsgicgi +# If you'd like to serve pages with UTF-8 instead of your default +# locale charset, you can do so by uncommenting the following lines. +# Note that this will cause your .hgrc files to be interpreted in +# UTF-8 and all your repo files to be displayed using UTF-8. +# +# os.environ["HGENCODING"] = "UTF-8" + def make_web_app(): return hgweb("/path/to/repo", "repository name") diff --git a/hgwebdir.cgi b/hgwebdir.cgi --- a/hgwebdir.cgi +++ b/hgwebdir.cgi @@ -29,6 +29,13 @@ import mercurial.hgweb.wsgicgi as wsgicg # Alternatively you can pass a list of ('virtual/path', '/real/path') tuples # or use a dictionary with entries like 'virtual/path': '/real/path' +# If you'd like to serve pages with UTF-8 instead of your default +# locale charset, you can do so by uncommenting the following lines. +# Note that this will cause your .hgrc files to be interpreted in +# UTF-8 and all your repo files to be displayed using UTF-8. +# +# os.environ["HGENCODING"] = "UTF-8" + def make_web_app(): return hgwebdir("hgweb.config") diff --git a/mercurial/hgweb/hgweb_mod.py b/mercurial/hgweb/hgweb_mod.py --- a/mercurial/hgweb/hgweb_mod.py +++ b/mercurial/hgweb/hgweb_mod.py @@ -654,7 +654,8 @@ class hgweb(object): def run_wsgi(self, req): def header(**map): - header_file = cStringIO.StringIO(''.join(self.t("header", **map))) + header_file = cStringIO.StringIO( + ''.join(self.t("header", encoding = util._encoding, **map))) msg = mimetools.Message(header_file, 0) req.header(msg.items()) yield header_file.read() diff --git a/templates/gitweb/header.tmpl b/templates/gitweb/header.tmpl --- a/templates/gitweb/header.tmpl +++ b/templates/gitweb/header.tmpl @@ -1,11 +1,10 @@ -Content-type: text/html +Content-type: text/html; charset={encoding} - + - diff --git a/templates/header.tmpl b/templates/header.tmpl --- a/templates/header.tmpl +++ b/templates/header.tmpl @@ -1,4 +1,4 @@ -Content-type: text/html +Content-type: text/html; charset={encoding} diff --git a/templates/raw/header.tmpl b/templates/raw/header.tmpl --- a/templates/raw/header.tmpl +++ b/templates/raw/header.tmpl @@ -1,1 +1,2 @@ -Content-type: text/plain +Content-type: text/plain; charset={encoding} +