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

PythonInitHandler does not work in .htaccess file.

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 3.1.4, 3.3.x, 3.2.10
    • None
    • core
    • None

    Description

      The documentation says this about the PythonInitHandler:

      This handler is the first handler called in the request processing phases that is allowed
      both inside and outside .htaccess and directory.

      This handler is actually an alias to two different handlers. When specified in the main config
      file outside any directory tags, it is an alias to PostReadRequestHandler. When specified
      inside directory (where PostReadRequestHandler is not allowed), it aliases to PythonHeaderParserHandler.

      I believe the idea is that instead of having to know whether one should use PythonPostReadRequestHandler or PythonHeaderParserHandler dependent on whether you are setting up configuration in either main Apache configuration or .htaccess file, you just use the PythonInitHandler directive instead in either the main Apache configuration or the .htaccess file and it will called as appropriate for either phase automatically based on where it was used.

      Problem is that it cannot work in the .htaccess file.

      This is because the code for PythonPostReadRequestHandler says:

      static int PythonPostReadRequestHandler(request_rec *req) {
      int rc;

      /* run PythonInitHandler */
      rc = python_handler(req, "PythonInitHandler");
      apr_table_set(req->notes, "python_init_ran", "1");
      if ((rc != OK) && (rc != DECLINED))
      return rc;

      return python_handler(req, "PythonPostReadRequestHandler");
      }

      and that for PythonHeaderParserHandler says:

      static int PythonHeaderParserHandler(request_rec *req) {
      int rc;

      /* run PythonInitHandler, if not already */
      if (! apr_table_get(req->notes, "python_init_ran"))

      { rc = python_handler(req, "PythonInitHandler"); if ((rc != OK) && (rc != DECLINED)) return rc; }

      return python_handler(req, "PythonHeaderParserHandler");
      }

      The issue is that the table note called 'python_init_ran' is always set in the first function regardless of whether there was actually a registered PythonInitHandler that got called as part of the PythonPostReadRequestHandler phase. Thus, there will never be an opportunity for a PythonInitHandler registered in a .htaccess file to get called.

      The whole idea of the PythonInitHandler is possibly a bit suspect and since the idea was copied from mod_perl, a look should be made to see what mod_perl 2.0 does and whether they still have it.

      One thing that is a bit confusing is why one would want a single alias for these two different phases, especially since they aren't even adjacent within the processing sequence. Specifically the Apache phases include:

      "postreadrequesthandler"
      "transhandler"
      "maptostoragehandler" # not implemented by mod_python
      "headerparserhandler"

      Thus, the two phases are quite separate and the PythonTransHandler comes between them. Thus, why have them use the same name????

      Attachments

        Activity

          People

            Unassigned Unassigned
            grahamd Graham Phillip Dumpleton
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated: