mirror of
https://github.com/postgres/pgweb.git
synced 2025-08-10 00:42:06 +00:00
Update @ssl_required decorator to play nice with other decorators
The decorator now retains all attributes of the original view and adds a new 'view.ssl_required = True' attribute.
This commit is contained in:

committed by
Magnus Hagander

parent
6ba4f789ed
commit
557c44fab5
@ -1,9 +1,12 @@
|
||||
import datetime
|
||||
from functools import wraps
|
||||
|
||||
def ssl_required(fn):
|
||||
def _require_ssl(request, *_args, **_kwargs):
|
||||
return fn(request, *_args, **_kwargs)
|
||||
return _require_ssl
|
||||
_require_ssl.ssl_required = True
|
||||
# wraps retains original function attributes such as __name__, csrf_exempt, etc
|
||||
return wraps(_require_ssl)(fn)
|
||||
|
||||
def nocache(fn):
|
||||
def _nocache(request, *_args, **_kwargs):
|
||||
|
@ -30,7 +30,7 @@ class PgMiddleware(object):
|
||||
return HttpResponseRedirect(request.build_absolute_uri().replace('http://','https://',1))
|
||||
return None
|
||||
|
||||
if view_func.__name__ == '_require_ssl':
|
||||
if getattr(view_func, 'ssl_required', False):
|
||||
# This view requires SSL, so check if we have it
|
||||
if not request.is_secure():
|
||||
# May need to deal with ports specified here?
|
||||
|
Reference in New Issue
Block a user