|
a/Allura/allura/lib/utils.py |
|
b/Allura/allura/lib/utils.py |
|
|
1 |
import mimetypes
|
|
|
2 |
|
1 |
from pylons import response
|
3 |
from pylons import response
|
2 |
from paste.httpheaders import CACHE_CONTROL, EXPIRES
|
4 |
from paste.httpheaders import CACHE_CONTROL, EXPIRES
|
3 |
|
5 |
|
4 |
def cache_forever():
|
6 |
def cache_forever():
|
5 |
headers = [
|
7 |
headers = [
|
|
... |
|
... |
11 |
max_age=60*60*24*365)
|
13 |
max_age=60*60*24*365)
|
12 |
EXPIRES.update(headers, delta=delta)
|
14 |
EXPIRES.update(headers, delta=delta)
|
13 |
response.headers.pop('cache-control', None)
|
15 |
response.headers.pop('cache-control', None)
|
14 |
response.headers.pop('pragma', None)
|
16 |
response.headers.pop('pragma', None)
|
15 |
response.headers.update(headers)
|
17 |
response.headers.update(headers)
|
|
|
18 |
|
|
|
19 |
def guess_mime_type(filename):
|
|
|
20 |
'''Guess MIME type based on filename.
|
|
|
21 |
Applies heuristics, tweaks, and defaults in centralized manner.
|
|
|
22 |
'''
|
|
|
23 |
# Consider changing to strict=False
|
|
|
24 |
content_type = mimetypes.guess_type(filename, strict=True)
|
|
|
25 |
if content_type[0]:
|
|
|
26 |
content_type = content_type[0]
|
|
|
27 |
else:
|
|
|
28 |
content_type = 'application/octet-stream'
|
|
|
29 |
return content_type
|