Issue Details (XML | Word | Printable)

Key: MODPYTHON-140
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Graham Dumpleton
Reporter: Graham Dumpleton
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
mod_python

util.redirect() returns wrong SERVER_RETURN status value

Created: 01/Mar/06 08:34 PM   Updated: 11/Apr/07 11:31 AM
Return to search
Component/s: core
Affects Version/s: 3.2.8
Fix Version/s: 3.3.1

Time Tracking:
Not Specified

File Attachments:
  Size
File Licensed for inclusion in ASF works grahamd_20060302_MP140_1.diff 2006-03-02 12:12 PM Graham Dumpleton 5 kB

Resolution Date: 07/Mar/06 09:34 AM


 Description  « Hide
The util.redirect() function ends with:

  raise apache.SERVER_RETURN, apache.OK

Although this will work when used in a handler run in the response/content handler phase, it will not always provide the desired result in a phase such as authenhandler where returning apache.OK actually means that the handler sucessfully authenticated the user.

One particular scenario that can result in undesirable behaviour is where a URL matches to a directory and Apache decides to iterate over files listed in DirectoryIndex trying to find an actual file. As it checks for each file, it will trigger any authenhandler. If the authenhandler decides it wants to redirect using util.redirect(), a status of apache.OK is being returned. All this does is make Apache think that authentication was successful and it ignores the fact that a redirection was being requested. The redirection only occurs when it gets to the last file listed in DirectoryIndex and it gives up, or it found one of the files. The desired result should be that it should stop looking through files immediately the redirection occurs.

To solve this problem and because util.redirect() is generating a complete response anyway, it should be returning apache.DONE and not apache.OK. Thus it should be using:

  raise apache.SERVER_RETURN, apache.DONE

By making this change, it will be safe to use util.redirect() in phases earlier than the response/content handler phase. This is not just because of the redirection issue described above, but is also because returning apache.OK as it does now doesn't actually stop any later phase from running, so a response/content handler would still run if one exists, with the content being appended to the content already generated by the util.redirect() function. Even if the util.redirect() was used in a response/content handler, without this change any stacked handlers not yet executed for the phase may still be run.

 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Graham Dumpleton made changes - 02/Mar/06 07:24 AM
Field Original Value New Value
Status Open [ 1 ] In Progress [ 3 ]
Graham Dumpleton added a comment - 02/Mar/06 12:12 PM
Attached "grahamd_20060302_MP140_1.diff" containing proposed changes.

Graham Dumpleton made changes - 02/Mar/06 12:12 PM
Attachment grahamd_20060302_MP140_1.diff [ 12323606 ]
Repository Revision Date User Message
ASF #383264 Sun Mar 05 01:23:20 UTC 2006 grahamd Changed util.redirect() to return DONE status instead of OK. (MODPYTHON-140)
Files Changed
MODIFY /httpd/mod_python/trunk/test/htdocs/tests.py
MODIFY /httpd/mod_python/trunk/Doc/modpython4.tex
MODIFY /httpd/mod_python/trunk/test/test.py
MODIFY /httpd/mod_python/trunk/lib/python/mod_python/util.py
MODIFY /httpd/mod_python/trunk/Doc/appendixc.tex

Graham Dumpleton made changes - 07/Mar/06 09:34 AM
Status In Progress [ 3 ] Resolved [ 5 ]
Resolution Fixed [ 1 ]
Graham Dumpleton made changes - 11/Apr/07 11:31 AM
Status Resolved [ 5 ] Closed [ 6 ]