comparison MoinMoin/action/cache.py @ 4578:ace3bbadf66d

cache action: fix emitting headers for werkzeug API
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sat, 14 Feb 2009 23:47:37 +0100
parents 5ad5753ae311
children 1dff6cfdcf90
comparison
equal deleted inserted replaced
4577:bbdcf159f469 4578:ace3bbadf66d
144 data_cache.update(data) 144 data_cache.update(data)
145 content_length = content_length or data_cache.size() 145 content_length = content_length or data_cache.size()
146 last_modified = last_modified or data_cache.mtime() 146 last_modified = last_modified or data_cache.mtime()
147 147
148 httpdate_last_modified = timefuncs.formathttpdate(int(last_modified)) 148 httpdate_last_modified = timefuncs.formathttpdate(int(last_modified))
149 headers = ['Content-Type: %s' % content_type, 149 headers = [('Content-Type', content_type),
150 'Last-Modified: %s' % httpdate_last_modified, 150 ('Last-Modified', httpdate_last_modified),
151 'Content-Length: %s' % content_length, 151 ('Content-Length', content_length),
152 ] 152 ]
153 if content_disposition and filename: 153 if content_disposition and filename:
154 # TODO: fix the encoding here, plain 8 bit is not allowed according to the RFCs 154 # TODO: fix the encoding here, plain 8 bit is not allowed according to the RFCs
155 # There is no solution that is compatible to IE except stripping non-ascii chars 155 # There is no solution that is compatible to IE except stripping non-ascii chars
156 filename = filename.encode(config.charset) 156 filename = filename.encode(config.charset)
157 headers.append('Content-Disposition: %s; filename="%s"' % (content_disposition, filename)) 157 headers.append(('Content-Disposition', '%s; filename="%s"' % (content_disposition, filename)))
158 158
159 meta_cache = caching.CacheEntry(request, cache_arena, key+'.meta', cache_scope, do_locking=do_locking, use_pickle=True) 159 meta_cache = caching.CacheEntry(request, cache_arena, key+'.meta', cache_scope, do_locking=do_locking, use_pickle=True)
160 meta_cache.update({ 160 meta_cache.update({
161 'httpdate_last_modified': httpdate_last_modified, 161 'httpdate_last_modified': httpdate_last_modified,
162 'last_modified': last_modified, 162 'last_modified': last_modified,
215 def _do_get(request, key): 215 def _do_get(request, key):
216 """ send a complete http response with headers/data cached for key """ 216 """ send a complete http response with headers/data cached for key """
217 try: 217 try:
218 last_modified, headers = _get_headers(request, key) 218 last_modified, headers = _get_headers(request, key)
219 if request.if_modified_since == last_modified: 219 if request.if_modified_since == last_modified:
220 request.emit_http_headers(["Status: 304 Not modified"]) 220 request.status_code = 304
221 else: 221 else:
222 data_file = _get_datafile(request, key) 222 data_file = _get_datafile(request, key)
223 request.emit_http_headers(headers) 223 for key, value in headers:
224 lkey = key.lower()
225 if lkey == 'content-type':
226 request.content_type = value
227 elif lkey == 'last-modified':
228 request.last_modified = value
229 elif lkey == 'content-length':
230 request.content_length = value
231 else:
232 request.headers.add(key, value)
224 request.send_file(data_file) 233 request.send_file(data_file)
225 except caching.CacheError: 234 except caching.CacheError:
226 request.emit_http_headers(["Status: 404 Not found"]) 235 request.status_code = 404
227 236
228 237
229 def _do_remove(request, key): 238 def _do_remove(request, key):
230 """ delete headers/data cache for key """ 239 """ delete headers/data cache for key """
231 remove(request, key) 240 remove(request, key)
232 request.emit_http_headers(["Status: 200 OK"])
233 241
234 242
235 def _do(request, do, key): 243 def _do(request, do, key):
236 if do == 'get': 244 if do == 'get':
237 _do_get(request, key) 245 _do_get(request, key)