You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Jeremy Nixon <je...@exit109.com> on 2005/11/08 22:25:39 UTC

MP2 custom config directives

I've recently moved to Apache2, and I'm now at my wit's end with custom
configuration directives.  I have them defined and working, following the
examples in the docs, but the merging behavior is proving difficult to
understand.

(Using mod_perl 2.0.2, apache 2.0.55, perl 5.8.7, FreeBSD 6.0RC1.)

At this point I'm not concerned with directory containers, I'm just
trying to get virtual hosts to work the way I want with directives that
apply server-wide.  The docs say: "If these functions are not supplied
the following default behavior takes place: the child container inherits
its parent configuration, unless it specifies its own and then it
overrides its parent configuration."

As luck would have it, this is exactly the behavior I want, so I figure
I'm good to go.  Unfortunately, this isn't what actually happens by
default.  What actually happens is that the virtual host inherits the
main server's configuration, but if *any* directives from the module
are specified within the virtual host, *none* of them are inherited and
the entire configuration must be repeated in the virtual host.

So, following what I think the docs are saying (they are pretty
incomprehensible on this subject) I add a simple SERVER_MERGE function
that merges the two hashes to try to duplicate what I thought was the
default behavior.  I observe no change, so I try increasingly crazy
things in this function, debug dumps, and ultimately deliberate fatal
run-time errors, and determine that this function is in fact never
getting called at all.

So, either I'm retrieving the values incorrectly, or I'm misunderstanding
the default behavior.

my $cfg = Apache2::Module::get_config(__PACKAGE__,$r->server,
                                      $r->per_dir_config);

(It makes no difference whether the per_dir_config thing is in there,
which I don't think it should since I'm not even trying directory
containers at this point.)  Using the above, the only way any of the
directives are inherited by the virtual host is if I specify none of
them within the virtual host section.  If any directives from the
module are specified, those are the only ones that appear.

And, I must be missing the part about how to get my SERVER_MERGE function
to be called.  The examples in the docs do not work as-is.

Any clues would be greatly appreciated.

-- 
Jeremy  |  jeremy@exit109.com


Re: MP2 custom config directives

Posted by Jeremy Nixon <je...@exit109.com>.
Geoffrey Young  <ge...@modperlcookbook.org> wrote:

> your description sounds correct for default behavior.  and I think it
> matches what you quoted :)

Hmm.  I took the description in the docs to mean that the directives would
override the "above" config on a per-directive basis.  It certainly didn't
occur to me that it would be per-module, but okay, that explains that, and
it makes sense now.

> you need to specify both SERVER_CREATE and SERVER_MERGE.

And that would explain that.

> or, more likely, DIR_CREATE and DIR_MERGE - SERVER_CREATE and SERVER_MERGE
> are only for things that can exist only on a per-server level, such as the
> PerlTransHandler (as opposed to the PerlFixupHandler which can appear
> per-server or per-directory).  make sense?

Ohhhh.  I came away from my (probably six or seven dozen) readings of the
docs thinking that DIR_{CREATE,MERGE} were for merging into <Directory> and
related containers, and SERVER_{CREATE,MERGE} were for merging into
virtual host containers.  So, I tried the SERVER_* ones, since the first
directives I was doing were server-level only.  But I'm reading them in
HeaderParser, Authen, Authz, and Log.  So, yeah.

> see
> 
>   http://people.apache.org/~geoff/Directive-2.tar.gz

Thank you very much.  I think I now have the Magic Clue.

-- 
Jeremy  |  jeremy@exit109.com


Re: MP2 custom config directives

Posted by Geoffrey Young <ge...@modperlcookbook.org>.
> At this point I'm not concerned with directory containers, I'm just
> trying to get virtual hosts to work the way I want with directives that
> apply server-wide.  The docs say: "If these functions are not supplied
> the following default behavior takes place: the child container inherits
> its parent configuration, unless it specifies its own and then it
> overrides its parent configuration."
> 
> As luck would have it, this is exactly the behavior I want, so I figure
> I'm good to go.  Unfortunately, this isn't what actually happens by
> default.  What actually happens is that the virtual host inherits the
> main server's configuration, but if *any* directives from the module
> are specified within the virtual host, *none* of them are inherited and
> the entire configuration must be repeated in the virtual host.

your description sounds correct for default behavior.  and I think it
matches what you quoted :)

> 
> So, following what I think the docs are saying (they are pretty
> incomprehensible on this subject) I add a simple SERVER_MERGE function
> that merges the two hashes to try to duplicate what I thought was the
> default behavior.  I observe no change, so I try increasingly crazy
> things in this function, debug dumps, and ultimately deliberate fatal
> run-time errors, and determine that this function is in fact never
> getting called at all.

you need to specify both SERVER_CREATE and SERVER_MERGE.  I suspect that's
your problem here.  or, more likely, DIR_CREATE and DIR_MERGE -
SERVER_CREATE and SERVER_MERGE are only for things that can exist only on a
per-server level, such as the PerlTransHandler (as opposed to the
PerlFixupHandler which can appear per-server or per-directory).  make sense?

> 
> So, either I'm retrieving the values incorrectly, or I'm misunderstanding
> the default behavior.

no, I think you have it right.  basically, things merge on their own until
_any_ custom directive appears in a container.  at that point the container
gets _only_ those custom directives explicitly defined in the container and
nothing merges.

if you want to override that behavior - say, use the one specified in the
container _and_ those defined in a parent container or on a per-server
level, then you need to implement DIR_CREATE and DIR_MERGE.

> 
> my $cfg = Apache2::Module::get_config(__PACKAGE__,$r->server,
>                                       $r->per_dir_config);
> 
> (It makes no difference whether the per_dir_config thing is in there,
> which I don't think it should since I'm not even trying directory
> containers at this point.)  Using the above, the only way any of the
> directives are inherited by the virtual host is if I specify none of
> them within the virtual host section.  If any directives from the
> module are specified, those are the only ones that appear.
> 
> And, I must be missing the part about how to get my SERVER_MERGE function
> to be called.  The examples in the docs do not work as-is.
> 
> Any clues would be greatly appreciated.

see

  http://people.apache.org/~geoff/Directive-2.tar.gz

for a quick example.  run 'make test' then look in the error_log - you'll
see the initial request gets the uppermost config, but the second request
gets a merged config, with one directive from the parent and one from the
current container.  well, in this case the "container" is an .htaccess file,
but those are essentially the same for purposes of merging.

anyway, HTH

--Geoff