[albatross-users] AppContext.redirect_url() question

Dave Cole djc at object-craft.com.au
Tue Jul 8 10:37:45 EST 2003


>>>>> "Matt" == Matt Goodall <matt at pollenation.net> writes:

Matt> Hi, Can anyone explain why the method in the subject is fiddling
Matt> around with uri paths? It looks like it's trying to cope with
Matt> the situation when the base uri and the request uri differ but I
Matt> don't understand why and it's probably not quite right,
Matt> i.e. what happens if the two URIs do not match correctly? When
Matt> would the two URIs be different anyway?

All of that code (which could probably be improved) is trying to
ensure that only absolute redirect URLs come out of the application.

You can see what it is trying to do by placing this application in
your cgi-bin directory and pointing your browser at it.

- - redirect.py - - - - - - - - - - - - - - - - - - - - - - - - - - -
#!/usr/bin/python
import sys
import os

if __name__ == '__main__':
    host = os.environ.get('HTTP_HOST')
    script_name = os.environ.get('SCRIPT_NAME')
    uri = os.environ.get('REQUEST_URI')

    page = uri[len(script_name):]
    sys.stderr.write('uri="%s", page="%s"\n' % (uri, page))
    if page == '/there':
        print 'Content-Type: text/plain'
        print
        print 'You are there'
    else:
        # This works perfectly
        loc = 'http://%s%s/there' % (host, script_name)
        # These all cause all sorts of strife
        #loc = '/%s/there' % script_name
        #loc = 'there'
        print 'Location:', loc
        print 'Status:', '301 Moved Permanently'
        print
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

The Albatross code is just trying to figure out how to construct an
absolute location for the requested redirect.  It also tries to avoid
fiddling with a URL that is already absolute.

Matt> Also, why does Albatross not make use of path info
Matt> (os.environ['PATH_INFO'] in cgi, req.path_info in mod_python;
Matt> not sure for BaseHTTPServer)? I think path info could simplify
Matt> the parsing and building or URLs which has been causing me a few
Matt> problems today when I popped a mod_python app behind a
Matt> mod_rewrite rule :(.

I am more than happy to change the current code if you figure out a
better way to do it.

- Dave

-- 
http://www.object-craft.com.au




More information about the Albatross-users mailing list