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:59:41 +0200 |
| commit | 29d2f5a66212af91f93edb47df07982f92b4ac5f (patch) | |
| tree | 308a8f14274d0e538baef965b9be277b37d9c5c5 /docs/ref | |
| parent | 62a4a5062fb12bebe87505f9ecd1484212d85795 (diff) | |
[2.2.x] Refs #26601 -- Used new-style middlewares in documentation.
Backport of d71497bb249a2c3ffec41e99089f5ae8e575f2d3 from master
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 30ad0ccf42..8d834621cc 100644 --- a/docs/ref/request-response.txt +++ b/docs/ref/request-response.txt @@ -279,16 +279,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. @@ -298,6 +299,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, |
