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 @@ -6,7 +6,7 @@ # This software may be used and distributed according to the terms # of the GNU General Public License, incorporated herein by reference. -import os, mimetypes, re, mimetools, cStringIO +import os, mimetypes, re from mercurial.node import * from mercurial import mdiff, ui, hg, util, archival, patch, hook from mercurial import revlog, templater @@ -253,11 +253,9 @@ class hgweb(object): # some functions for the templater def header(**map): - header_file = cStringIO.StringIO( - ''.join(tmpl("header", encoding=self.encoding, **map))) - msg = mimetools.Message(header_file, 0) - req.header(msg.items()) - yield header_file.read() + ctype = tmpl('mimetype', encoding=self.encoding) + req.httphdr(templater.stringify(ctype)) + yield tmpl('header', encoding=self.encoding, **map) def footer(**map): yield tmpl("footer", **map) diff --git a/mercurial/hgweb/hgwebdir_mod.py b/mercurial/hgweb/hgwebdir_mod.py --- a/mercurial/hgweb/hgwebdir_mod.py +++ b/mercurial/hgweb/hgwebdir_mod.py @@ -6,7 +6,7 @@ # This software may be used and distributed according to the terms # of the GNU General Public License, incorporated herein by reference. -import os, mimetools, cStringIO +import os from mercurial.i18n import gettext as _ from mercurial import ui, hg, util, templater from common import ErrorResponse, get_mtime, staticfile, style_map, paritygen, \ @@ -226,6 +226,7 @@ class hgwebdir(object): "%s%s" % ((not descending and column == sortcolumn) and "-" or "", column)) for column in sortable] + req.write(tmpl("index", entries=entries, subdir=subdir, sortcolumn=sortcolumn, descending=descending, **dict(sort))) @@ -233,11 +234,9 @@ class hgwebdir(object): def templater(self, req): def header(**map): - header_file = cStringIO.StringIO( - ''.join(tmpl("header", encoding=util._encoding, **map))) - msg = mimetools.Message(header_file, 0) - req.header(msg.items()) - yield header_file.read() + ctype = tmpl('mimetype', encoding=util._encoding) + req.httphdr(templater.stringify(ctype)) + yield tmpl('header', encoding=util._encoding, **map) def footer(**map): yield tmpl("footer", **map) diff --git a/templates/atom/header.tmpl b/templates/atom/header.tmpl --- a/templates/atom/header.tmpl +++ b/templates/atom/header.tmpl @@ -1,4 +1,2 @@ -Content-type: application/atom+xml; charset={encoding} - \ No newline at end of file diff --git a/templates/atom/map b/templates/atom/map --- a/templates/atom/map +++ b/templates/atom/map @@ -1,5 +1,6 @@ default = 'changelog' feedupdated = '#date|rfc3339date#' +mimetype = 'application/atom+xml; charset={encoding}' header = header.tmpl changelog = changelog.tmpl changelogentry = changelogentry.tmpl diff --git a/templates/gitweb/header.tmpl b/templates/gitweb/header.tmpl --- a/templates/gitweb/header.tmpl +++ b/templates/gitweb/header.tmpl @@ -1,5 +1,3 @@ -Content-type: text/html; charset={encoding} - diff --git a/templates/gitweb/map b/templates/gitweb/map --- a/templates/gitweb/map +++ b/templates/gitweb/map @@ -1,4 +1,5 @@ default = 'summary' +mimetype = 'text/html; charset={encoding}' header = header.tmpl footer = footer.tmpl search = search.tmpl diff --git a/templates/header.tmpl b/templates/header.tmpl --- a/templates/header.tmpl +++ b/templates/header.tmpl @@ -1,5 +1,3 @@ -Content-type: text/html; charset={encoding} - diff --git a/templates/map b/templates/map --- a/templates/map +++ b/templates/map @@ -1,4 +1,5 @@ default = 'shortlog' +mimetype = 'text/html; charset={encoding}' header = header.tmpl footer = footer.tmpl search = search.tmpl diff --git a/templates/old/header.tmpl b/templates/old/header.tmpl --- a/templates/old/header.tmpl +++ b/templates/old/header.tmpl @@ -1,5 +1,3 @@ -Content-type: text/html - diff --git a/templates/old/map b/templates/old/map --- a/templates/old/map +++ b/templates/old/map @@ -1,4 +1,5 @@ default = 'changelog' +mimetype = 'text/html' header = header.tmpl footer = footer.tmpl search = search.tmpl diff --git a/templates/raw/header.tmpl b/templates/raw/header.tmpl deleted file mode 100644 --- a/templates/raw/header.tmpl +++ /dev/null @@ -1,2 +0,0 @@ -Content-type: text/plain; charset={encoding} - diff --git a/templates/raw/map b/templates/raw/map --- a/templates/raw/map +++ b/templates/raw/map @@ -1,4 +1,5 @@ -header = header.tmpl +mimetype = 'text/plain; charset={encoding}' +header = '' footer = '' changeset = changeset.tmpl difflineplus = '#line#' diff --git a/templates/rss/header.tmpl b/templates/rss/header.tmpl --- a/templates/rss/header.tmpl +++ b/templates/rss/header.tmpl @@ -1,5 +1,3 @@ -Content-type: text/xml; charset={encoding} - diff --git a/templates/rss/map b/templates/rss/map --- a/templates/rss/map +++ b/templates/rss/map @@ -1,4 +1,5 @@ default = 'changelog' +mimetype = 'text/xml; charset={encoding}' header = header.tmpl changelog = changelog.tmpl changelogentry = changelogentry.tmpl diff --git a/tests/test-hgweb-no-request-uri.out b/tests/test-hgweb-no-request-uri.out --- a/tests/test-hgweb-no-request-uri.out +++ b/tests/test-hgweb-no-request-uri.out @@ -7,7 +7,7 @@ summary: test ---- HEADERS 200 Script output follows ---- DATA -[('content-type', 'application/atom+xml; charset=ascii')] +[('Content-type', 'application/atom+xml; charset=ascii')] @@ -41,7 +41,7 @@ 200 Script output follows ---- HEADERS 200 Script output follows ---- DATA -[('content-type', 'text/plain; charset=ascii')] +[('Content-type', 'text/plain; charset=ascii')] -rw-r--r-- 4 bar @@ -52,7 +52,7 @@ 200 Script output follows ---- HEADERS 200 Script output follows ---- DATA -[('content-type', 'text/plain; charset=ascii')] +[('Content-type', 'text/plain; charset=ascii')] /repo/ @@ -62,7 +62,7 @@ 200 Script output follows ---- HEADERS 200 Script output follows ---- DATA -[('content-type', 'text/plain; charset=ascii')] +[('Content-type', 'text/plain; charset=ascii')] -rw-r--r-- 4 bar diff --git a/tests/test-non-interactive-wsgi.out b/tests/test-non-interactive-wsgi.out --- a/tests/test-non-interactive-wsgi.out +++ b/tests/test-non-interactive-wsgi.out @@ -7,6 +7,6 @@ summary: test ---- HEADERS 200 Script output follows ---- DATA -[('content-type', 'text/html; charset=ascii')] +[('Content-type', 'text/html; charset=ascii')] ---- ERRORS