Add support to enhance the cacheability of course assets.

This introduces a mechanism to control the time-to-live for an unlocked
course asset, which will allow browsers and intermediate proxies/caches
to cache these course assets, determinstically.

Locked assets, with their nature of requiring authorization, are not
eligible for caching.
This commit is contained in:
Toby Lawrence
2016-01-15 11:38:34 -05:00
parent 5a5b5e8026
commit 01a9ad2369
14 changed files with 419 additions and 62 deletions

View File

@@ -0,0 +1,25 @@
"""
Middleware used for cleaning headers from a response before it is sent to the end user.
"""
class CleanHeadersMiddleware(object):
"""
Middleware that can drop headers present in a response.
This can be used, for example, to remove headers i.e. drop any Vary headers to improve cache performance.
"""
def process_response(self, _request, response):
"""
Processes the given response, potentially stripping out any unwanted headers.
"""
if len(getattr(response, 'clean_headers', [])) > 0:
for header in response.clean_headers:
try:
del response[header]
except KeyError:
pass
return response