Coverage for ivatar/middleware.py: 80%

5 statements  

« prev     ^ index     » next       coverage.py v7.6.9, created at 2024-12-26 00:11 +0000

1# -*- coding: utf-8 -*- 

2""" 

3Middleware classes 

4""" 

5 

6from django.utils.deprecation import MiddlewareMixin 

7 

8 

9class MultipleProxyMiddleware( 

10 MiddlewareMixin 

11): # pylint: disable=too-few-public-methods 

12 """ 

13 Middleware to rewrite proxy headers for deployments 

14 with multiple proxies 

15 """ 

16 

17 def process_request(self, request): # pylint: disable=no-self-use 

18 """ 

19 Rewrites the proxy headers so that forwarded server is 

20 used if available. 

21 """ 

22 if "HTTP_X_FORWARDED_SERVER" in request.META: 

23 request.META["HTTP_X_FORWARDED_HOST"] = request.META[ 

24 "HTTP_X_FORWARDED_SERVER" 

25 ]