Changeset 1528 for branches


Ignore:
Timestamp:
Mar 27, 2010, 6:11:31 PM (15 years ago)
Author:
andersk
Message:
trac: Mangle HTTP_REFERER to let the login link keep you on the same page.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/locker-dev/locker/deploy/trac/trac.fcgi

    r1527 r1528  
    33import os, os.path, sys
    44from trac.web import fcgi_frontend
     5import urlparse
    56
    67env_path = os.getcwd()+'/tracdata'
     
    4748        and environ['REDIRECT_URL'].endswith(environ['PATH_INFO'])):
    4849        environ['SCRIPT_NAME'] = environ['REDIRECT_URL'][:-len(environ['PATH_INFO'])]
     50
     51    # If the referrer has our hostname and path, rewrite it to have
     52    # the right protocol and port, too.  This lets the login link go
     53    # to the right page.
     54    if 'HTTP_REFERER' in environ:
     55        referrer = urlparse.urlsplit(environ['HTTP_REFERER'])
     56        base = urlparse.urlsplit(
     57            ('https://' if environ.get('HTTPS') == 'on' else 'http://') +
     58            environ['HTTP_HOST'] +
     59            environ['SCRIPT_NAME'])
     60        if referrer.hostname == base.hostname and \
     61           (referrer.path == base.path or
     62            referrer.path.startswith(base.path + '/')):
     63            environ['HTTP_REFERER'] = urlparse.urlunsplit(
     64                (base.scheme, base.netloc,
     65                 referrer.path, referrer.query, referrer.fragment))
     66
    4967    return fcgi_frontend.dispatch_request(environ, start_response)
    5068
Note: See TracChangeset for help on using the changeset viewer.