[Zope-Checkins] SVN: Zope/branches/2.11/ ZPublisher response.setBody: don't append Accept-Encoding to Vary

Laurence Rowe l at lrowe.co.uk
Sat Apr 25 20:13:08 EDT 2009


Log message for revision 99503:
  ZPublisher response.setBody: don't append Accept-Encoding to Vary
          header if it is already present - this can make cache configuration
          difficult. (merged 99493)

Changed:
  U   Zope/branches/2.11/doc/CHANGES.txt
  U   Zope/branches/2.11/lib/python/ZPublisher/HTTPResponse.py
  U   Zope/branches/2.11/lib/python/ZPublisher/tests/testHTTPResponse.py

-=-
Modified: Zope/branches/2.11/doc/CHANGES.txt
===================================================================
--- Zope/branches/2.11/doc/CHANGES.txt	2009-04-26 00:12:23 UTC (rev 99502)
+++ Zope/branches/2.11/doc/CHANGES.txt	2009-04-26 00:13:08 UTC (rev 99503)
@@ -27,6 +27,10 @@
 
     Bugs Fixed
 
+      - ZPublisher response.setBody: don't append Accept-Encoding to Vary
+        header if it is already present - this can make cache configuration
+        difficult. (merged 99493)
+
       - Launchpad #267834: proper separation of HTTP header fields    
         using CRLF as requested by RFC 2616. (merged 90980, 92625)
 

Modified: Zope/branches/2.11/lib/python/ZPublisher/HTTPResponse.py
===================================================================
--- Zope/branches/2.11/lib/python/ZPublisher/HTTPResponse.py	2009-04-26 00:12:23 UTC (rev 99502)
+++ Zope/branches/2.11/lib/python/ZPublisher/HTTPResponse.py	2009-04-26 00:13:08 UTC (rev 99503)
@@ -398,7 +398,9 @@
                         # was ignored anyway, so cache should not
                         # vary on it. Otherwise if not forced, cache should
                         # respect Accept-Encoding client header
-                        self.appendHeader('Vary','Accept-Encoding')
+                        vary = self.getHeader('Vary')
+                        if vary is None or 'Accept-Encoding' not in vary: 
+                            self.appendHeader('Vary','Accept-Encoding')
         return self
 
     def enableHTTPCompression(self,REQUEST={},force=0,disable=0,query=0):

Modified: Zope/branches/2.11/lib/python/ZPublisher/tests/testHTTPResponse.py
===================================================================
--- Zope/branches/2.11/lib/python/ZPublisher/tests/testHTTPResponse.py	2009-04-26 00:12:23 UTC (rev 99502)
+++ Zope/branches/2.11/lib/python/ZPublisher/tests/testHTTPResponse.py	2009-04-26 00:13:08 UTC (rev 99503)
@@ -180,7 +180,21 @@
                 'Set-Cookie: '
                 'violation="http://www.ietf.org/rfc/rfc2616.txt"\r\n')
 
+    def test_setBody_compression_vary(self):
+        # Vary header should be added here
+        response = self._makeOne()
+        response.enableHTTPCompression(REQUEST={'HTTP_ACCEPT_ENCODING': 'gzip'})
+        response.setBody('foo'*100) # body must get smaller on compression
+        self.assertEqual('Accept-Encoding' in response.getHeader('Vary'), True)
+        # But here it would be unnecessary
+        response = self._makeOne()
+        response.enableHTTPCompression(REQUEST={'HTTP_ACCEPT_ENCODING': 'gzip'})
+        response.setHeader('Vary', 'Accept-Encoding,Accept-Language')
+        before = response.getHeader('Vary')
+        response.setBody('foo'*100)
+        self.assertEqual(before, response.getHeader('Vary'))
 
+
 def test_suite():
     suite = unittest.TestSuite()
     suite.addTest(unittest.makeSuite(HTTPResponseTests, 'test'))



More information about the Zope-Checkins mailing list