Login

SSL Force Middleware

Author:
careercoder
Posted:
May 24, 2014
Language:
Python
Version:
1.5
Tags:
middleware django ssl secure
Score:
0 (after 0 ratings)

A simple way to force SSL on all pages. It's very simple at this point - the only issue I can see right now and I will address this later is if someone sends http:// in another portion of your url.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
#########
# Not Currently Working, it was... something happened fixing 
#########
__license__ = "Python"
__copyright__ = "Copyright (C) 2014 Jody Fitzpatrick"
__author__ = "Jody Fitzpatrick - jody@careerextender.com"

from django.http import HttpResponseRedirect, HttpResponsePermanentRedirect

class SSLRedirect:
    
  def process_request(self, request):
      
    if request.META['HTTP_HOST'] == 'http':
      newurl = str(request.build_absolute_uri()).replace('http://', 'https://')       
      return HttpResponsePermanentRedirect(newurl)
        

More like this

  1. Enable AWS ELB with SSL Termination by zvikico 4 years, 1 month ago
  2. SSL Middleware by sjzabel 8 years, 5 months ago
  3. SSL Redirect Middleware and testing by willhardy 7 years ago
  4. TLS(SSL) middleware, per URL pattern or whole site by robmadole 4 years, 8 months ago
  5. Fake SSL Middleware for Tests and Local Development by DrMeers 5 years, 2 months ago

Comments

Please login first before commenting.