changeset 5928:3340aa5a64f7

hgweb: move HTTP content types out of header templates This removes the ability for templates to add custom HTTP headers, which can easily be re-added if someone needs it. Thanks to asak for repeatedly reviewing this patch and helping to iron out the quirks.
author Dirkjan Ochtman <dirkjan@ochtman.nl>
date Tue, 22 Jan 2008 10:45:55 +0100
parents b06c56f8fab7
children e160f2312815
files mercurial/hgweb/hgweb_mod.py mercurial/hgweb/hgwebdir_mod.py templates/atom/header.tmpl templates/atom/map templates/gitweb/header.tmpl templates/gitweb/map templates/header.tmpl templates/map templates/old/header.tmpl templates/old/map templates/raw/header.tmpl templates/raw/map templates/rss/header.tmpl templates/rss/map tests/test-hgweb-no-request-uri.out tests/test-non-interactive-wsgi.out
diffstat 16 files changed, 21 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/hgweb/hgweb_mod.py	Tue Jan 22 10:45:52 2008 +0100
+++ b/mercurial/hgweb/hgweb_mod.py	Tue Jan 22 10:45:55 2008 +0100
@@ -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 @@
         # 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)
--- a/mercurial/hgweb/hgwebdir_mod.py	Tue Jan 22 10:45:52 2008 +0100
+++ b/mercurial/hgweb/hgwebdir_mod.py	Tue Jan 22 10:45:55 2008 +0100
@@ -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 @@
                  "%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 @@
     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)
--- a/templates/atom/header.tmpl	Tue Jan 22 10:45:52 2008 +0100
+++ b/templates/atom/header.tmpl	Tue Jan 22 10:45:55 2008 +0100
@@ -1,4 +1,2 @@
-Content-type: application/atom+xml; charset={encoding}
-
 <?xml version="1.0" encoding="{encoding}"?>
 <feed xmlns="http://www.w3.org/2005/Atom">
\ No newline at end of file
--- a/templates/atom/map	Tue Jan 22 10:45:52 2008 +0100
+++ b/templates/atom/map	Tue Jan 22 10:45:55 2008 +0100
@@ -1,5 +1,6 @@
 default = 'changelog'
 feedupdated = '<updated>#date|rfc3339date#</updated>'
+mimetype = 'application/atom+xml; charset={encoding}'
 header = header.tmpl
 changelog = changelog.tmpl
 changelogentry = changelogentry.tmpl
--- a/templates/gitweb/header.tmpl	Tue Jan 22 10:45:52 2008 +0100
+++ b/templates/gitweb/header.tmpl	Tue Jan 22 10:45:55 2008 +0100
@@ -1,5 +1,3 @@
-Content-type: text/html; charset={encoding}
-
 <?xml version="1.0" encoding="{encoding}"?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
--- a/templates/gitweb/map	Tue Jan 22 10:45:52 2008 +0100
+++ b/templates/gitweb/map	Tue Jan 22 10:45:55 2008 +0100
@@ -1,4 +1,5 @@
 default = 'summary'
+mimetype = 'text/html; charset={encoding}'
 header = header.tmpl
 footer = footer.tmpl
 search = search.tmpl
--- a/templates/header.tmpl	Tue Jan 22 10:45:52 2008 +0100
+++ b/templates/header.tmpl	Tue Jan 22 10:45:55 2008 +0100
@@ -1,5 +1,3 @@
-Content-type: text/html; charset={encoding}
-
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 <html>
 <head>
--- a/templates/map	Tue Jan 22 10:45:52 2008 +0100
+++ b/templates/map	Tue Jan 22 10:45:55 2008 +0100
@@ -1,4 +1,5 @@
 default = 'shortlog'
+mimetype = 'text/html; charset={encoding}'
 header = header.tmpl
 footer = footer.tmpl
 search = search.tmpl
--- a/templates/old/header.tmpl	Tue Jan 22 10:45:52 2008 +0100
+++ b/templates/old/header.tmpl	Tue Jan 22 10:45:55 2008 +0100
@@ -1,5 +1,3 @@
-Content-type: text/html
-
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 <html>
 <head>
--- a/templates/old/map	Tue Jan 22 10:45:52 2008 +0100
+++ b/templates/old/map	Tue Jan 22 10:45:55 2008 +0100
@@ -1,4 +1,5 @@
 default = 'changelog'
+mimetype = 'text/html'
 header = header.tmpl
 footer = footer.tmpl
 search = search.tmpl
--- a/templates/raw/header.tmpl	Tue Jan 22 10:45:52 2008 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,2 +0,0 @@
-Content-type: text/plain; charset={encoding}
-
--- a/templates/raw/map	Tue Jan 22 10:45:52 2008 +0100
+++ b/templates/raw/map	Tue Jan 22 10:45:55 2008 +0100
@@ -1,4 +1,5 @@
-header = header.tmpl
+mimetype = 'text/plain; charset={encoding}'
+header = ''
 footer = ''
 changeset = changeset.tmpl
 difflineplus = '#line#'
--- a/templates/rss/header.tmpl	Tue Jan 22 10:45:52 2008 +0100
+++ b/templates/rss/header.tmpl	Tue Jan 22 10:45:55 2008 +0100
@@ -1,5 +1,3 @@
-Content-type: text/xml; charset={encoding}
-
 <?xml version="1.0" encoding="{encoding}"?>
 <rss version="2.0">
   <channel>
--- a/templates/rss/map	Tue Jan 22 10:45:52 2008 +0100
+++ b/templates/rss/map	Tue Jan 22 10:45:55 2008 +0100
@@ -1,4 +1,5 @@
 default = 'changelog'
+mimetype = 'text/xml; charset={encoding}'
 header = header.tmpl
 changelog = changelog.tmpl
 changelogentry = changelogentry.tmpl
--- a/tests/test-hgweb-no-request-uri.out	Tue Jan 22 10:45:52 2008 +0100
+++ b/tests/test-hgweb-no-request-uri.out	Tue Jan 22 10:45:55 2008 +0100
@@ -7,7 +7,7 @@
 ---- HEADERS
 200 Script output follows
 ---- DATA
-[('content-type', 'application/atom+xml; charset=ascii')]
+[('Content-type', 'application/atom+xml; charset=ascii')]
 <?xml version="1.0" encoding="ascii"?>
 <feed xmlns="http://www.w3.org/2005/Atom">
  <!-- Changelog -->
@@ -41,7 +41,7 @@
 ---- 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 @@
 ---- HEADERS
 200 Script output follows
 ---- DATA
-[('content-type', 'text/plain; charset=ascii')]
+[('Content-type', 'text/plain; charset=ascii')]
 
 /repo/
 
@@ -62,7 +62,7 @@
 ---- HEADERS
 200 Script output follows
 ---- DATA
-[('content-type', 'text/plain; charset=ascii')]
+[('Content-type', 'text/plain; charset=ascii')]
 
 -rw-r--r-- 4 bar
 
--- a/tests/test-non-interactive-wsgi.out	Tue Jan 22 10:45:52 2008 +0100
+++ b/tests/test-non-interactive-wsgi.out	Tue Jan 22 10:45:55 2008 +0100
@@ -7,6 +7,6 @@
 ---- HEADERS
 200 Script output follows
 ---- DATA
-[('content-type', 'text/html; charset=ascii')]
+[('Content-type', 'text/html; charset=ascii')]
 ---- ERRORS