class CommonMiddleware(MiddlewareMixin):
"Common" middleware for taking care of some basic operations:
Forbid access to User-Agents in settings.DISALLOWED_USER_AGENTS
URL rewriting: Based on the APPEND_SLASH and PREPEND_WWW settings, append missing slashes and/or prepends missing "www."s.
- If APPEND_SLASH is set and the initial URL doesn't end with a slash, and it is not found in urlpatterns, form a new URL by appending a slash at the end. If this new URL is found in urlpatterns, return an HTTP redirect to this new URL; otherwise process the initial URL as usual.
This behavior can be customized by subclassing CommonMiddleware and overriding the response_redirect_class attribute.
Method | get_full_path_with_slash |
Return the full path of the request with a trailing slash appended. |
Method | process_request |
Check for denied User-Agents and rewrite the URL based on settings.APPEND_SLASH and settings.PREPEND_WWW |
Method | process_response |
When the status code of the response is 404, it may redirect to a path with an appended slash if should_redirect_with_slash() returns True. |
Method | should_redirect_with_slash |
Return True if settings.APPEND_SLASH is True and appending a slash to the request path turns an invalid path into a valid one. |
Inherited from MiddlewareMixin
:
Async Method | __acall__ |
Async version of __call__ that is swapped in when an async request is running. |
Method | __call__ |
Undocumented |
Method | __init__ |
Undocumented |
Method | __repr__ |
Undocumented |
Method | _async_check |
If get_response is a coroutine function, turns us into async mode so a thread is not consumed during a whole request. |
Class Variable | async_capable |
Undocumented |
Class Variable | sync_capable |
Undocumented |
Instance Variable | _is_coroutine |
Undocumented |
Instance Variable | get_response |
Undocumented |
Return the full path of the request with a trailing slash appended.
Raise a RuntimeError if settings.DEBUG is True and request.method is POST, PUT, or PATCH.