You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by "Marc M. Adkins" <Pe...@Doorways.org> on 2007/06/13 07:47:54 UTC

DirectoryIndex vs. PerlTransHandler

I define a generalized output filter for any .page file:

<FilesMatch "\.page">
      SetHandler              perl-script
      PerlOutputFilterHandler Layout
</FilesMatch>

I have a <Directory> block:

<Directory ${WEB_07_ROOT}/tools>
      DataSources     Environment
</Directory>

which I'm referencing via an Alias from a VirtualHost:

<VirtualHost *:${WEB_07_PORT}>
      ServerName      home.Dimension.org
      DocumentRoot    ${WEB_07_ROOT}/dimension
      DirectoryIndex  index.page

      Alias           /tools ${WEB_07_ROOT}/tools

      <FilesMatch "\.page">
          SetHandler              perl-script
          PerlResponseHandler     Data
      </FilesMatch>
</VirtualHost>

(never mind the macro expansion strings, I'm pre-processing the
configuration file because it's just easier that way).

My PerlResponseHandler works fine on files in the /tools directory for
pages that are specified, for example:

/tools/environment.page
/tools/index.page

If I use just the directory URI:

/tools/

the DirectoryIndex specification works but I don't get any configuration
data inside the PerlResponseHandler from any variant of
Apache2::Module::get_config.  So my response handler doesn't work right.
   Everything's fine when I specify index.page, and when I don't the URI
comes back as index.page, but in the case where DirectoryIndex makes
this happen I don't get any configuration data item.

I have constructed a PerlTransHandler which can be attached to the
VirtualHost.  In it I do what DirectoryIndex would do, I check for a
trailing slash and append index.page.  When I do this the subsequent
response handler has appropriate configuration data.

I find this odd.  Can anyone explain why DirectoryIndex doesn't work the
same as an "equivalent" PerlTransHandler?


Re: DirectoryIndex vs. PerlTransHandler

Posted by "Marc M. Adkins" <Pe...@Doorways.org>.
Geoffrey Young wrote:
>> My PerlResponseHandler works fine on files in the /tools directory for
>> pages that are specified, for example:
>>
>> /tools/environment.page
>> /tools/index.page
>>
>> If I use just the directory URI:
>>
>> /tools/
>>
>> the DirectoryIndex specification works but I don't get any configuration
>> data inside the PerlResponseHandler from any variant of
>> Apache2::Module::get_config.  So my response handler doesn't work right.
>>   Everything's fine when I specify index.page, and when I don't the URI
>> comes back as index.page, but in the case where DirectoryIndex makes
>> this happen I don't get any configuration data item.
>>
>> I have constructed a PerlTransHandler which can be attached to the
>> VirtualHost.  In it I do what DirectoryIndex would do, I check for a
>> trailing slash and append index.page.  When I do this the subsequent
>> response handler has appropriate configuration data.
>>
>> I find this odd.  Can anyone explain why DirectoryIndex doesn't work the
>> same as an "equivalent" PerlTransHandler?
> 
> please take a look here
> 
>   http://marc.info/?l=apache-modperl&m=112805393100758&w=2
> 
> --GEoff
> 

I read most of that a couple of nights ago while trying to fix the 
problem.  It seemed to slightly miss the mark at the time, though it 
makes more sense now (much other doc reading in the interim).

When I tried implementing Apache2::DirectoryFixup just now it did not 
solve the problem.  I can see it working via trace statements but I 
still don't have configuration objects when I get to the response handler.

It took a while to get it to set the magic value anyway.  I had to set 
the handler to 'perl-script' in my <directory> block.  That isn't 
necessary with my PerlTransHandler for some reason.

I do find it interesting that $r->filename is <undef> in my 
PerlTransHandler.  That would seem to indicate that the trans handler is 
called kind of early in the process compared to the fixup handler (quite 
obvious from http://perl.apache.org/docs/2.0/user/handlers/http.html).

Maybe that's a clue, maybe a red herring.  I just don't know at what 
point in the cycle the configuration objects get, um, configured.

It seems like using a <Directory> configuration block as I do the 
associated configuration items could not possibly be set until the map 
to storage step, so I have to fix things before there, not after.  Which 
might explain why I get results using a trans handler but not a fixup 
handler.  But shouldn't mod_dir be part of the trans handler?  I should 
perhaps look up that code.

I'm not unhappy with my solution, mostly curious.  Trying to understand 
"why" often helps me solve other problems later.  I should probably buy 
a copy of the mod_perl cookbook.  ;)

Re: DirectoryIndex vs. PerlTransHandler

Posted by Geoffrey Young <ge...@modperlcookbook.org>.
> My PerlResponseHandler works fine on files in the /tools directory for
> pages that are specified, for example:
> 
> /tools/environment.page
> /tools/index.page
> 
> If I use just the directory URI:
> 
> /tools/
> 
> the DirectoryIndex specification works but I don't get any configuration
> data inside the PerlResponseHandler from any variant of
> Apache2::Module::get_config.  So my response handler doesn't work right.
>   Everything's fine when I specify index.page, and when I don't the URI
> comes back as index.page, but in the case where DirectoryIndex makes
> this happen I don't get any configuration data item.
> 
> I have constructed a PerlTransHandler which can be attached to the
> VirtualHost.  In it I do what DirectoryIndex would do, I check for a
> trailing slash and append index.page.  When I do this the subsequent
> response handler has appropriate configuration data.
> 
> I find this odd.  Can anyone explain why DirectoryIndex doesn't work the
> same as an "equivalent" PerlTransHandler?

please take a look here

  http://marc.info/?l=apache-modperl&m=112805393100758&w=2

--GEoff

Re: DirectoryIndex vs. PerlTransHandler

Posted by "Marc M. Adkins" <Pe...@Doorways.org>.
Turns out the solution to my problem was quite simple.  I replaced:

<Directory ${WEB_07_ROOT}/tools>
      DataSources     Environment
</Directory>

with:

<Location /tools/environment.page>
     DataSources     Environment
</Location>

and all of my problems resolved.  I am no longer using any 
PerlTransHandler or PerlFixupHandler (as described in other emails), 
just DirectoryIndex and Alias.  Works like a charm.

Apparently the problem was twofold.  First, <directory> was the wrong 
tag to use.  Second, even with <location>, I had to be very specific. 
Specifying the directory didn't work as it was too general.  I had to 
attach the configuration to the specific file, which was more correct 
anyway.  Never use a shotgun when you need a target rifle.  ;)

Along the way I did some testing to determine at what phase of the 
response cycle the configuration objects are set.  It looks like they 
are done in the Fixup phase after any PerlFixupHandler is run.  In case 
anyone needs to know.

Thanks for all the various suggestions.  This has all been very informative.

Marc M. Adkins

> I define a generalized output filter for any .page file:
> 
> <FilesMatch "\.page">
>      SetHandler              perl-script
>      PerlOutputFilterHandler Layout
> </FilesMatch>
> 
> I have a <Directory> block:
> 
> <Directory ${WEB_07_ROOT}/tools>
>      DataSources     Environment
> </Directory>
> 
> which I'm referencing via an Alias from a VirtualHost:
> 
> <VirtualHost *:${WEB_07_PORT}>
>      ServerName      home.Dimension.org
>      DocumentRoot    ${WEB_07_ROOT}/dimension
>      DirectoryIndex  index.page
> 
>      Alias           /tools ${WEB_07_ROOT}/tools
> 
>      <FilesMatch "\.page">
>          SetHandler              perl-script
>          PerlResponseHandler     Data
>      </FilesMatch>
> </VirtualHost>
> 
> (never mind the macro expansion strings, I'm pre-processing the
> configuration file because it's just easier that way).
> 
> My PerlResponseHandler works fine on files in the /tools directory for
> pages that are specified, for example:
> 
> /tools/environment.page
> /tools/index.page
> 
> If I use just the directory URI:
> 
> /tools/
> 
> the DirectoryIndex specification works but I don't get any configuration
> data inside the PerlResponseHandler from any variant of
> Apache2::Module::get_config.  So my response handler doesn't work right.
>   Everything's fine when I specify index.page, and when I don't the URI
> comes back as index.page, but in the case where DirectoryIndex makes
> this happen I don't get any configuration data item.
> 
> I have constructed a PerlTransHandler which can be attached to the
> VirtualHost.  In it I do what DirectoryIndex would do, I check for a
> trailing slash and append index.page.  When I do this the subsequent
> response handler has appropriate configuration data.
> 
> I find this odd.  Can anyone explain why DirectoryIndex doesn't work the
> same as an "equivalent" PerlTransHandler?