Improvements associated with req.handler for type checker phase.
----------------------------------------------------------------

         Key: MODPYTHON-125
         URL: http://issues.apache.org/jira/browse/MODPYTHON-125
     Project: mod_python
        Type: Improvement
  Components: core  
    Versions: 3.3    
    Reporter: Graham Dumpleton


One purpose of the type checker phase in Apache, as able to be hooked using the 
PythonTypeHandler directive, is to use it to make decisions as to which actual 
handler should be used to deliver up the content for a request. It is also 
intended to be used to set up attributes such as req.content_type, 
req.content_encoding and req.content_languages. An example of an Apache module 
which supplies a function for this phase is mod_mime. That module uses lookups 
based on content type as derived from request URL extension type, to specify 
which handler should be used to generate the content. Another is 
mod_negotiation, which performs other sorts of determinations based on the 
request extension.

In mod_python, there are a few missing bits which would allow you to use 
mod_python to do the same sorts of things. These are that req.handler, 
req.content_encoding and req.content_languages are not writable. Of these the 
most important is probably req.handler.

To illustrate how it might be used, imagine an Apache configuration for a 
directory of:

  PythonTypeHandler select_handler
  PythonHandler deliver_content

Although the PythonHandler directive is specified here, it is never actually 
called. This is because the configuration doesn't specify either "SetHandler" 
or "AddHandler" directives. When the SetHandler directive is used, normally the 
Apache core would see it and trigger mod_python for the content handler phase. 
If AddHandler is instead used, it is mod_mime that would trigger mod_python be 
used if the extension matches that in the request URL.

Instead of using either of these directives, what should instead be able to be 
done is that a handler associated with PythonTypeHandler could say that 
mod_python should be triggered for the content phase. This might be done 
something like:

  def typehandler(req):
    if os.path.splitext(req.filename)[1] == ".py":
      req.handler = "mod_python"
      return apache.OK
    return apache.DECLINED

You might even say exactly which handler should be called as well.

  def typehandler(req):
    if os.path.splitext(req.filename)[1] == ".py":
      req.handler = "mod_python"
      req.add_handler("PythonHandler","mod_python.publisher")
      return apache.OK
    return apache.DECLINED

Unfortunately, this doesn't work because req.handler isn't writable. With 
req.handler writable it does work and the handler associated with 
PythonHandler, or as specified using req.add_handler() will be executed for the 
content phase.

Now the main intent of this JIRA issue is to make req.handler writable, but at 
the same time it is to highlight that for completeness, that 
req.content_encoding and req.content_languages should also probably be made 
writable as they are values which for example are modifed by mod_mime in this 
phase of processing. Note that req.content_type is already writable, which is 
another attribute which mod_mime modifies in this phase.
 

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira

Reply via email to