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:
25
common/djangoapps/clean_headers/middleware.py
Normal file
25
common/djangoapps/clean_headers/middleware.py
Normal 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
|
||||
Reference in New Issue
Block a user