mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-27 07:48:16 -05:00
send cache-control headers to fix the login-but-still-cached bug
This commit is contained in:
@@ -143,7 +143,8 @@ class ErrorController(RedditController):
|
||||
c.response.content = toofast
|
||||
return c.response
|
||||
elif code == '304':
|
||||
c.response.headers['x-sup-id'] = request.GET.get('x-sup-id')
|
||||
if request.GET.has_key('x-sup-id'):
|
||||
c.response.headers['x-sup-id'] = request.GET.get('x-sup-id')
|
||||
return c.response
|
||||
elif c.site:
|
||||
return self.send404()
|
||||
|
||||
@@ -598,11 +598,14 @@ class RedditController(BaseController):
|
||||
if c.user_is_loggedin:
|
||||
return
|
||||
|
||||
date = utils.is_modified_since(thing, action, request.if_modified_since)
|
||||
if date is False:
|
||||
last_modified = utils.last_modified_date(thing, action)
|
||||
date_str = http_utils.http_date_str(last_modified)
|
||||
c.response.headers['last-modified'] = date_str
|
||||
c.response.headers['cache-control'] = "private, max-age=0, must-revalidate"
|
||||
|
||||
modified_since = request.if_modified_since
|
||||
if modified_since and modified_since >= last_modified:
|
||||
abort(304, 'not modified')
|
||||
else:
|
||||
c.response.headers['Last-Modified'] = http_utils.http_date_str(date)
|
||||
|
||||
def abort404(self):
|
||||
abort(404, "not found")
|
||||
|
||||
@@ -9,10 +9,8 @@ def make_last_modified():
|
||||
def last_modified_key(thing, action):
|
||||
return 'last_%s_%s' % (str(action), thing._fullname)
|
||||
|
||||
def is_modified_since(thing, action, date):
|
||||
"""Returns true if the date is older than the last_[action] date,
|
||||
which means a 304 should be returned. Otherwise returns the date
|
||||
that should be sent as the last-modified header."""
|
||||
def last_modified_date(thing, action):
|
||||
"""Returns the date that should be sent as the last-modified header."""
|
||||
from pylons import g
|
||||
cache = g.permacache
|
||||
|
||||
@@ -22,12 +20,7 @@ def is_modified_since(thing, action, date):
|
||||
#if there is no last_modified, add one
|
||||
last_modified = make_last_modified()
|
||||
cache.set(key, last_modified)
|
||||
|
||||
if not date or date < last_modified:
|
||||
return last_modified
|
||||
else:
|
||||
#if a date was passed in and it's >= to last modified
|
||||
return False
|
||||
return last_modified
|
||||
|
||||
def set_last_modified(thing, action):
|
||||
from pylons import g
|
||||
|
||||
Reference in New Issue
Block a user