Daniel J. Popowich wrote:
Jim Gallacher writes:
Daniel J. Popowich wrote:
Jim Gallacher writes:
Jim Gallacher wrote:
Using an internal_redirect messes with some of these attributes but not
others. Those that change get their new values from the new_uri used in
the redirect. Unchanged values are from the initial request.
req.internal_redirect(new_uri)
the_request unchanged
unparsed_uri new
parsed_uri new
args new
uri unchanged
^^^^^^^^^
uri new (oops - wee typo there)
hostname unchanged
Jim,
Really, I don't mean to be obtuse, but I'm not groking your point.
Are you clarifying that for internal redirects the *source* for these
attributes is different than what I was saying in my documentation
Exactly. The documentation needs to account for the different behaviour
after an internal_redirect. I'll let the code talk for me as I can't
come up with adequate text. Assume you are using publisher with the
following code.
Client request:
http://www.example.com/mod_python/parsed_uri/mptest.py?blah=de-blah
mptest.py
---------
def index(req):
req.content_type = 'text/plain'
req.write('-----\nindex\n-----\n')
stuff(req)
# I'm sorry about the look of the next statement -
# thunderbird line wrapping issues
req.internal_redirect("http://ABCDE.example.org:666"
"/mod_python/parsed_uri/mptest/redirect"
"?inquisition=spanish#foo")
def redirect(req):
req.write('\n\n--------\nredirect\n--------\n')
stuff(req)
def stuff(req):
req.write('req.the_request: %s\n' % req.the_request)
req.write('req.uri: %s\n' % req.uri)
req.write('req.unparsed_uri: %s\n' % str(req.unparsed_uri))
req.write('req.parsed_uri: %s\n' % str(req.parsed_uri))
req.write('req.hostname: %s\n' % req.hostname)
req.write('req.args: %s\n' % req.args)
Output:
=======
-----
index
-----
req.the_request: GET /mod_python/parsed_uri/mptest?blah=de-blah HTTP/1.1
req.uri: /mod_python/parsed_uri/mptest.py
req.unparsed_uri: /mod_python/parsed_uri/mptest
req.parsed_uri: (None, None, None, None, None, None,
'/mod_python/parsed_uri/mptest', 'blah=de-blah', None)
req.hostname: www.example.org
req.args: blah=de-blah
--------
redirect
--------
req.the_request: GET /mod_python/parsed_uri/mptest HTTP/1.1
req.uri: /mod_python/parsed_uri/mptest.py/redirect
req.unparsed_uri:
http://ABCDE.example.org:666/mod_python/parsed_uri/mptest/redirect?inquisition=spanish#foo
req.parsed_uri: ('http', 'ABCDE.example.org:666', None, None,
'ABCDE.example.org', 666, '/mod_python/parsed_uri/mptest/redirect',
'inquisition=spanish', 'foo')
req.hostname: www.example.org
req.args: inquisition=spanish
HOLY COW! Is it me or does this seem completely arbitrary?
Ambiguous at the very least. At least we can blame always blame apache. ;)
The value
of the_request is wrong, too (doesn't include the query).
Bit of an operator error there. The ol' copy and paste bit me on the
bum. Probably a good thing that I'm not writing any nuclear reactor
control code today.
I ran the test a couple of times and the results posted above were *not*
from the given request. It should look more like this:
Client request:
http://www.example.com/mod_python/parsed_uri/mptest.py?blah=de-blah
-----
index
-----
req.the_request: GET /mod_python/parsed_uri/mptest.py?blah=de-blah HTTP/1.1
--------
redirect
--------
req.the_request: GET /mod_python/parsed_uri/mptest.py?blah=de-blah HTTP/1.1
Jim