Skip to content

Instantly share code, notes, and snippets.

@ferrix
ferrix / middleware.py
Created July 2, 2012 06:35 — forked from mtigas/middleware.py
An SSL-enforcing middleware
from django.conf import settings
from django.http import HttpResponsePermanentRedirect, get_host
class ForceSSLMiddleware(object):
"""
Redirects all (non-DEBUG) requests to go through SSL.
Picks up the `HTTP_X_FORWARDED_PROTO` proxy header set by Heroku.
Also sets the "Strict-Transport-Security" header for 600 seconds so that