brotli: degrade gracefully when redis is missing
This commit is contained in:
parent
785d0509af
commit
f10b9dac80
|
@ -5,6 +5,7 @@ from hashlib import sha256
|
|||
import redis as libredis
|
||||
import os.path
|
||||
import mimetypes
|
||||
from redis.exceptions import RedisError
|
||||
|
||||
|
||||
class BrotliCache(object):
|
||||
|
@ -34,6 +35,7 @@ class BrotliCache(object):
|
|||
digest = sha256(body).hexdigest()
|
||||
cache_key = 'brotlicache:{}'.format(digest)
|
||||
|
||||
try:
|
||||
encbody = self.redis.get(cache_key)
|
||||
response.headers.set('brotli-cache', 'HIT')
|
||||
if not encbody:
|
||||
|
@ -60,6 +62,8 @@ class BrotliCache(object):
|
|||
response.headers.set('vary', 'accept-encoding')
|
||||
response.set_data(encbody)
|
||||
return response
|
||||
except RedisError:
|
||||
response.headers.set('brotli-cache', 'ERROR')
|
||||
|
||||
return response
|
||||
|
||||
|
|
Loading…
Reference in New Issue