Uploaded image for project: 'mod_python'
  1. mod_python
  2. MODPYTHON-125

Improvements associated with req.handler for type checker phase.

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 3.3.x
    • Fix Version/s: 3.3.1
    • Component/s: core
    • Labels:
      None

      Description

      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.

        Activity

        Hide
        grahamd Graham Dumpleton added a comment -

        Forgot to mention that req.content_languages is not documented in mod_python HTML documentation for request object.

        Show
        grahamd Graham Dumpleton added a comment - Forgot to mention that req.content_languages is not documented in mod_python HTML documentation for request object.
        Hide
        grahamd Graham Dumpleton added a comment -

        Note that although changes have been commited to make req.handler writable. Nothing has been done about making req.content_encoding and req.content_languages writable. Nor has anything been done about the fact that req.content_languages isn't documented. Seperate issue should possibly be created for these changes.

        Show
        grahamd Graham Dumpleton added a comment - Note that although changes have been commited to make req.handler writable. Nothing has been done about making req.content_encoding and req.content_languages writable. Nor has anything been done about the fact that req.content_languages isn't documented. Seperate issue should possibly be created for these changes.

          People

          • Assignee:
            grahamd Graham Dumpleton
            Reporter:
            grahamd Graham Dumpleton
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development