openedx.core.djangoapps.header_control package#

Submodules#

openedx.core.djangoapps.header_control.decorators module#

Middleware decorator for removing headers.

openedx.core.djangoapps.header_control.decorators.force_header(header, value)#

Decorator that forces a header in the response to have a specific value. Usage:

@force_header(“Vary”, “Origin”) def myview(request):

The HeaderControlMiddleware must be used and placed as closely as possible to the top of the middleware chain, ideally after any caching middleware but before everything else.

This decorator is not safe for multiple uses: each call will overwrite any previously set values.

openedx.core.djangoapps.header_control.decorators.remove_headers(*headers)#

Decorator that removes specific headers from the response. Usage:

@remove_headers(“Vary”) def myview(request):

The HeaderControlMiddleware must be used and placed as closely as possible to the top of the middleware chain, ideally after any caching middleware but before everything else.

This decorator is not safe for multiple uses: each call will overwrite any previously set values.

openedx.core.djangoapps.header_control.middleware module#

Middleware used for adjusting headers in a response before it is sent to the end user.

class openedx.core.djangoapps.header_control.middleware.HeaderControlMiddleware(get_response)#

Bases: MiddlewareMixin

Middleware that can modify/remove headers in a response.

This can be used, for example, to remove headers i.e. drop any Vary headers to improve cache performance.

process_response(_request, response)#

Processes the given response, potentially remove or modifying headers.

Module contents#

This middleware is used for adjusting the headers in a response before it is sent to the end user.

This middleware is intended to sit as close as possible to the top of the middleare list as possible, so that it is one of the last pieces of middleware to touch the response, and thus can most accurately adjust/control the headers of the response.

openedx.core.djangoapps.header_control.force_header_for_response(response, header, value)#

Forces the given header for the given response using the header_control middleware.

openedx.core.djangoapps.header_control.remove_headers_from_response(response, *headers)#

Removes the given headers from the response using the header_control middleware.