Commit 5c723552 authored by Laurence Rowe's avatar Laurence Rowe

ZPublisher response.setBody: don't append Accept-Encoding to Vary

        header if it is already present - this can make cache configuration
        difficult. (merged 99493)
parent 8852bb90
...@@ -27,6 +27,10 @@ Zope Changes ...@@ -27,6 +27,10 @@ Zope Changes
Bugs fixed 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 - Launchpad #267834: proper separation of HTTP header fields
using CRLF as requested by RFC 2616. (merged 90980, 92625) using CRLF as requested by RFC 2616. (merged 90980, 92625)
......
...@@ -398,6 +398,8 @@ class HTTPResponse(BaseResponse): ...@@ -398,6 +398,8 @@ class HTTPResponse(BaseResponse):
# was ignored anyway, so cache should not # was ignored anyway, so cache should not
# vary on it. Otherwise if not forced, cache should # vary on it. Otherwise if not forced, cache should
# respect Accept-Encoding client header # respect Accept-Encoding client header
vary = self.getHeader('Vary')
if vary is None or 'Accept-Encoding' not in vary:
self.appendHeader('Vary','Accept-Encoding') self.appendHeader('Vary','Accept-Encoding')
return self return self
......
...@@ -180,6 +180,20 @@ class HTTPResponseTests(unittest.TestCase): ...@@ -180,6 +180,20 @@ class HTTPResponseTests(unittest.TestCase):
'Set-Cookie: ' 'Set-Cookie: '
'violation="http://www.ietf.org/rfc/rfc2616.txt"\r\n') '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(): def test_suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment