[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/pagetemplate/ make sure ViewPageTemplateFile sets the Content-Type header if not

Fred L. Drake, Jr. fdrake at gmail.com
Wed Sep 29 13:39:17 EDT 2004


Log message for revision 27706:
  make sure ViewPageTemplateFile sets the Content-Type header if not
  already set
  


Changed:
  U   Zope3/trunk/src/zope/app/pagetemplate/tests/test_viewzpt.py
  U   Zope3/trunk/src/zope/app/pagetemplate/viewpagetemplatefile.py


-=-
Modified: Zope3/trunk/src/zope/app/pagetemplate/tests/test_viewzpt.py
===================================================================
--- Zope3/trunk/src/zope/app/pagetemplate/tests/test_viewzpt.py	2004-09-29 09:56:44 UTC (rev 27705)
+++ Zope3/trunk/src/zope/app/pagetemplate/tests/test_viewzpt.py	2004-09-29 17:39:16 UTC (rev 27706)
@@ -94,6 +94,24 @@
         self.request.debug.showTAL = True
         self.assert_('metal:' in t(self))
 
+    def test_render_sets_content_type_unless_set(self):
+        from zope.publisher.browser import TestRequest
+        t = ViewPageTemplateFile('test.pt')
+
+        self.request = TestRequest()
+        response = self.request.response
+        self.assert_(not response.getHeader('Content-Type'))
+        t(self)
+        self.assertEquals(response.getHeader('Content-Type'), 'text/html')
+
+        self.request = TestRequest()
+        response = self.request.response
+        response.setHeader('Content-Type', 'application/x-test-junk')
+        t(self)
+        self.assertEquals(response.getHeader('Content-Type'),
+                          'application/x-test-junk')
+        
+
 class TestViewZPTContentType(unittest.TestCase):
 
     def testInitWithoutType(self):

Modified: Zope3/trunk/src/zope/app/pagetemplate/viewpagetemplatefile.py
===================================================================
--- Zope3/trunk/src/zope/app/pagetemplate/viewpagetemplatefile.py	2004-09-29 09:56:44 UTC (rev 27705)
+++ Zope3/trunk/src/zope/app/pagetemplate/viewpagetemplatefile.py	2004-09-29 17:39:16 UTC (rev 27706)
@@ -45,8 +45,12 @@
             request=instance.request,
             instance=instance, args=args, options=keywords)
         debug_flags = instance.request.debug
-        return self.pt_render(namespace, showtal=debug_flags.showTAL,
-                              sourceAnnotations=debug_flags.sourceAnnotations)
+        s = self.pt_render(namespace, showtal=debug_flags.showTAL,
+                           sourceAnnotations=debug_flags.sourceAnnotations)
+        response = instance.request.response
+        if not response.getHeader("Content-Type"):
+            response.setHeader("Content-Type", self.content_type)
+        return s
 
     def __get__(self, instance, type):
         return BoundPageTemplate(self, instance)



More information about the Zope3-Checkins mailing list