Middleware

This module contains middleware to ensure best practices of DRF and other endpoints..

class RequestCustomAttributesMiddleware(get_response=None)

Adds various request related custom attributes.

Possible custom attributes include:
request_authenticated_user_set_in_middleware:
Example values: ‘process_request’, ‘process_view’, ‘process_response’, or ‘process_exception’. Attribute won’t exist if user is not authenticated.
request_auth_type_guess: Example values include: no-user, unauthenticated,

jwt, bearer, other-token-type, jwt-cookie, or session-or-other Note: These are just guesses because if a token was expired, for example,

the user could have been authenticated by some other means.

request_client_name: The client name from edx-rest-api-client calls. request_referer request_user_agent: The user agent string from the request header. request_user_id: The user id of the request user. request_is_staff_or_superuser: staff or superuser depending on whether the

user in the request is a django staff or superuser.

This middleware is dependent on the RequestCacheMiddleware. You must include this middleware later. For example:

MIDDLEWARE = (
    'edx_django_utils.cache.middleware.RequestCacheMiddleware',
    'edx_rest_framework_extensions.middleware.RequestCustomAttributesMiddleware',
)

This middleware should also appear after any authentication middleware.

process_exception(request, exception)

Django middleware handler to process an exception

process_request(request)

Caches if authenticated user was found.

process_response(request, response)

Add custom attributes for various details of the request.

process_view(request, view_func, view_args, view_kwargs)

Caches if authenticated user was found.

class RequestMetricsMiddleware(*args, **kwargs)

Deprecated class for handling middleware. Class has been renamed to RequestCustomAttributesMiddleware.