Changeset 47

Show
Ignore:
Timestamp:
10/06/06 20:10:51 (2 years ago)
Author:
verbosus
Message:

Raise a RuntimeError? if trying to redirect on a POST request (thanks, C8E)

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • django/trunk/middleware/sslmiddleware.py

    r46 r47  
    1111https-less counterpart if needed). 
    1212""" 
    13 __version__ = "1.0" 
     13__version__ = "1.1" 
    1414__license__ = "Python" 
    1515__copyright__ = "Copyright (C) 2006, Antonio Cavedoni" 
    1616__author__ = "Antonio Cavedoni <http://cavedoni.com/>" 
    17 __contributors__ = ["Stefano J. Attardi <http://attardi.org/>"] 
     17__contributors__ = [ 
     18    "Stefano J. Attardi <http://attardi.org/>",  
     19    "Carlo C8E Miron" 
     20    ] 
    1821 
    1922from django.conf import settings 
     
    2730                if request.path.startswith("/%s" % path): 
    2831                    if not request.is_secure(): 
    29                         # Redirect to https:// 
     32                        # Should be SSL but it isn't, redirect! 
    3033                        return self._redirect(request, "https") 
    3134                    else: 
     
    3538            if _to_redir: 
    3639                if request.is_secure(): 
     40                    # Shouldn't be SSL but it is, redirect! 
    3741                    return self._redirect(request, "http") 
    3842 
     
    4246        if request.GET: 
    4347            newurl += '?' + request.GET.urlencode() 
     48        if settings.DEBUG and request.method == 'POST': 
     49            raise RuntimeError, """ 
     50Django can't redirect to the %(protocol)s URL you requested while maintaining  
     51POST data. Change your form to point to %(uri)s (dont't forget to specify the  
     52%(protocol)s or remove the requested path from the HTTPS_PATHS tuple in the  
     53project settings""" % {'uri': newurl, 'protocol': protocol.upper()} 
    4454        return HttpResponseRedirect(newurl)