comparison MoinMoin/action/cache.py @ 5945:d73431c6d2c9

fix 304 http status for cache action, see MoinMoinBugs/CacheActionComparesTimestampsIncorrectly
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Thu, 28 Feb 2013 15:48:49 +0100
parents 1dff6cfdcf90
children 500f68d3e2fd
comparison
equal deleted inserted replaced
5944:82ad863c255e 5945:d73431c6d2c9
24 html = '<img src="%s">' % url 24 html = '<img src="%s">' % url
25 25
26 @copyright: 2008 MoinMoin:ThomasWaldmann 26 @copyright: 2008 MoinMoin:ThomasWaldmann
27 @license: GNU GPL, see COPYING for details. 27 @license: GNU GPL, see COPYING for details.
28 """ 28 """
29
30 from datetime import datetime
29 31
30 from MoinMoin import log 32 from MoinMoin import log
31 logging = log.getLogger(__name__) 33 logging = log.getLogger(__name__)
32 34
33 # keep both imports below as they are, order is important: 35 # keep both imports below as they are, order is important:
200 202
201 def _get_headers(request, key): 203 def _get_headers(request, key):
202 """ get last_modified and headers cached for key """ 204 """ get last_modified and headers cached for key """
203 meta_cache = caching.CacheEntry(request, cache_arena, key+'.meta', cache_scope, do_locking=do_locking, use_pickle=True) 205 meta_cache = caching.CacheEntry(request, cache_arena, key+'.meta', cache_scope, do_locking=do_locking, use_pickle=True)
204 meta = meta_cache.content() 206 meta = meta_cache.content()
205 return meta['httpdate_last_modified'], meta['headers'] 207 return meta['last_modified'], meta['headers']
206 208
207 209
208 def _get_datafile(request, key): 210 def _get_datafile(request, key):
209 """ get an open data file for the data cached for key """ 211 """ get an open data file for the data cached for key """
210 data_cache = caching.CacheEntry(request, cache_arena, key+'.data', cache_scope, do_locking=do_locking) 212 data_cache = caching.CacheEntry(request, cache_arena, key+'.data', cache_scope, do_locking=do_locking)
214 216
215 def _do_get(request, key): 217 def _do_get(request, key):
216 """ send a complete http response with headers/data cached for key """ 218 """ send a complete http response with headers/data cached for key """
217 try: 219 try:
218 last_modified, headers = _get_headers(request, key) 220 last_modified, headers = _get_headers(request, key)
219 if request.if_modified_since == last_modified: 221 if datetime.utcfromtimestamp(int(last_modified)) == request.if_modified_since:
220 request.status_code = 304 222 request.status_code = 304
221 else: 223 else:
222 for k, v in headers: 224 for k, v in headers:
223 request.headers.add(k, v) 225 request.headers.add(k, v)
224 data_file = _get_datafile(request, key) 226 data_file = _get_datafile(request, key)