Commented: (MODPYTHON-146) ap_internal_fast_redirect() and
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Web Servers reviews > Apache Server configuration support > Apache Mod-Python > Commented: (MODPYTHON-146) ap_internal_fast_redirect() and




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Commented: (MODPYTHON-146) ap_internal_fast_redirect() and  
Graham Dumpleton (JIRA)


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-15-06 12:46 PM

[ http://issues.apache.org/jira/brows...237
0489 ]

Graham Dumpleton commented on MODPYTHON-146:
--------------------------------------------

The idea of trying to use req->notes to store an ID for the request object t
o be used will in practice not be able to be used, or not easily. This is be
cause ap_internal_fast_redirect() wrongly merges the contents of the notes t
able from main request and
subrequest. This issue has been brought up on main Apache developers mailing
 list:

http://www.mail-archive.com/dev%40h...g/msg31263.html

The responses indicate it is a bug, but indications are that it possibly wil
l not be truly fixed until Apache 2.4 by using a proper internal redirect ra
ther than a fast redirect.

http://www.mail-archive.com/dev%40h...g/msg31264.html
http://www.mail-archive.com/dev%40h...g/msg31265.html
http://www.mail-archive.com/dev%40h...g/msg31266.html

Even if mod_python tried to implement a solution for use of the wrong reques
t object, the way that req.notes is wrongly merged from sub request to main 
request means that data in that table is going to be stuffed up and possibly
 not useable. As a conseque
nce, there doesn't seem to be much point in trying to fix this problem.

The only workaround for this whole issue at this point is for a fixup handle
r to be implemented by a user which hijacks the DirectoryIndex mapping mecha
nism and which determines what file to redirect to and execute an internal r
edirect instead. For exampl
e:

import os
from mod_python import apache

def fixuphandler(req):
if os.path.isdir(req.filename):
uri = req.uri + 'index.html'
if req.args: uri += '?' + req.args
req.internal_redirect(uri)
return apache.DONE
return apache.OK

This should really just use request_rec->finfo->filetype, but mod_python doe
sn't seem to expose the file type attribute through the request object. Thus
, necessary to perform a redundant check of whether target is a directory.

Alternatively, could use:

def fixuphandler(req):
if req.content_type == 'httpd/unix-directory':
uri = req.uri + 'index.html'
if req.args: uri += '?' + req.args
req.internal_redirect(uri)
return apache.DONE
return apache.OK

as mod_mime seems to set content type to this magic value when request_rec->
finfo->filetype is APR_DIR, ie., a directory. Should mod_python provide this
 magic content type as apache.DIR_MAGIC_TYPE?

Note that these examples assume that index file exists, but handler could ju
st as easily iterate over a list of possible targets until one is found. Wou
ld get even more complicated if one had to consider different choices based 
on language.


> ap_internal_fast_redirect() and request object cache
> ----------------------------------------------------
>
>          Key: MODPYTHON-146
>          URL: http://issues.apache.org/jira/browse/MODPYTHON-146
>      Project: mod_python
>         Type: Bug
>   Components: core
>     Versions: 3.2.8
>     Reporter: Graham Dumpleton
>     Assignee: Graham Dumpleton

>
> mod_python uses a Python class to wrap the Apache request_rec structure. The prima
ry purpose of the request object wrapper is to access the request_rec internals. One
 of the other features of the request object wrapper is that handlers can add their 
own
attributes to it, to facilitate communication of information between handler
s. This communication of information between handlers works because a handle
r will lookup to see if a request object has already been created for the re
quest as a whole before cr
eating a fresh request object wrapper, and will use the existing one instead.
> All in all this generally works okay, however, the DirectoryIndex directiv
e and the ap_internal_fast_redirect() do cause undesirable behaviour in spec
ific cases.
> Now when a request is made against a directory, this is detected by mod_dir, which
 in a LAST hooked handler in the fixup handler phase, will use ap_internal_fast_redi
rect() to determine if any of the files mentioned in the DirectoryIndex directive ex
ist
. What this function does is run through all request phases up to and includ
ing the fixup handler phase for the file which would be matched for the entr
y in DirectoryIndex. If the status comes back OK indicating the request coul
d be satisfied, it copies a
ll the information from the sub request request_rec structure into the parent request_rec st
ructure. It will then proceed with this information to execute the content handler phase.[vb
col=seagreen]
> The problem is that ap_internal_fast_redirect() knows only about the request_rec s
tructure and nothing about the Python request object wrapper. As a consequence, the 
request object created for the sub request which worked and ran through to the fixup
 ha[/vbcol]
ndler phase is being ignored and that originally created for the parent request continues to
 be used. As a consequence, any of the attributes added by handler phases up to and includin
g the fixup handler are lost.
> What possibly needs to be done is that the get_request_object() function in mod_py
thon needs to add to req->notes a tag which identifies the instance of the request o
bject which has been created. Because req->notes will be overlayed by the notes tabl
e c
ontents from the sub request, it will be able to detect when this copy of su
b request data into the parent has occured. It can then decide to switch to 
the request object created for the sub request, updating the request_rec mem
ber to point to the parent
request_rec instead.
> What may also come out of of storing an id for a request object in the req->notes 
table is that when an internal redirect occurs, instead of a fresh request object wr
apper instance being created to use for the req.main attribute, it can use the id in
 re
q->notes to actually get hold of the real request object of the parent and c
hain to it properly. Doing this will mean then that a sub request will be ab
le to access attributes added into a request object of the parent request, s
omething which can't curren
tly be done.
> Now, if you understand everything I have said above, you have done well. ;
-)
> Depending on whether people do understand or not, when I get a chance I'll
 try and attach some examples of handlers which demonstrate he problem.
> Acknowledgements that you understand the issue appreciated.






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 03:26 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register