Changes between Initial Version and Version 1 of Ticket #29925, comment 4
- Timestamp:
- Nov 8, 2018, 9:38:37 AM (6 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #29925, comment 4
initial v1 5 5 6 6 class Http2ServerPushRedirectMiddleware: 7 redirect_status_codes = {301, 302} 8 7 9 def __init__(self, get_response): 8 10 self.get_response = get_response 9 11 12 def should_preload(self, request, response): 13 return ( 14 request.is_secure 15 and response.status_code in self.redirect_status_codes 16 and hasattr(response, 'url') 17 and not response.has_header('Link') 18 ) 19 10 20 def __call__(self, request): 11 21 response = self.get_response(request) 12 if request.is_secure and response.status_code in {301, 302} and hasattr(response, 'url'):22 if self.should_preload(request, response): 13 23 url = response.url 14 24 if is_safe_url(url, allowed_hosts={request.get_host()}, require_https=True): 15 25 response['Link'] = f'<{url}>; rel=preload' 16 26 return response 17 27 }}} 18 28