Django

Code

Changeset 3410

Show
Ignore:
Timestamp:
07/21/06 11:20:22 (2 years ago)
Author:
jacob
Message:

Fixed #2092: added a "is_secure()" method to HttpRequest which correctly handles the subtleties of mod_python's interaction with os.environ. This one's been bugging me for about a *year*, so many many thanks to k.shaposhnikov@gmail.com for figuring it out, and Tim Shaffer for pointing out this ticket.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/contrib/admin/views/doc.py

    r3284 r3410  
    2929    admin_root = request.path[:-len('doc/bookmarklets/')] 
    3030    return render_to_response('admin_doc/bookmarklets.html', { 
    31         'admin_url': "%s://%s%s" % (os.environ.get('HTTPS') == 'on' and 'https' or 'http', get_host(request), admin_root), 
     31        'admin_url': "%s://%s%s" % (request.is_secure() and 'https' or 'http', get_host(request), admin_root), 
    3232    }, context_instance=RequestContext(request)) 
    3333bookmarklets = staff_member_required(bookmarklets) 
  • django/trunk/django/core/handlers/modpython.py

    r3164 r3410  
    2323    def get_full_path(self): 
    2424        return '%s%s' % (self.path, self._req.args and ('?' + self._req.args) or '') 
     25 
     26    def is_secure(self): 
     27        return self._req.subprocess_env.has_key('HTTPS') and self._req.subprocess_env['HTTPS'] == 'on' 
    2528 
    2629    def _load_post_and_files(self): 
  • django/trunk/django/core/handlers/wsgi.py

    r3393 r3410  
    5555        self.environ = environ 
    5656        self.path = environ['PATH_INFO'] 
    57         self.META = environ 
     57        self.META = environ  
    5858        self.method = environ['REQUEST_METHOD'].upper() 
    5959 
     
    6666    def get_full_path(self): 
    6767        return '%s%s' % (self.path, self.environ.get('QUERY_STRING', '') and ('?' + self.environ.get('QUERY_STRING', '')) or '') 
     68 
     69    def is_secure(self): 
     70        return self.environ.has_key('HTTPS') and self.environ['HTTPS'] == 'on' 
    6871 
    6972    def _load_post_and_files(self): 
  • django/trunk/django/http/__init__.py

    r3166 r3410  
     1import os 
    12from Cookie import SimpleCookie 
    23from pprint import pformat 
     
    3839    def get_full_path(self): 
    3940        return '' 
     41         
     42    def is_secure(self): 
     43        return os.environ.get("HTTPS") == "on" 
    4044 
    4145def parse_file_upload(header_dict, post_data): 
  • django/trunk/django/middleware/common.py

    r3171 r3410  
    22from django import http 
    33from django.core.mail import mail_managers 
    4 import md5, os 
     4import md5 
    55 
    66class CommonMiddleware(object): 
     
    4545            # Redirect 
    4646            if new_url[0]: 
    47                 newurl = "%s://%s%s" % (os.environ.get('HTTPS') == 'on' and 'https' or 'http', new_url[0], new_url[1]) 
     47                newurl = "%s://%s%s" % (request.is_secure() and 'https' or 'http', new_url[0], new_url[1]) 
    4848            else: 
    4949                newurl = new_url[1] 
  • django/trunk/django/views/debug.py

    r3127 r3410  
    125125        'lastframe': frames[-1], 
    126126        'request': request, 
    127         'request_protocol': os.environ.get("HTTPS") == "on" and "https" or "http", 
     127        'request_protocol': request.is_secure() and "https" or "http", 
    128128        'settings': get_safe_settings(), 
    129129        'template_info': template_info, 
     
    150150        'reason': str(exception), 
    151151        'request': request, 
    152         'request_protocol': os.environ.get("HTTPS") == "on" and "https" or "http", 
     152        'request_protocol': request.is_secure() and "https" or "http", 
    153153        'settings': get_safe_settings(), 
    154154    }) 
  • django/trunk/docs/request_response.txt

    r3360 r3410  
    135135 
    136136``__getitem__(key)`` 
    137     Returns the GET/POST value for the given key, checking POST first, then 
    138     GET. Raises ``KeyError`` if the key doesn't exist. 
    139  
    140     This lets you use dictionary-accessing syntax on an ``HttpRequest`` 
    141     instance. Example: ``request["foo"]`` would return ``True`` if either 
    142     ``request.POST`` or ``request.GET`` had a ``"foo"`` key. 
     137   Returns the GET/POST value for the given key, checking POST first, then 
     138   GET. Raises ``KeyError`` if the key doesn't exist. 
     139 
     140   This lets you use dictionary-accessing syntax on an ``HttpRequest`` 
     141   instance. Example: ``request["foo"]`` would return ``True`` if either 
     142   ``request.POST`` or ``request.GET`` had a ``"foo"`` key. 
    143143 
    144144``has_key()`` 
    145     Returns ``True`` or ``False``, designating whether ``request.GET`` or 
    146     ``request.POST`` has the given key. 
     145   Returns ``True`` or ``False``, designating whether ``request.GET`` or 
     146   ``request.POST`` has the given key. 
    147147 
    148148``get_full_path()`` 
    149     Returns the ``path``, plus an appended query string, if applicable. 
    150  
    151     Example: ``"/music/bands/the_beatles/?print=true"`` 
     149   Returns the ``path``, plus an appended query string, if applicable. 
     150 
     151   Example: ``"/music/bands/the_beatles/?print=true"`` 
     152     
     153``is_secure()`` 
     154   Returns ``True`` if the request is secure; that is, if it was made with 
     155   HTTPS. 
    152156 
    153157QueryDict objects