diff options
| author | Claude Paroz <claude@2xlibre.net> | 2019-09-24 09:58:17 +0200 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2019-09-24 09:58:17 +0200 |
| commit | d71497bb249a2c3ffec41e99089f5ae8e575f2d3 (patch) | |
| tree | 60a9a1d5cb01d5bbce13e52517e0a980e9e1e4c7 /docs/ref | |
| parent | 37f8f293775d0b672da8ae369d9a4e17f1db7851 (diff) | |
Refs #26601 -- Used new-style middlewares in documentation.
Diffstat (limited to 'docs/ref')
| -rw-r--r-- | docs/ref/request-response.txt | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/docs/ref/request-response.txt b/docs/ref/request-response.txt index 72cef1068f..e7b285b086 100644 --- a/docs/ref/request-response.txt +++ b/docs/ref/request-response.txt @@ -286,16 +286,17 @@ Methods behind multiple proxies. One solution is to use middleware to rewrite the proxy headers, as in the following example:: - from django.utils.deprecation import MiddlewareMixin - - class MultipleProxyMiddleware(MiddlewareMixin): + class MultipleProxyMiddleware: FORWARDED_FOR_FIELDS = [ 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED_HOST', 'HTTP_X_FORWARDED_SERVER', ] - def process_request(self, request): + def __init__(self, get_response): + self.get_response = get_response + + def __call__(self, request): """ Rewrites the proxy headers so that only the most recent proxy is used. @@ -305,6 +306,7 @@ Methods if ',' in request.META[field]: parts = request.META[field].split(',') request.META[field] = parts[-1].strip() + return self.get_response(request) This middleware should be positioned before any other middleware that relies on the value of :meth:`~HttpRequest.get_host()` -- for instance, |
