Skip to content

Commit

Permalink
Merge pull request #58 from plone/if-range-support
Browse files Browse the repository at this point in the history
If range support
  • Loading branch information
mauritsvanrees authored Jun 24, 2020
2 parents a2f9771 + f5b08c5 commit ae038d4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions news/58.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Remove Range from request if the If-Range condition is not fulfilled
[mamico]
17 changes: 17 additions & 0 deletions plone/app/caching/operations/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from plone.app.caching.operations.utils import getLastModifiedAnnotation
from plone.app.caching.operations.utils import isModified
from plone.app.caching.operations.utils import notModified
from plone.app.caching.operations.utils import parseDateTime
from plone.app.caching.operations.utils import setCacheHeaders
from plone.app.caching.operations.utils import visibleToRole
from plone.caching.interfaces import ICachingOperation
Expand All @@ -22,6 +23,7 @@
from zope.interface import provider
from zope.publisher.interfaces.http import IHTTPRequest

import datetime
import random
import time

Expand Down Expand Up @@ -98,6 +100,21 @@ def interceptResponse(self, rulename, response, class_=None):
lastModified = getLastModifiedAnnotation(
self.published, self.request, lastModified=lastModified)

# Remove Range from request if the If-Range condition is not fulfilled
if_range = self.request.environ.get('HTTP_IF_RANGE', '').strip('"')
if if_range:
if 'HTTP_RANGE' in self.request.environ:
if_range_dt = parseDateTime(if_range)
delta_sec = datetime.timedelta(seconds=1)
if if_range_dt and (lastModified - if_range_dt) < delta_sec:
pass
elif if_range == etag:
pass
else:
del self.request.environ['HTTP_RANGE']
# If-Range check is done here so we could remove it from the request
del self.request.environ['HTTP_IF_RANGE']

# Check for cache stop request variables
if cacheStop(self.request, rulename):
return None
Expand Down

0 comments on commit ae038d4

Please sign in to comment.