app/soc/views/helpers/response_helpers.py
changeset 169 a9b3d6c9d4f9
parent 167 13e438623ded
child 179 4882d6c5630d
equal deleted inserted replaced
168:87296bdfc9c6 169:a9b3d6c9d4f9
    21   '"Todd Larsen" <tlarsen@google.com>',
    21   '"Todd Larsen" <tlarsen@google.com>',
    22   '"Pawel Solyga" <pawel.solyga@gmail.com>',
    22   '"Pawel Solyga" <pawel.solyga@gmail.com>',
    23   ]
    23   ]
    24 
    24 
    25 
    25 
       
    26 import logging
    26 import urlparse
    27 import urlparse
    27 
    28 
    28 from google.appengine.api import users
    29 from google.appengine.api import users
    29 
    30 
    30 from django import http
    31 from django import http
   200       any suffix was removed from that request path
   201       any suffix was removed from that request path
   201     False otherwise
   202     False otherwise
   202        
   203        
   203   """
   204   """
   204   http_from = request.META.get('HTTP_REFERER')
   205   http_from = request.META.get('HTTP_REFERER')
   205         
   206       
   206   if not http_from:
   207   if not http_from:
   207     # no HTTP referrer, so cannot possibly start with expected prefix
   208     # no HTTP referrer, so cannot possibly start with expected prefix
   208     return False
   209     return False
   209 
   210 
   210   from_path = urlparse.urlparse(http_from).path
   211   from_path = urlparse.urlparse(http_from).path
   213     # use HTTP request path, since expected_prefix was not supplied
   214     # use HTTP request path, since expected_prefix was not supplied
   214     expected_prefix = request.path
   215     expected_prefix = request.path
   215 
   216 
   216   if suffix:
   217   if suffix:
   217     # remove suffix (such as a link name) before comparison
   218     # remove suffix (such as a link name) before comparison
   218     expected_prefix = expected_prefix[:-len(suffix)+1]
   219     chars_to_remove = len(suffix)
       
   220     
       
   221     if not suffix.startswith('/'):
       
   222       chars_to_remove = chars_to_remove + 1
       
   223 
       
   224     expected_prefix = expected_prefix[:-chars_to_remove]
   219 
   225 
   220   if not from_path.startswith(expected_prefix):
   226   if not from_path.startswith(expected_prefix):
   221     # expected prefix did not match first part of HTTP referrer path
   227     # expected prefix did not match first part of HTTP referrer path
   222     return False
   228     return False
   223  
   229