diff options
author | Magnus Hagander | 2019-01-17 14:30:25 +0000 |
---|---|---|
committer | Magnus Hagander | 2019-01-17 14:35:39 +0000 |
commit | 87237f6536a1e6df112ca34818cf8459cb04fc68 (patch) | |
tree | 1c85c7d11382bb7ef6a2c98e780df7b8ffd59e8d /pgweb/util/middleware.py | |
parent | b2ed4946551c098079d1a156b222d4ebf5c85cba (diff) |
Tabs, meet your new overlords: spaces
In a quest to reach pep8, use spaces to indent rather than tabs.
Diffstat (limited to 'pgweb/util/middleware.py')
-rw-r--r-- | pgweb/util/middleware.py | 88 |
1 files changed, 44 insertions, 44 deletions
diff --git a/pgweb/util/middleware.py b/pgweb/util/middleware.py index 12f54d8f..9abcae2e 100644 --- a/pgweb/util/middleware.py +++ b/pgweb/util/middleware.py @@ -14,61 +14,61 @@ except ImportError: _thread_locals = local() def get_current_user(): - return getattr(_thread_locals, 'user', None) + return getattr(_thread_locals, 'user', None) # General middleware for all middleware functionality specific to the pgweb # project. class PgMiddleware(object): - def process_view(self, request, view_func, view_args, view_kwargs): - return None + def process_view(self, request, view_func, view_args, view_kwargs): + return None - def process_request(self, request): + def process_request(self, request): # Thread local store for username, see comment at the top of this file - _thread_locals.user = getattr(request, 'user', None) - initialize_template_collection() + _thread_locals.user = getattr(request, 'user', None) + initialize_template_collection() - def process_response(self, request, response): - # Set xkey representing the templates that are in use so we can do efficient - # varnish purging on commits. - tlist = get_all_templates() - if 'base/esi.html' in tlist: - response['x-do-esi'] = "1" - tlist.remove('base/esi.html') - if tlist: - response['xkey'] = ' '.join(["pgwt_{0}".format(hashlib.md5(t).hexdigest()) for t in tlist]) + def process_response(self, request, response): + # Set xkey representing the templates that are in use so we can do efficient + # varnish purging on commits. + tlist = get_all_templates() + if 'base/esi.html' in tlist: + response['x-do-esi'] = "1" + tlist.remove('base/esi.html') + if tlist: + response['xkey'] = ' '.join(["pgwt_{0}".format(hashlib.md5(t).hexdigest()) for t in tlist]) - # Set security headers - sources = OrderedDict([ - ('default', ["'self'", ]), - ('img', ['*', 'data:', ]), - ('script', ["'self'", "www.google-analytics.com", "ssl.google-analytics.com", "data:"]), - ('connect', ["'self'", "www.google-analytics.com", "ssl.google-analytics.com"]), - ('media', ["'self'", ]), - ('style', ["'self'", "fonts.googleapis.com"]), - ('font', ["'self'", "fonts.gstatic.com", "data:" ]), - ]) - if hasattr(response, 'x_allow_extra_sources'): - for k,v in response.x_allow_extra_sources.items(): - if k in sources: - sources[k].extend(v) - else: - sources[k] = v + # Set security headers + sources = OrderedDict([ + ('default', ["'self'", ]), + ('img', ['*', 'data:', ]), + ('script', ["'self'", "www.google-analytics.com", "ssl.google-analytics.com", "data:"]), + ('connect', ["'self'", "www.google-analytics.com", "ssl.google-analytics.com"]), + ('media', ["'self'", ]), + ('style', ["'self'", "fonts.googleapis.com"]), + ('font', ["'self'", "fonts.gstatic.com", "data:" ]), + ]) + if hasattr(response, 'x_allow_extra_sources'): + for k,v in response.x_allow_extra_sources.items(): + if k in sources: + sources[k].extend(v) + else: + sources[k] = v - security_policies = ["{0}-src {1}".format(k," ".join(v)) for k,v in sources.items()] + security_policies = ["{0}-src {1}".format(k," ".join(v)) for k,v in sources.items()] - if not getattr(response, 'x_allow_frames', False): - response['X-Frame-Options'] = 'DENY' - security_policies.append("frame-ancestors 'none'") + if not getattr(response, 'x_allow_frames', False): + response['X-Frame-Options'] = 'DENY' + security_policies.append("frame-ancestors 'none'") - if hasattr(settings, 'SECURITY_POLICY_REPORT_URI'): - security_policies.append("report-uri " + settings.SECURITY_POLICY_REPORT_URI) + if hasattr(settings, 'SECURITY_POLICY_REPORT_URI'): + security_policies.append("report-uri " + settings.SECURITY_POLICY_REPORT_URI) - if security_policies: - if getattr(settings, 'SECURITY_POLICY_REPORT_ONLY', False): - response['Content-Security-Policy-Report-Only'] = " ; ".join(security_policies) - else: - response['Content-Security-Policy'] = " ; ".join(security_policies) + if security_policies: + if getattr(settings, 'SECURITY_POLICY_REPORT_ONLY', False): + response['Content-Security-Policy-Report-Only'] = " ; ".join(security_policies) + else: + response['Content-Security-Policy'] = " ; ".join(security_policies) - response['X-XSS-Protection'] = "1; mode=block" - return response + response['X-XSS-Protection'] = "1; mode=block" + return response |