Commit febc3d23 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

Base, WebSection, Sound, OOoDocumentExtensibleTraversableMixin: set...

Base, WebSection, Sound, OOoDocumentExtensibleTraversableMixin: set Cache-Control header in 304 Not Modified response case as well.
parent 746dce16
......@@ -51,12 +51,12 @@ class OOoDocumentExtensibleTraversableMixin(BaseExtensibleTraversableMixin):
try:
self._convert(format='html')
view = _ViewEmulator().__of__(self)
# call caching policy manager.
_setCacheHeaders(view, web_cache_kw)
# If we have a conditional get, set status 304 and return
# no content
if _checkConditionalGET(view, web_cache_kw):
return ''
# call caching policy manager.
_setCacheHeaders(view, web_cache_kw)
mime, data = self.getConversion(format=EMBEDDED_FORMAT, filename=name)
document = OFSFile(name, name, data, content_type=mime).__of__(self.aq_parent)
except (NotConvertedError, ConversionError, KeyError):
......
......@@ -55,12 +55,12 @@ class Sound(File):
if format:
web_cache_kw['format'] = format
view = _ViewEmulator().__of__(self)
# call caching policy manager.
_setCacheHeaders(view, web_cache_kw)
# If we have a conditional get, set status 304 and return
# no content
if _checkConditionalGET(view, web_cache_kw):
return ''
# call caching policy manager.
_setCacheHeaders(view, web_cache_kw)
if not self.checkConversionFormatPermission(format, **kw):
raise Forbidden('You are not allowed to get this document in this ' \
......
......@@ -254,12 +254,12 @@ class WebSection(Domain, DocumentExtensibleTraversableMixin):
document = self
result = getattr(document, custom_render_method_id)()
view = _ViewEmulator().__of__(self)
# call caching policy manager.
_setCacheHeaders(view, {})
# If we have a conditional get, set status 304 and return
# no content
if _checkConditionalGET(view, extra_context={}):
return ''
# call caching policy manager.
_setCacheHeaders(view, {})
return result
elif document is not None:
return document()
......
......@@ -29,6 +29,7 @@
##############################################################################
import re
import requests
import time
from unittest import expectedFailure, skip
from StringIO import StringIO
......@@ -1308,6 +1309,12 @@ Hé Hé Hé!""", page.asText().strip())
self.assertTrue(self.publish(web_section.absolute_url_path()).getHeader('X-Cache-Headers-Set-By'))
web_section.setCustomRenderMethodId('WebSection_viewAsWeb')
self.assertTrue(self.publish(web_section.absolute_url_path()).getHeader('X-Cache-Headers-Set-By'))
conditional_get_response = requests.get(
web_section.absolute_url(),
headers={'If-Modified-Since': DateTime().utcdatetime().strftime('%a, %d %b %Y %H:%M:%S UTC')},
)
self.assertEqual(conditional_get_response.status_code, 304)
self.assertIn('Cache-Control', conditional_get_response.headers)
def test_16_404ErrorPageIsReturned(self):
"""
......
......@@ -80,12 +80,12 @@ class DownloadableMixin:
if format:
web_cache_kw['format'] = format
view = _ViewEmulator().__of__(self)
# call caching policy manager.
_setCacheHeaders(view, web_cache_kw)
# If we have a conditional get, set status 304 and return
# no content
if _checkConditionalGET(view, web_cache_kw):
return ''
# call caching policy manager.
_setCacheHeaders(view, web_cache_kw)
if not self.checkConversionFormatPermission(format, **kw):
raise Forbidden('You are not allowed to get this document in this ' \
......
......@@ -2518,12 +2518,12 @@ class Base(
"""Returns the default view even if index_html is overridden"""
result = self._renderDefaultView('view')
view = _ViewEmulator().__of__(self)
# call caching policy manager.
_setCacheHeaders(view, {})
# If we have a conditional get, set status 304 and return
# no content
if _checkConditionalGET(view, extra_context={}):
return ''
# call caching policy manager.
_setCacheHeaders(view, {})
return result
# Default views - the default security in CMFCore
......
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