class CommonMiddleware(MiddlewareMixin): (source)
"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 |
Return the full path of the request with a trailing slash appended. |
Method | process |
Check for denied User-Agents and rewrite the URL based on settings.APPEND_SLASH and settings.PREPEND_WWW |
Method | process |
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 |
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 |
Class Variable | async |
Undocumented |
Class Variable | sync |
Undocumented |
Instance Variable | get |
Undocumented |
Method | _async |
If get_response is a coroutine function, turns us into async mode so a thread is not consumed during a whole request. |
Instance Variable | _is |
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.
Check for denied User-Agents and rewrite the URL based on settings.APPEND_SLASH and settings.PREPEND_WWW