>>>>> "Perrin" == Perrin Harkins <[EMAIL PROTECTED]> writes:

Perrin> The common approach I've seen is to have a separate Location
Perrin> that doesn't map directly to the file system and exists only
Perrin> to drive this mod_perl handler.  It's also a good practice to
Perrin> organize your images in a separate directory so that you can
Perrin> easilly serve them from a dedicated image server later on.

Perrin> Also, you really should turn off auto indexes anyway on a
Perrin> production server.  It's a security problem.

As an alternative, I have used a PerlFixupHandler that detects a MIME
type of text/html and for only those enables Mason leaving the rest
alone.  This lets autoindexing still work properly, as well as images
and other content in the same directory.  The same trick can work with
Template.  The code looks like this:

    package Stonehenge::MyFixup;

    ## PerlFixupHandler Stonehenge::MyFixup

    use strict;
    use vars qw($VERSION);
    $VERSION = (qw$Revision: 1.6 $ )[-1];

    use Apache::Constants qw(DECLINED);

    sub handler {
      use Stonehenge::Reload; goto &handler if Stonehenge::Reload->reload_me;

      my $r = shift;

      if ($r->content_type and $r->content_type eq "text/html"
          and not $r->uri =~ m{^/CPAN}
         ) {
        0 and $r->log->notice("mason enabling ", $r->uri,
                        ($r->uri =~ m{^/} ? () : (" at filename ", $r->filename)),
                       );
        my $masonite = $r->dir_config("Masonite");
        if (defined $masonite and not $masonite =~ /^on$/i) {
          0 and $r->log->notice("masonite is $masonite, skipping");
        } else {
          $r->handler("perl-script");
          require Stonehenge::Mason unless defined &Stonehenge::Mason::handler;
          $r->set_handlers(PerlHandler => [\&Stonehenge::Mason::handler]);
        }
      }

      if (not $r->proxyreq and $r->is_main) {
        $r->header_out(X_mod_perl_rules =>
                       "mod_perl rules! Get it at http://perl.apache.org/";);
        $r->header_out(X_all_your_base =>
                       "ARE BELONG TO US!");
      }

      return DECLINED;
    }

    1;


-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[EMAIL PROTECTED]> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


Reply via email to