Commit 12366b5d authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

support 304 (Not Modified) response where we support caching policy manager.

parent 0accb3ef
......@@ -37,7 +37,7 @@ from AccessControl import Unauthorized
from OFS.Traversable import NotFound
from Persistence import Persistent
from ZPublisher import BeforeTraverse
from Products.CMFCore.utils import _setCacheHeaders, _ViewEmulator
from Products.CMFCore.utils import _checkConditionalGET, _setCacheHeaders, _ViewEmulator
from Products.ERP5Type.Cache import getReadOnlyTransactionCache
......@@ -234,7 +234,13 @@ class WebSection(Domain, DocumentExtensibleTraversableMixin):
if document is None:
document = self
result = getattr(document, custom_render_method_id)()
_setCacheHeaders(_ViewEmulator().__of__(self), {})
view = _ViewEmulator().__of__(self)
# 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,7 +29,7 @@
from AccessControl import ClassSecurityInfo, Unauthorized
from Products.ERP5Type import Permissions
from Products.ERP5Type.Utils import fill_args_from_request
from Products.CMFCore.utils import getToolByName, _setCacheHeaders,\
from Products.CMFCore.utils import getToolByName, _checkConditionalGET, _setCacheHeaders,\
_ViewEmulator
import warnings
from zExceptions import Forbidden
......@@ -78,7 +78,13 @@ class DownloadableMixin:
web_cache_kw = kw.copy()
if format:
web_cache_kw['format'] = format
_setCacheHeaders(_ViewEmulator().__of__(self), web_cache_kw)
view = _ViewEmulator().__of__(self)
# 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 ' \
......
......@@ -36,7 +36,7 @@ from Products.ERP5Type.Cache import getReadOnlyTransactionCache
from AccessControl import ClassSecurityInfo, getSecurityManager
from AccessControl.SecurityManagement import newSecurityManager, setSecurityManager
from Products.ERP5Type import Permissions
from Products.CMFCore.utils import getToolByName, _setCacheHeaders, _ViewEmulator
from Products.CMFCore.utils import getToolByName, _checkConditionalGET, _setCacheHeaders, _ViewEmulator
from OFS.Image import File as OFSFile
from warnings import warn
import sys
......@@ -213,7 +213,13 @@ class OOoDocumentExtensibleTraversableMixin(BaseExtensibleTraversableMixin):
'format': EMBEDDED_FORMAT}
try:
self._convert(format='html')
_setCacheHeaders(_ViewEmulator().__of__(self), web_cache_kw)
view = _ViewEmulator().__of__(self)
# 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):
......
......@@ -51,7 +51,7 @@ from ZopePatch import ERP5PropertyManager
from Products.CMFCore.PortalContent import PortalContent
from Products.CMFCore.Expression import Expression
from Products.CMFCore.utils import getToolByName, _setCacheHeaders, _ViewEmulator
from Products.CMFCore.utils import getToolByName, _checkConditionalGET, _setCacheHeaders, _ViewEmulator
from Products.CMFCore.WorkflowCore import ObjectDeleted, ObjectMoved
from Products.CMFCore.CMFCatalogAware import CMFCatalogAware
......@@ -2415,8 +2415,13 @@ class Base( CopyContainer,
def view(self):
"""Returns the default view even if index_html is overridden"""
result = self._renderDefaultView('view')
view = _ViewEmulator().__of__(self)
# If we have a conditional get, set status 304 and return
# no content
if _checkConditionalGET(view, extra_context={}):
return ''
# call caching policy manager.
_setCacheHeaders(_ViewEmulator().__of__(self), {})
_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