You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by "Christopher H. Laco" <cl...@chrislaco.com> on 2005/08/16 18:07:51 UTC
Adding Directives At Runtime
Are there any phase or scope limitations when adding directives to
apache at runtime? I've never done it, but I'm looking into a hack that
would require it.
The scenerio. In a Catalyst based app, Catalyst is setup to handle all
requests; be they for dynamic urls, or for physical files with static
content.
<Perl>
use lib qw(/var/www/MyCatalystApp/lib);
</Perl>
# ideally, here would be when the Catalyst app adds known
# additional Location directives
PerlModule MyCatalystApp
<Location />
SetHandler perl-script
PerlHandler MyCatalystApp
</Location>
There are various plugins and httpd.conf changes that can be made to
disuade this behaviour, but I would like to take it a step further and
make it Just Work(TM) so I don't have to tweak the httpd.conf or the
static plugin every time I add a new static directory.
At the time the Catalyst app loads, it knows all of the urls
(<Location>) that it should handle. I think everything else should just
be a regular Apache request without the need of adding LocationMatch or
Alias directives manually in httpd.conf.
So, given a list of urls, is it possible to dynamically add <Location
/somemethod> tags to Apache? I think so, I just don't know where to start.
Thanks,
-=Chris
Re: Adding Directives At Runtime
Posted by "Christopher H. Laco" <cl...@chrislaco.com>.
Geoffrey Young wrote:
>>What I don't yet grasp is if adding to the httpd.conf at runtime is
>>limited to a particular phase of if I could have any mod_perl handler
>>actually alter the http config while serving live requests.
>
>
> well, you probably wouldn't want to do the latter - once you're serving a
> request it makes little sense to add a full <Location> or whatnot, since
> that directive would just disappear at the end of the request. you'd be
> better off just fiddling with the current request using stuff like
> $r->handler than thinking about how to add real httpd.conf directives at
> that point.
Yah. I wouldn't want to do it either. It was more of a means to express
the ability to alter config at a later runtime, versus doing it during
the parse/load phase of the httpd.conf...
>
>
>>Could I have
>>a mod_perl page whereby the user submits a form, that in turn added a
>>Location directive to the runnin apache processes?
>
>
> yes, through means like $r->handler and whatnot. not really in terms of
> Location, at least not that I know about. but as I said, you probably
> wouldn't want to do that anyway.
>
> --Geoff
>
>
Re: Adding Directives At Runtime
Posted by Geoffrey Young <ge...@modperlcookbook.org>.
> Yes, and No. Read it. It seems to cover more of doing things like that
> in <Perl> sections. What I'm more curious is if it can be done during
> this phase:
>
> PerlModule MyCatalystApp
yes. at least in mp1. see
http://www.modperlcookbook.org/~geoff/modules/experimental/Apache-ReverseLocation-0.01.tar.gz
for a bizarre yet working example of adding to the PerlSections namespace.
fwiw, gozer tells me this is perfectly fine in mp2 as well. however, I have
my doubts - PerlModule doesn't start the interpreter anymore, so you'd need
to use PerlLoadModule to insert these into apache's config time. though I
can't recall if we altered PerlLoadModule so it can be used without custom
config directives (though I think gozer did that too). if not, you can
trick the interpreter into starting with a dummy <Perl> section :)
>
> What I don't yet grasp is if adding to the httpd.conf at runtime is
> limited to a particular phase of if I could have any mod_perl handler
> actually alter the http config while serving live requests.
well, you probably wouldn't want to do the latter - once you're serving a
request it makes little sense to add a full <Location> or whatnot, since
that directive would just disappear at the end of the request. you'd be
better off just fiddling with the current request using stuff like
$r->handler than thinking about how to add real httpd.conf directives at
that point.
> Could I have
> a mod_perl page whereby the user submits a form, that in turn added a
> Location directive to the runnin apache processes?
yes, through means like $r->handler and whatnot. not really in terms of
Location, at least not that I know about. but as I said, you probably
wouldn't want to do that anyway.
--Geoff
Re: Adding Directives At Runtime
Posted by Frank Wiles <fr...@wiles.org>.
On Tue, 16 Aug 2005 12:23:04 -0400
"Christopher H. Laco" <cl...@chrislaco.com> wrote:
> Yes, and No. Read it. It seems to cover more of doing things like that
>
> in <Perl> sections. What I'm more curious is if it can be done during
> this phase:
>
> PerlModule MyCatalystApp
>
> What I don't yet grasp is if adding to the httpd.conf at runtime is
> limited to a particular phase of if I could have any mod_perl handler
> actually alter the http config while serving live requests. Could I
> have a mod_perl page whereby the user submits a form, that in turn
> added a Location directive to the runnin apache processes?
I know it's possible, I'm just not finding exactly the right part
of the guide about this. For MP2 I believe you can use:
http://perl.apache.org/docs/2.0/api/Apache2/Directive.html
---------------------------------
Frank Wiles <fr...@wiles.org>
http://www.wiles.org
---------------------------------
Re: Adding Directives At Runtime
Posted by "Christopher H. Laco" <cl...@chrislaco.com>.
Frank Wiles wrote:
> On Tue, 16 Aug 2005 12:07:51 -0400
> "Christopher H. Laco" <cl...@chrislaco.com> wrote:
>
>
>>So, given a list of urls, is it possible to dynamically add <Location
>>/somemethod> tags to Apache? I think so, I just don't know where to
>>start.
>
>
> I think this is what you are looking for:
>
> http://perl.apache.org/docs/1.0/guide/config.html#Apache_Configuration_in_Perl
>
> ---------------------------------
> Frank Wiles <fr...@wiles.org>
> http://www.wiles.org
> ---------------------------------
>
>
Yes, and No. Read it. It seems to cover more of doing things like that
in <Perl> sections. What I'm more curious is if it can be done during
this phase:
PerlModule MyCatalystApp
What I don't yet grasp is if adding to the httpd.conf at runtime is
limited to a particular phase of if I could have any mod_perl handler
actually alter the http config while serving live requests. Could I have
a mod_perl page whereby the user submits a form, that in turn added a
Location directive to the runnin apache processes?
-=Chris
Re: Adding Directives At Runtime
Posted by Frank Wiles <fr...@wiles.org>.
On Tue, 16 Aug 2005 12:07:51 -0400
"Christopher H. Laco" <cl...@chrislaco.com> wrote:
> So, given a list of urls, is it possible to dynamically add <Location
> /somemethod> tags to Apache? I think so, I just don't know where to
> start.
I think this is what you are looking for:
http://perl.apache.org/docs/1.0/guide/config.html#Apache_Configuration_in_Perl
---------------------------------
Frank Wiles <fr...@wiles.org>
http://www.wiles.org
---------------------------------
Re: Adding Directives At Runtime
Posted by "Philippe M. Chiasson" <go...@ectoplasm.org>.
David Baird wrote:
> On 8/16/05, Christopher H. Laco <cl...@chrislaco.com> wrote:
>>Philippe M. Chiasson wrote
>>>A sample example of what I _think_ you are trying to do would look like:
>>>
>>>[...]
>>>
>>>With ->add_config, you can just feed arbitrary chunks of config to httpd, so you
>>>are free to do whatever you need to do.
>>
>>Exactly. IS there an an equivilant in MP1?
>
> Nobody has mentioned Apache->httpd_conf(), which makes me think I'm
> not quite grokking the scenario, but at least during server startup,
> you can feed chunks of config to the server this way.
True, and it's even documented (somewhat) here:
http://perl.apache.org/docs/1.0/guide/config.html#Usage
--------------------------------------------------------------------------------
Philippe M. Chiasson m/gozer\@(apache|cpan|ectoplasm)\.org/ GPG KeyID : 88C3A5A5
http://gozer.ectoplasm.org/ F9BF E0C2 480E 7680 1AE5 3631 CB32 A107 88C3A5A5
Re: Adding Directives At Runtime
Posted by David Baird <li...@gmail.com>.
On 8/16/05, Christopher H. Laco <cl...@chrislaco.com> wrote:
> Philippe M. Chiasson wrote:
> > A sample example of what I _think_ you are trying to do would look like:
> >
> > <httpd.conf>
> > PerlModule Catalyst
> > </httpd.conf>
> >
> > <Catalyst.pm>
> > package Catalyst;
> > use Apache2::ServerUtil qw();
> >
> > [... figure out where/what to configure ...]
> >
> > Apache2::ServerUtil->server->add_config([
> > '<Location /foo-bar>',
> > ' SetHandler perl-script',
> > ' PerlHandler Catalyst::Foo::Bar',
> > ]);
> > </Catalyst.pm>
> >
> > With ->add_config, you can just feed arbitrary chunks of config to httpd, so you
> > are free to do whatever you need to do.
>
>
> Exactly. IS there an an equivilant in MP1?
Nobody has mentioned Apache->httpd_conf(), which makes me think I'm
not quite grokking the scenario, but at least during server startup,
you can feed chunks of config to the server this way.
d.
Re: Adding Directives At Runtime
Posted by Geoffrey Young <ge...@modperlcookbook.org>.
>>Exactly. IS there an an equivilant in MP1?
>
>
> Not exacrly, but pretty close.
>
> <Perl> blocks are evaluated in the Apache::ReadConfig:: namespace. Anything you place
> in there will be handled by the <Perl> block handler.
which is exactly what the Apache::ReverseLocation code I sent does, so look
there if you need some additional pointers. IIRC it has the proper syntax
for adding a <Location> block.
oh, and for the record, add_config() can't inject _any_ directive into
httpd.conf - add_config() runs under the same restrictions as .htaccess
files, which can potentially bite you. at least it did to me when I was
trying to use it in one of my cpan modules :)
--Geoff
Re: Adding Directives At Runtime
Posted by "Philippe M. Chiasson" <go...@ectoplasm.org>.
Christopher H. Laco wrote:
> Philippe M. Chiasson wrote:
>
>> A sample example of what I _think_ you are trying to do would look like:
>>
>> <httpd.conf>
>> PerlModule Catalyst
>> </httpd.conf>
>>
>> <Catalyst.pm>
>> package Catalyst;
>> use Apache2::ServerUtil qw();
>>
>> [... figure out where/what to configure ...]
>>
>> Apache2::ServerUtil->server->add_config([
>> '<Location /foo-bar>',
>> ' SetHandler perl-script',
>> ' PerlHandler Catalyst::Foo::Bar',
>> ]);
>> </Catalyst.pm>
>>
>> With ->add_config, you can just feed arbitrary chunks of config to
>> httpd, so you
>> are free to do whatever you need to do.
>
> Exactly. IS there an an equivilant in MP1?
Not exacrly, but pretty close.
<Perl> blocks are evaluated in the Apache::ReadConfig:: namespace. Anything you place
in there will be handled by the <Perl> block handler.
so if in your module you put:
$Apache::ReadConfig::ServerAdmin = 'gozer@apache.org';
It will be identical to if you had :
<Perl>
$ServerAdmin = 'gozer@apache.org';
</Perl>
in your httpd.conf.
--------------------------------------------------------------------------------
Philippe M. Chiasson m/gozer\@(apache|cpan|ectoplasm)\.org/ GPG KeyID : 88C3A5A5
http://gozer.ectoplasm.org/ F9BF E0C2 480E 7680 1AE5 3631 CB32 A107 88C3A5A5
Re: Adding Directives At Runtime
Posted by "Christopher H. Laco" <cl...@chrislaco.com>.
Philippe M. Chiasson wrote:
> A sample example of what I _think_ you are trying to do would look like:
>
> <httpd.conf>
> PerlModule Catalyst
> </httpd.conf>
>
> <Catalyst.pm>
> package Catalyst;
> use Apache2::ServerUtil qw();
>
> [... figure out where/what to configure ...]
>
> Apache2::ServerUtil->server->add_config([
> '<Location /foo-bar>',
> ' SetHandler perl-script',
> ' PerlHandler Catalyst::Foo::Bar',
> ]);
> </Catalyst.pm>
>
> With ->add_config, you can just feed arbitrary chunks of config to httpd, so you
> are free to do whatever you need to do.
Exactly. IS there an an equivilant in MP1?
Re: Adding Directives At Runtime
Posted by "Philippe M. Chiasson" <go...@ectoplasm.org>.
Christopher H. Laco wrote:
> Perrin Harkins wrote:
>
>> On Tue, 2005-08-16 at 12:07 -0400, Christopher H. Laco wrote:
>>
>>> There are various plugins and httpd.conf changes that can be made to
>>> disuade this behaviour, but I would like to take it a step further
>>> and make it Just Work(TM) so I don't have to tweak the httpd.conf or
>>> the static plugin every time I add a new static directory.
>
>> If you put your catalyst app under a known path (i.e. /something instead
>> of /), you wouldn't have to worry about that. Or you could just put all
>> static files under /assets/ or similar.
>>
>> - Perrin
>>
> Of course, but that's not always the case.
> I see no reason setup situations should be constrainded like that when
> they don't have to be.
A sample example of what I _think_ you are trying to do would look like:
<httpd.conf>
PerlModule Catalyst
</httpd.conf>
<Catalyst.pm>
package Catalyst;
use Apache2::ServerUtil qw();
[... figure out where/what to configure ...]
Apache2::ServerUtil->server->add_config([
'<Location /foo-bar>',
' SetHandler perl-script',
' PerlHandler Catalyst::Foo::Bar',
]);
</Catalyst.pm>
With ->add_config, you can just feed arbitrary chunks of config to httpd, so you
are free to do whatever you need to do.
--------------------------------------------------------------------------------
Philippe M. Chiasson m/gozer\@(apache|cpan|ectoplasm)\.org/ GPG KeyID : 88C3A5A5
http://gozer.ectoplasm.org/ F9BF E0C2 480E 7680 1AE5 3631 CB32 A107 88C3A5A5
Re: Adding Directives At Runtime
Posted by "Christopher H. Laco" <cl...@chrislaco.com>.
Perrin Harkins wrote:
> On Tue, 2005-08-16 at 12:07 -0400, Christopher H. Laco wrote:
>
>>There are various plugins and httpd.conf changes that can be made to
>>disuade this behaviour, but I would like to take it a step further and
>>make it Just Work(TM) so I don't have to tweak the httpd.conf or the
>>static plugin every time I add a new static directory.
>
>
> If you put your catalyst app under a known path (i.e. /something instead
> of /), you wouldn't have to worry about that. Or you could just put all
> static files under /assets/ or similar.
>
> - Perrin
>
>
Of course, but that's not always the case.
I see no reason setup situations should be constrainded like that when
they don't have to be.
Re: Adding Directives At Runtime
Posted by Perrin Harkins <pe...@elem.com>.
On Tue, 2005-08-16 at 12:07 -0400, Christopher H. Laco wrote:
> There are various plugins and httpd.conf changes that can be made to
> disuade this behaviour, but I would like to take it a step further and
> make it Just Work(TM) so I don't have to tweak the httpd.conf or the
> static plugin every time I add a new static directory.
If you put your catalyst app under a known path (i.e. /something instead
of /), you wouldn't have to worry about that. Or you could just put all
static files under /assets/ or similar.
- Perrin