SSL Decorator

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
import urlparse
from django.conf import settings
from django.http import HttpResponseRedirect


def ssl_required(view_func):
    def _checkssl(request, *args, **kwargs):
        if not settings.DEBUG and not request.is_secure():
            if hasattr(settings, 'SSL_DOMAIN'):
                url_str = urlparse.urljoin(
                    settings.SSL_DOMAIN,
                    request.get_full_path()
                )
            else:
                url_str = request.build_absolute_uri()
            url_str = url_str.replace('http://', 'https://')
            return HttpResponseRedirect(url_str)

        return view_func(request, *args, **kwargs)
    return _checkssl

More like this

  1. Securely Signed S3 Links With Expiration by pjs 4 years, 7 months ago
  2. SSL / HTTPS Middleware for Redirection and href Rewriting by DrMeers 3 years, 1 month ago
  3. SSL Middleware for Webfaction by parlar 6 years, 1 month ago
  4. Security: Sideband information cover traffic middleware by jdunck 3 years, 2 months ago
  5. KMZMiddleware by giovabal 5 years, 2 months ago

Comments

(Forgotten your password?)