Skip to content

Commit fb8809e

Browse files
committed
Move _update_response_headers method into ApplicationContent
1 parent 1c4df1d commit fb8809e

File tree

1 file changed

+29
-34
lines changed

1 file changed

+29
-34
lines changed

feincms/content/application/models.py

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ def render(self, request, **kwargs):
340340
def finalize(self, request, response):
341341
headers = getattr(self, 'rendered_headers', None)
342342
if headers:
343-
_update_response_headers(request, response, headers)
343+
self._update_response_headers(request, response, headers)
344344

345345
def save(self, *args, **kwargs):
346346
super(ApplicationContent, self).save(*args, **kwargs)
@@ -352,36 +352,31 @@ def delete(self, *args, **kwargs):
352352
# Clear reverse() cache
353353
_empty_reverse_cache()
354354

355-
356-
# ------------------------------------------------------------------------
357-
def _update_response_headers(request, response, headers):
358-
"""
359-
Combine all headers that were set by the different content types
360-
We are interested in Cache-Control, Last-Modified, Expires
361-
"""
362-
from django.utils.http import http_date
363-
364-
# Ideally, for the Cache-Control header, we'd want to do some intelligent
365-
# combining, but that's hard. Let's just collect and unique them and let
366-
# the client worry about that.
367-
cc_headers = set()
368-
for x in (cc.split(",") for cc in headers.get('Cache-Control', ())):
369-
cc_headers |= set((s.strip() for s in x))
370-
371-
if len(cc_headers):
372-
response['Cache-Control'] = ", ".join(cc_headers)
373-
else: # Default value
374-
response['Cache-Control'] = 'no-cache, must-revalidate'
375-
376-
# Check all Last-Modified headers, choose the latest one
377-
lm_list = [parsedate(x) for x in headers.get('Last-Modified', ())]
378-
if len(lm_list) > 0:
379-
response['Last-Modified'] = http_date(mktime(max(lm_list)))
380-
381-
# Check all Expires headers, choose the earliest one
382-
lm_list = [parsedate(x) for x in headers.get('Expires', ())]
383-
if len(lm_list) > 0:
384-
response['Expires'] = http_date(mktime(min(lm_list)))
385-
386-
387-
# ------------------------------------------------------------------------
355+
def _update_response_headers(self, request, response, headers):
356+
"""
357+
Combine all headers that were set by the different content types
358+
We are interested in Cache-Control, Last-Modified, Expires
359+
"""
360+
from django.utils.http import http_date
361+
362+
# Ideally, for the Cache-Control header, we'd want to do some intelligent
363+
# combining, but that's hard. Let's just collect and unique them and let
364+
# the client worry about that.
365+
cc_headers = set()
366+
for x in (cc.split(",") for cc in headers.get('Cache-Control', ())):
367+
cc_headers |= set((s.strip() for s in x))
368+
369+
if len(cc_headers):
370+
response['Cache-Control'] = ", ".join(cc_headers)
371+
else: # Default value
372+
response['Cache-Control'] = 'no-cache, must-revalidate'
373+
374+
# Check all Last-Modified headers, choose the latest one
375+
lm_list = [parsedate(x) for x in headers.get('Last-Modified', ())]
376+
if len(lm_list) > 0:
377+
response['Last-Modified'] = http_date(mktime(max(lm_list)))
378+
379+
# Check all Expires headers, choose the earliest one
380+
lm_list = [parsedate(x) for x in headers.get('Expires', ())]
381+
if len(lm_list) > 0:
382+
response['Expires'] = http_date(mktime(min(lm_list)))

0 commit comments

Comments
 (0)