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