Changeset 144

Show
Ignore:
Timestamp:
01/09/08 20:14:19
Author:
thejimmyg
Message:

Added an alternative construct_url() method

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • AuthKit/trunk/AuthKit.egg-info/PKG-INFO

    r141 r144  
    11Metadata-Version: 1.0 
    22Name: AuthKit 
    3 Version: 0.4.1dev-r139 
     3Version: 0.4.1dev-r143 
    44Summary: An authentication and authorization toolkit for WSGI applications and frameworks 
    55Home-page: http://authkit.org/ 
     
    5353        0.4.1 (**svn**) 
    5454         
     55        * Fixed #38, cookie sign out path should match the path specified in 
     56        the config file. 
     57        * Fixed #37, missing import of sys in digest authentication 
     58        * Updated SQLAlchemy code to use SQLAlchemyManager. Needs installing 
     59        manually with ``easy_install SQLAlchemyManager``. 
    5560        * Added a user management api_version attribute and changed the API so that 
    5661        the users object is set up on each request and recieves an environ 
  • AuthKit/trunk/CHANGELOG.txt

    r143 r144  
    440.4.1 (**svn**) 
    55 
     6* AuthKit form authentication now picks up HTTP_X_FORWARDED_HOST and 
     7  HTTP_X_FORWARDED_PORT when generating an action. This allows you to run 
     8  an AuthKit app on port 80, proxied from 443 as long as you set up these 
     9  two (slightly unstandard) variables. 
    610* Fixed #38, cookie sign out path should match the path specified in  
    711  the config file. 
  • AuthKit/trunk/authkit/authenticate/form.py

    r139 r144  
    2020 
    2121from paste.auth.form import AuthFormHandler 
    22 from paste.request import construct_url, parse_formvars 
     22from paste.request import parse_formvars 
    2323from authkit.authenticate import get_template, valid_password, \ 
    2424   get_authenticate_function, strip_base, RequireEnvironKey, \ 
     
    2727 
    2828import logging 
     29import urllib 
    2930log = logging.getLogger('authkit.authenticate.form') 
    3031 
     
    9495        return [content] 
    9596 
     97def construct_url(environ, with_query_string=True, with_path_info=True, 
     98                  script_name=None, path_info=None, querystring=None): 
     99    """Reconstructs the URL from the WSGI environment. 
     100 
     101    You may override SCRIPT_NAME, PATH_INFO, and QUERYSTRING with 
     102    the keyword arguments. 
     103 
     104    """ 
     105    url = '://' 
     106    host = environ.get('HTTP_X_FORWARDED_HOST', environ.get('HTTP_HOST')) 
     107    port = None 
     108    if ':' in host: 
     109        host, port = host.split(':', 1) 
     110    else: 
     111        host = environ.get('HTTP_X_FORWARDED_HOST', environ.get('HTTP_HOST')) 
     112        port = environ.get('HTTP_X_FORWARDED_PORT', environ.get('SERVER_PORT')) 
     113 
     114        # This is not a good way of determining the request scheme because 
     115        # the request could be proxied from an HTTPS server to an HTTP server 
     116        # if environ['wsgi.url_scheme'] == 'https': 
     117        #     if port == '443': 
     118        #         port = None 
     119        # elif environ['wsgi.url_scheme'] == 'http': 
     120        #     if port == '80': 
     121        #         port = None 
     122    url += host 
     123    if port: 
     124        if port == '443': 
     125            url = 'https'+url 
     126        elif port == '80': 
     127            url = 'http'+url 
     128        else: 
     129            url += 'https'+url+':%s' % port 
     130    else: 
     131        url = 'http'+url 
     132    if script_name is None: 
     133        url += urllib.quote(environ.get('SCRIPT_NAME','')) 
     134    else: 
     135        url += urllib.quote(script_name) 
     136    if with_path_info: 
     137        if path_info is None: 
     138            url += urllib.quote(environ.get('PATH_INFO','')) 
     139        else: 
     140            url += urllib.quote(path_info) 
     141    if with_query_string: 
     142        if querystring is None: 
     143            if environ.get('QUERY_STRING'): 
     144                url += '?' + environ['QUERY_STRING'] 
     145        elif querystring: 
     146            url += '?' + querystring 
     147    return url 
     148 
     149 
     150 
    96151def load_form_config( 
    97152    app,