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