Commented: (MODPYTHON-98) wrong handler supplied to
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-98) wrong handler supplied to




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

    Commented: (MODPYTHON-98) wrong handler supplied to  
Jim Gallacher (JIRA)


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


 
01-14-06 02:18 AM

[ http://issues.apache.org/jira/brows...2362
399 ]

Jim Gallacher commented on MODPYTHON-98:
----------------------------------------

Applied Graham's suggestions so all these related issues can be considered f
ixed.

Still need to write some unit tests before this issue is marked as resolved.

> wrong handler supplied to req.add_handler() generates error
> -----------------------------------------------------------
>
>          Key: MODPYTHON-98
>          URL: http://issues.apache.org/jira/browse/MODPYTHON-98
>      Project: mod_python
>         Type: Bug
>   Components: core
>     Versions: 3.1.4, 3.2
>     Reporter: Graham Dumpleton

>
> The documentation for req.add_handler() states:
>   Note: There is no checking being done on the validity of the handler nam
e. If you pass this function an invalid handler it will simply be ignored.
> In other words, get the name of the handler wrong and it is supposed to ju
st ignore it. This is not actually the case, instead it will generate an exc
eption when it goes to process the handler:
>   Mod_python error: "PythonHandler example::handler_3"
>   Traceback (most recent call last):
>     File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/pyt
hon2.3/site-packages/mod_python/apache.py", line 291, in HandlerDispatch
>       arg=req, silent=hlist.silent)
>     File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/pyt
hon2.3/site-packages/mod_python/apache.py", line 538, in resolve_object
>       raise AttributeError, s
>   AttributeError: module '/Users/grahamd/Sites/add_handler/example.py' con
tains no 'handler_3'
> This can be seen with .htaccess file of:
>   SetHandler mod_python
>   PythonAccessHandler example
>   PythonHandler example::handler_1
>   PythonDebug On
> and example.py file containing:
>   from mod_python import apache
>   def accesshandler(req):
>     apache.log_error("accesshandler")
>     req.add_handler("PythonHandler","example::handler_3")
>     return apache.OK
>   def handler_1(req):
>     apache.log_error("handler_1")
>     req.content_type = 'text/plain'
>     req.write("HELLO")
>     return apache.OK
>   def handler_2(req):
>     apache.log_error("handler_2")
>     return apache.OK
> Either the documentation is wrong and an exception is desired, or more lik
ely this is an extension of the prior problem with hlist.silent as described
 as being a problem in other ways in MODPYTHON-46.
> In that case the logic of SILENT/NOTSILENT was the wrong way around and it was fix
ed by reversing the definitions of the two. In doing this though, it didn't cover ca
ses where a "silent" flag is passed to hlist_new() and hlist_append() in the req_add
_ha
ndler() function of requestobject.c.
> Specfically, there are calls to hlist_new() and hlist_append() in that fun
ction:
>         hlist_append(self->request_rec->pool, self->hlo->head,
>                      handler, dir, 0);
>             hle = hlist_new(self->request_rec->pool, handler, dir, 0);
>             hlist_append(self->request_rec->pool, hle, handler, dir, 0);
> These should be written as:
>         hlist_append(self->request_rec->pool, self->hlo->head,
>                      handler, dir, SILENT);
>             hle = hlist_new(self->request_rec->pool, handler, dir, SILENT)
;
>             hlist_append(self->request_rec->pool, hle, handler, dir, SILEN
T);
> If this change were made, the code would then behaves conformant with the 
documentation as far as being silent, however it highlights a further issue.
> This further issue is that although it is silent when the handler name is wrong, t
his results in apache.DECLINED being returned for the handler that couldn't be found
. Because apache.DECLINED is returned, Apache will try and interpret the URL again a
nd
if possible serve up a static file etc.
> For the above example code this then means that if "example.py" was used i
n the URL, the browser gets back a response of:
>   HELLOfrom mod_python import apache
>   def accesshandler(req):
>     apache.log_error("accesshandler")
>     req.add_handler("PythonHandler","example::handler_3")
>     return apache.OK
>   def handler_1(req):
>     apache.log_error("handler_1")
>     req.content_type = 'text/plain'
>     req.write("HELLO")
>     return apache.OK
>   def handler_2(req):
>     apache.log_error("handler_2")
>     return apache.OK
> That is, the content as returned by handler_1(), followed by the contents 
of the example.py file.
> If instead the URL wasn't 'example.py' but say 'other.py' with that not ex
isting, get back:
>   HELLO
>   OK
>   The requested URL /~grahamd/add_handler/foo.py was not found on this ser
ver.
>   Apache/2.0.51 (Unix) mod_python/3.2.5b Python/2.3 Server at localhost Po
rt 8080
> In some ways, this behaviour suggests that the behaviour whereby it raised an exce
ption was probably a better way of handling the situtation anyway. Thus, maybe the d
ocumentation should instead be changed and the code left as is, or at least the 0 ar
gum
ents changed to be NOTSLIENT to make it more obvious what it is doing.
> The other option is to change the code to use SILENT, but then document th
e strange things that can result if the specified handler doesn't exist.
> Comments??????






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 09:02 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