Created
August 19, 2010 09:07
-
-
Save rozza/537450 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.conf import settings | |
from django.http import HttpResponseRedirect | |
def secure_required(func): | |
""" | |
Decorator makes sure URL is accessed over https. | |
Use with `SecureRequiredMiddleware` to ensure only decorated urls are | |
accessed via https | |
""" | |
def wrap(request, *args, **kwargs): | |
request.secure_required = True | |
if not request.is_secure(): | |
if getattr(settings, 'HTTPS_SUPPORT', True): | |
request_url = request.build_absolute_uri(request.get_full_path()) | |
secure_url = request_url.replace('http://', 'https://') | |
return HttpResponseRedirect(secure_url) | |
return func(request, *args, **kwargs) | |
return wrap |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment