diff --git a/r2/r2/controllers/error.py b/r2/r2/controllers/error.py index c2c4c14f7..af5fbc2a5 100644 --- a/r2/r2/controllers/error.py +++ b/r2/r2/controllers/error.py @@ -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() diff --git a/r2/r2/controllers/reddit_base.py b/r2/r2/controllers/reddit_base.py index 13e928171..19c8af8ab 100644 --- a/r2/r2/controllers/reddit_base.py +++ b/r2/r2/controllers/reddit_base.py @@ -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") diff --git a/r2/r2/lib/utils/thing_utils.py b/r2/r2/lib/utils/thing_utils.py index 6aff369c0..1d2a9092c 100644 --- a/r2/r2/lib/utils/thing_utils.py +++ b/r2/r2/lib/utils/thing_utils.py @@ -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